From 81fbaa70f3f084ba3a2567541624519dca88bd74 Mon Sep 17 00:00:00 2001 From: Caldfir Date: Mon, 3 Dec 2012 18:51:54 -0800 Subject: [PATCH] Merged block draw queues to the segment. Got fog into the new system. Note that creature names are still broken. --- Block.cpp | 60 +++---- Block.h | 413 ++++++++++++++++++++++----------------------- BlockTree.h | 182 ++++++++++---------- Config.cpp | 7 + Creatures.cpp | 2 +- GUI.cpp | 2 - SpriteObjects.cpp | 13 +- SpriteObjects.h | 13 +- WorldSegment.cpp | 135 +++++++++------ WorldSegment.h | 2 + commonTypes.h | 3 +- main.cpp | 1 + resources/init.txt | 5 + 13 files changed, 424 insertions(+), 414 deletions(-) diff --git a/Block.cpp b/Block.cpp index 2072beae..8903dc8c 100644 --- a/Block.cpp +++ b/Block.cpp @@ -145,12 +145,11 @@ void Block::AssembleSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet, void Block::AssembleSprite(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR tint, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, int flags) { Draw_Event d = {bitmap, tint, sx, sy, sw, sh, dx, dy, dw, dh, flags}; - todraw.push_back(d); + ownerSegment->AssembleSprite(d); } -void Block::Assemble() +void Block::AssembleBlock() { - todraw.clear(); if(!visible) { return; @@ -214,7 +213,7 @@ void Block::Assemble() spriteobject->set_size(SPRITEWIDTH, TILEHEIGHT); spriteobject->set_tile_layout(RAMPTOPTILE); spriteobject->set_offset(0, WALLHEIGHT); - spriteobject->draw_world_offset_src(x, y, z, 0, this, b, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + spriteobject->assemble_world_offset_src(x, y, z, 0, this, b, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); spriteobject->set_offset(0, 0); } //if (spriteobject->get_sheetindex() == UNCONFIGURED_INDEX) { @@ -226,7 +225,7 @@ void Block::Assemble() // spriteobject->set_offset(0, -(FLOORHEIGHT)); // spriteobject->set_tile_layout(RAMPTOPTILE); // spriteobject->set_defaultsheet(IMGRampSheet); - // spriteobject->draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + // spriteobject->assemble_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); // spriteobject->set_offset(0, 0); //} spriteobject->set_tile_layout(BLOCKTILE); @@ -254,9 +253,9 @@ void Block::Assemble() spriteobject->set_sheetindex(SPRITEOBJECT_FLOOR_NA); spriteobject->set_fileindex(INVALID_INDEX); spriteobject->set_offset(0, WALLHEIGHT); - spriteobject->draw_world(x, y, z, this); + spriteobject->assemble_world(x, y, z, this); } else { - spriteobject->draw_world(x, y, z, this); + spriteobject->assemble_world(x, y, z, this); } } } @@ -298,7 +297,7 @@ void Block::Assemble() if (spriteobject->get_sheetindex() != INVALID_INDEX) { spriteobject->set_size(SPRITEWIDTH, SPRITEHEIGHT); spriteobject->set_tile_layout(RAMPBOTTOMTILE); - spriteobject->draw_world_offset(x, y, z, 0, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + spriteobject->assemble_world_offset(x, y, z, 0, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); } spriteobject->set_tile_layout(BLOCKTILE); } @@ -323,7 +322,7 @@ void Block::Assemble() // c_sprite * vegetationsprite = 0; // vegetationsprite = GetSpriteVegetation( (TileClass) getVegetationType( this->floorType ), tree.index ); // if(vegetationsprite) - // vegetationsprite->draw_world(x, y, z); + // vegetationsprite->assemble_world(x, y, z); //} //items @@ -332,11 +331,11 @@ void Block::Assemble() contentLoader->itemConfigs[Item.item.type] && (Item.item.index < contentLoader->itemConfigs[Item.item.type]->subItems.size()) && contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.index]) { - contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.index]->sprite.draw_world(x, y, z, this); + contentLoader->itemConfigs[Item.item.type]->subItems[Item.item.index]->sprite.assemble_world(x, y, z, this); } else if ( contentLoader->itemConfigs[Item.item.type] && contentLoader->itemConfigs[Item.item.type]->configured) { - contentLoader->itemConfigs[Item.item.type]->default_sprite.draw_world(x, y, z, this); + contentLoader->itemConfigs[Item.item.type]->default_sprite.assemble_world(x, y, z, this); } else { AssembleSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt, Item.dyematt), drawx, (tileShapeBasic==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*ssConfig.scale)):drawy , this); } @@ -356,9 +355,9 @@ void Block::Assemble() for(uint32_t i=0; i < building.sprites.size(); i++) { spriteobject = &building.sprites[i]; if(building.parent) { - spriteobject->draw_world(x, y, z, building.parent); + spriteobject->assemble_world(x, y, z, building.parent); } else { - spriteobject->draw_world(x, y, z, this); + spriteobject->assemble_world(x, y, z, this); } } } @@ -374,9 +373,9 @@ void Block::Assemble() spriteobject = GetFloorSpriteMap(tileType, material, consForm); if(spriteobject->get_sheetindex() != INVALID_INDEX && spriteobject->get_sheetindex() != UNCONFIGURED_INDEX) { if (mirrored) { - spriteobject->draw_world_offset(x, y, z, 1, this); + spriteobject->assemble_world_offset(x, y, z, 1, this); } else { - spriteobject->draw_world(x, y, z, this); + spriteobject->assemble_world(x, y, z, this); } } @@ -384,9 +383,9 @@ void Block::Assemble() spriteobject = GetBlockSpriteMap(tileType, material, consForm); if(spriteobject->get_sheetindex() != INVALID_INDEX && spriteobject->get_sheetindex() != UNCONFIGURED_INDEX) { if (mirrored) { - spriteobject->draw_world_offset(x, y, z, 1, this); + spriteobject->assemble_world_offset(x, y, z, 1, this); } else { - spriteobject->draw_world(x, y, z, this); + spriteobject->assemble_world(x, y, z, this); } } } @@ -404,7 +403,7 @@ void Block::Assemble() if (spriteobject->get_sheetindex() == INVALID_INDEX) { //skip } else { - spriteobject->draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + spriteobject->assemble_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); } } @@ -448,9 +447,9 @@ void Block::Assemble() if(water.index > 0) { //if(waterlevel == 7) waterlevel--; if(water.type == 0) { - contentLoader->water[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + contentLoader->water[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); } else { - contentLoader->lava[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); + contentLoader->lava[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); } } @@ -584,7 +583,7 @@ void Block::Drawcreaturetext() // spriteobject->set_offset(0, -(FLOORHEIGHT)); // spriteobject->set_tile_layout(RAMPTOPTILE); // spriteobject->set_defaultsheet(IMGRampSheet); -// spriteobject->draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); +// spriteobject->assemble_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2)); // spriteobject->set_offset(0, 0); // } // spriteobject->set_tile_layout(BLOCKTILE); @@ -782,22 +781,3 @@ void Block::AssembleFloorBlood ( int32_t drawx, int32_t drawy ) } } -void Block::Draw(){ - if(visible) { - for(int i=0; i>> item; -}; - -struct Draw_Event{ - ALLEGRO_BITMAP *bitmap; - ALLEGRO_COLOR tint; - float sx; - float sy; - float sw; - float sh; - float dx; - float dy; - float dw; - float dh; - int flags; -}; - - -class Block -{ -public: - Block(WorldSegment* ownerSegment, df::tiletype type); - ~Block(void); - static void* operator new (size_t size); - static void operator delete (void *p); - bool visible; - - WorldSegment* ownerSegment; - - uint32_t x, y, z; - int drawx, drawy, drawz; - df::tiletype_shape_basic tileShapeBasic; - df::tiletype_shape tileShape; - df::tiletype_special tileSpecial; - df::tiletype_material tileMaterial; - df::tiletype tileType; - DFHack::t_matglossPair material; - DFHack::t_matglossPair layerMaterial; - DFHack::t_matglossPair veinMaterial; - bool hasVein; - - bool depthBorderNorth; - bool depthBorderWest; - bool depthBorderDown; - int shadow; - - uint8_t wallborders; - uint8_t floorborders; - uint8_t openborders; - uint8_t rampborders; - uint8_t upstairborders; - uint8_t downstairborders; - uint8_t lightborders; - - bool creaturePresent; - bool buildingPresent; - bool fog_of_war; - DFHack::t_matglossPair ramp; - DFHack::t_matglossPair water; - - //following are neighbor water levels (unused) - //DFHack::t_matglossPair abovewater; - //DFHack::t_matglossPair belowwater; - //DFHack::t_matglossPair rightwater; - //DFHack::t_matglossPair leftwater; - - DFHack::t_designation designation; - DFHack::t_occupancy occ; - DFHack::Units::t_unit * creature; - DFHack::t_matglossPair tree; - - int mudlevel; - int snowlevel; - int bloodlevel; - ALLEGRO_COLOR bloodcolor; - - uint8_t grasslevel; - uint32_t grassmat; - - uint8_t engraving_character; - df::engraving_flags engraving_flags; - uint8_t engraving_quality; - - //vector grasslevels; - //vector grassmats; - - //struct BlockEffects //size 40 - //{ - // uint16_t count; - // uint16_t type; - // DFHack::t_matglossPair material; - // int16_t lifetime; - // int16_t x_direction; - // int16_t y_direction; - // uint8_t canCreateNew;//?? - //} blockeffects; - - //individual effects - Effect Eff_Miasma; - Effect Eff_Steam; - Effect Eff_Mist; - Effect Eff_MaterialDust; - Effect Eff_MagmaMist; - Effect Eff_Smoke; - Effect Eff_Dragonfire; - Effect Eff_Fire; - Effect Eff_Web; - Effect Eff_MaterialGas; - Effect Eff_MaterialVapor; - Effect Eff_OceanWave; - Effect Eff_SeaFoam; - struct { - DFHack::Buildings::t_building info; - std::vector sprites; - uint32_t index; - Block * parent; - } building; - - bool IsVisible() { - return IDisWall(tileType) || IDisFloor(tileType); - } - void Assemble(); - void Drawcreaturetext(); - void AddRamptop(); - void AssembleFloorBlood ( int32_t drawx, int32_t drawy ); - void AssembleParticleCloud(int count, float centerX, float centerY, float rangeX, float rangeY, ALLEGRO_BITMAP *sprite, ALLEGRO_COLOR tint); - void AssembleSpriteFromSheet(int spriteNum, ALLEGRO_BITMAP* spriteSheet, ALLEGRO_COLOR color, float x, float y, Block * b=NULL, float in_scale=1.0f); - void AssembleSprite(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR tint, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, int flags); - void Draw(); - //void DrawPixel(int drawx, int drawy); - - uint16_t temp1; - uint16_t temp2; - - uint16_t consForm; - - bool obscuringCreature; - bool obscuringBuilding; - - struct SS_Item { - DFHack::t_matglossPair item; - DFHack::t_matglossPair matt; - DFHack::t_matglossPair dyematt; - } Item; - - //These are actually applied to the creature standing here, but there's only one creature shown, so it's okay. - Unit_Inventory * inv; - - -private: - std::vector todraw; - -}; -void createEffectSprites(); -void destroyEffectSprites(); -void initRandomCube(); - -//find a better place for these -bool hasWall(Block* b); -bool hasBuildingOfID(Block* b, int ID); -bool hasBuildingIdentity(Block* b, uint32_t index, int buildingOcc); -bool hasBuildingOfIndex(Block* b, uint32_t index); +#pragma once + +#include "common.h" +#include "SpriteObjects.h" +#include "TileTypes.h" +#include "df/item_type.h" + + +//not sure where to put these... + +inline bool IDisWall(int in) +{ + return isWallTerrain( (tiletype::tiletype) in ); +} + +inline bool IDisFloor(int in) +{ + return isFloorTerrain( (tiletype::tiletype) in ); +} + +inline bool IDhasOpaqueFloor(int in) +{ + return !FlowPassableDown( (tiletype::tiletype) in ); +} + +inline bool IDhasOpaqueSides(int in) +{ + return (!FlowPassable( (tiletype::tiletype) in )) && in != tiletype::Tree; +} + +class WorldSegment; + +struct Effect { + DFHack::t_matglossPair matt; + int16_t density; +}; + +struct Worn_Item { + DFHack::t_matglossPair matt; + DFHack::t_matglossPair dyematt; + int8_t rating; + Worn_Item(); +}; + +struct Unit_Inventory { + //[item_type][item_subtype][item_number] + std::vector>> item; +}; + +struct Draw_Event{ + ALLEGRO_BITMAP *bitmap; + ALLEGRO_COLOR tint; + float sx; + float sy; + float sw; + float sh; + float dx; + float dy; + float dw; + float dh; + int flags; +}; + +class Block +{ +public: + Block(WorldSegment* ownerSegment, df::tiletype type); + ~Block(void); + static void* operator new (size_t size); + static void operator delete (void *p); + bool visible; + + WorldSegment* ownerSegment; + + uint32_t x, y, z; + int drawx, drawy, drawz; + df::tiletype_shape_basic tileShapeBasic; + df::tiletype_shape tileShape; + df::tiletype_special tileSpecial; + df::tiletype_material tileMaterial; + df::tiletype tileType; + DFHack::t_matglossPair material; + DFHack::t_matglossPair layerMaterial; + DFHack::t_matglossPair veinMaterial; + bool hasVein; + + bool depthBorderNorth; + bool depthBorderWest; + bool depthBorderDown; + int shadow; + + uint8_t wallborders; + uint8_t floorborders; + uint8_t openborders; + uint8_t rampborders; + uint8_t upstairborders; + uint8_t downstairborders; + uint8_t lightborders; + + bool creaturePresent; + bool buildingPresent; + bool fog_of_war; + DFHack::t_matglossPair ramp; + DFHack::t_matglossPair water; + + //following are neighbor water levels (unused) + //DFHack::t_matglossPair abovewater; + //DFHack::t_matglossPair belowwater; + //DFHack::t_matglossPair rightwater; + //DFHack::t_matglossPair leftwater; + + DFHack::t_designation designation; + DFHack::t_occupancy occ; + DFHack::Units::t_unit * creature; + DFHack::t_matglossPair tree; + + int mudlevel; + int snowlevel; + int bloodlevel; + ALLEGRO_COLOR bloodcolor; + + uint8_t grasslevel; + uint32_t grassmat; + + uint8_t engraving_character; + df::engraving_flags engraving_flags; + uint8_t engraving_quality; + + //vector grasslevels; + //vector grassmats; + + //struct BlockEffects //size 40 + //{ + // uint16_t count; + // uint16_t type; + // DFHack::t_matglossPair material; + // int16_t lifetime; + // int16_t x_direction; + // int16_t y_direction; + // uint8_t canCreateNew;//?? + //} blockeffects; + + //individual effects + Effect Eff_Miasma; + Effect Eff_Steam; + Effect Eff_Mist; + Effect Eff_MaterialDust; + Effect Eff_MagmaMist; + Effect Eff_Smoke; + Effect Eff_Dragonfire; + Effect Eff_Fire; + Effect Eff_Web; + Effect Eff_MaterialGas; + Effect Eff_MaterialVapor; + Effect Eff_OceanWave; + Effect Eff_SeaFoam; + struct { + DFHack::Buildings::t_building info; + std::vector sprites; + uint32_t index; + Block * parent; + } building; + + bool IsVisible() { + return IDisWall(tileType) || IDisFloor(tileType); + } + void AssembleBlock(); + void Drawcreaturetext(); + void AddRamptop(); + void AssembleFloorBlood ( int32_t drawx, int32_t drawy ); + void AssembleParticleCloud(int count, float centerX, float centerY, float rangeX, float rangeY, ALLEGRO_BITMAP *sprite, ALLEGRO_COLOR tint); + void AssembleSpriteFromSheet(int spriteNum, ALLEGRO_BITMAP* spriteSheet, ALLEGRO_COLOR color, float x, float y, Block * b=NULL, float in_scale=1.0f); + void AssembleSprite(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR tint, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, int flags); + //void DrawPixel(int drawx, int drawy); + + uint16_t temp1; + uint16_t temp2; + + uint16_t consForm; + + bool obscuringCreature; + bool obscuringBuilding; + + struct SS_Item { + DFHack::t_matglossPair item; + DFHack::t_matglossPair matt; + DFHack::t_matglossPair dyematt; + } Item; + + //These are actually applied to the creature standing here, but there's only one creature shown, so it's okay. + Unit_Inventory * inv; + + +private: + +}; +void createEffectSprites(); +void destroyEffectSprites(); +void initRandomCube(); + +//find a better place for these +bool hasWall(Block* b); +bool hasBuildingOfID(Block* b, int ID); +bool hasBuildingIdentity(Block* b, uint32_t index, int buildingOcc); +bool hasBuildingOfIndex(Block* b, uint32_t index); bool wallShouldNotHaveBorders( int in ); \ No newline at end of file diff --git a/BlockTree.h b/BlockTree.h index 564bc5a7..003e07ad 100644 --- a/BlockTree.h +++ b/BlockTree.h @@ -1,91 +1,91 @@ -#pragma once -#include "common.h" -#include "SpriteObjects.h" -#include "Block.h" -#include "WorldSegment.h" - -class Block; - -class c_block_tree_twig -{ - c_sprite own_sprite; - vector westward_growth; - vector eastward_growth; -public: - c_block_tree_twig(void); - ~c_block_tree_twig(void); - - void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); - void set_single_sprite(void); - void set_sheetindex(int32_t in) { - own_sprite.set_sheetindex(in); - } - void set_fileindex(int32_t in) { - own_sprite.set_fileindex(in); - } - int32_t get_sheetindex(void) { - return own_sprite.get_sheetindex(); - } - void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); - void add_sprite(int x, c_sprite sprite); - void reset(); - - void draw_world(int x, int y, int z, Block * b, bool chop = false) { - own_sprite.draw_world(x,y,z,b,chop); - } -}; - -class c_block_tree_branch -{ - c_block_tree_twig own_twig; - vector northward_growth; - vector southward_growth; -public: - c_block_tree_branch(void); - ~c_block_tree_branch(void); - - void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); - void set_sheetindex(int32_t in) { - own_twig.set_sheetindex(in); - } - void set_fileindex(int32_t in) { - own_twig.set_fileindex(in); - } - int32_t get_sheetindex(void) { - return own_twig.get_sheetindex(); - } - void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); - void add_sprite(int x, int y, c_sprite sprite); - void reset(); - - void draw_world(int x, int y, int z, Block * b, bool chop = false) { - own_twig.draw_world(x,y,z,b,chop); - } -}; - -class c_block_tree -{ - c_block_tree_branch own_branch; - vector upward_growth; -public: - c_block_tree(void); - ~c_block_tree(void); - - void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); - void set_sheetindex(int32_t in) { - own_branch.set_sheetindex(in); - } - void set_fileindex(int32_t in) { - own_branch.set_fileindex(in); - } - int32_t get_sheetindex(void) { - return own_branch.get_sheetindex(); - } - void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); - void add_sprite(int x, int y, int z, c_sprite sprite); - void reset(); - - void draw_world(int x, int y, int z, Block * b, bool chop = false) { - own_branch.draw_world(x,y,z,b,chop); - } -}; +#pragma once +#include "common.h" +#include "SpriteObjects.h" +#include "Block.h" +#include "WorldSegment.h" + +class Block; + +class c_block_tree_twig +{ + c_sprite own_sprite; + vector westward_growth; + vector eastward_growth; +public: + c_block_tree_twig(void); + ~c_block_tree_twig(void); + + void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); + void set_single_sprite(void); + void set_sheetindex(int32_t in) { + own_sprite.set_sheetindex(in); + } + void set_fileindex(int32_t in) { + own_sprite.set_fileindex(in); + } + int32_t get_sheetindex(void) { + return own_sprite.get_sheetindex(); + } + void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); + void add_sprite(int x, c_sprite sprite); + void reset(); + + void assemble_world(int x, int y, int z, Block * b, bool chop = false) { + own_sprite.assemble_world(x,y,z,b,chop); + } +}; + +class c_block_tree_branch +{ + c_block_tree_twig own_twig; + vector northward_growth; + vector southward_growth; +public: + c_block_tree_branch(void); + ~c_block_tree_branch(void); + + void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); + void set_sheetindex(int32_t in) { + own_twig.set_sheetindex(in); + } + void set_fileindex(int32_t in) { + own_twig.set_fileindex(in); + } + int32_t get_sheetindex(void) { + return own_twig.get_sheetindex(); + } + void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); + void add_sprite(int x, int y, c_sprite sprite); + void reset(); + + void assemble_world(int x, int y, int z, Block * b, bool chop = false) { + own_twig.assemble_world(x,y,z,b,chop); + } +}; + +class c_block_tree +{ + c_block_tree_branch own_branch; + vector upward_growth; +public: + c_block_tree(void); + ~c_block_tree(void); + + void insert_sprites(WorldSegment * w, int x, int y, int z, Block * parent); + void set_sheetindex(int32_t in) { + own_branch.set_sheetindex(in); + } + void set_fileindex(int32_t in) { + own_branch.set_fileindex(in); + } + int32_t get_sheetindex(void) { + return own_branch.get_sheetindex(); + } + void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); + void add_sprite(int x, int y, int z, c_sprite sprite); + void reset(); + + void assemble_world(int x, int y, int z, Block * b, bool chop = false) { + own_branch.assemble_world(x,y,z,b,chop); + } +}; diff --git a/Config.cpp b/Config.cpp index e8e217ed..aaec973d 100644 --- a/Config.cpp +++ b/Config.cpp @@ -262,6 +262,13 @@ void parseConfigLine( string line ) } ssConfig.viewZoffset = value; } + if( line.find("[BITMAP_HOLDS") != -1) { + int value = parseIntFromLine( "BITMAP_HOLDS", line); + if(value < 1) { + value = 1; + } + ssConfig.bitmapHolds = value; + } if( line.find("[LOG_IMAGECACHE") != -1) { string result = parseStrFromLine( "LOG_IMAGECACHE", line ); ssConfig.saveImageCache = (result == "YES"); diff --git a/Creatures.cpp b/Creatures.cpp index 4517c186..82fd797b 100644 --- a/Creatures.cpp +++ b/Creatures.cpp @@ -209,7 +209,7 @@ void AssembleCreature(int drawx, int drawy, t_unit* creature, Block * b) { c_sprite * sprite = GetCreatureSpriteMap( creature ); if(sprite) { - sprite->draw_world(creature->x,creature->y, creature->z, b); + sprite->assemble_world(creature->x,creature->y, creature->z, b); } else { df::creature_raw *raw = df::global::world->raws.creatures.all[creature->race]; int spritenum = raw->creature_tile; diff --git a/GUI.cpp b/GUI.cpp index bd994fec..79c8e8ec 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -1222,7 +1222,6 @@ void saveImage(ALLEGRO_BITMAP* image) void saveMegashot(bool tall) { - ssConfig.showRenderStatus = true; al_lock_mutex(ssConfig.readMutex); draw_textf_border(font, al_map_rgb(255,255,255), ssState.ScreenW/2, ssState.ScreenH/2, ALLEGRO_ALIGN_CENTRE, "saving large screenshot..."); @@ -1346,7 +1345,6 @@ void saveMegashot(bool tall) ssConfig.fogenable = tempfog; ssConfig.follow_DFscreen = tempFollow; ssConfig.lift_segment_offscreen = tempLift; - ssConfig.showRenderStatus = false; al_unlock_mutex(ssConfig.readMutex); } diff --git a/SpriteObjects.cpp b/SpriteObjects.cpp index 9a7c9783..c769a567 100644 --- a/SpriteObjects.cpp +++ b/SpriteObjects.cpp @@ -624,16 +624,7 @@ void c_sprite::set_by_xml(TiXmlElement *elemSprite) // } //} -inline void c_sprite::draw_world(int x, int y, int z, Block * b, bool chop) -{ - draw_world_offset_src(x, y, z, 0, b, b, chop); -} - -inline void c_sprite::draw_world_offset(int x, int y, int z, int tileoffset, Block * b, bool chop){ - draw_world_offset_src(x, y, z, tileoffset, b, b, chop); -} - -void c_sprite::draw_world_offset_src(int x, int y, int z, int tileoffset, Block * b, Block* src, bool chop) +void c_sprite::assemble_world_offset_src(int x, int y, int z, int tileoffset, Block * b, Block* src, bool chop) { if(defaultsheet == 0) { defaultsheet = IMGObjectSheet; @@ -898,7 +889,7 @@ void c_sprite::draw_world_offset_src(int x, int y, int z, int tileoffset, Block draw_subsprite: if(!subsprites.empty()) { for(int i = 0; i < subsprites.size(); i++) { - subsprites.at(i).draw_world_offset_src(x, y, z, tileoffset, b, src, chop); + subsprites.at(i).assemble_world_offset_src(x, y, z, tileoffset, b, src, chop); } } } diff --git a/SpriteObjects.h b/SpriteObjects.h index fbc09b9b..ad3aaa14 100644 --- a/SpriteObjects.h +++ b/SpriteObjects.h @@ -111,10 +111,15 @@ class c_sprite c_sprite(void); ~c_sprite(void); //void draw_screen(int x, int y); - inline void draw_world(int x, int y, int z, Block * b, bool chop = false); - inline void draw_world_offset(int x, int y, int z, int tileoffset, Block * b, bool chop = false); - void draw_world_offset_src(int x, int y, int z, int tileoffset, Block * b, Block* src, bool chop = false); - void draw_world_ramp_bottom(int x, int y, int z, bool chop = false); + void assemble_world_offset_src(int x, int y, int z, int tileoffset, Block * b, Block* src, bool chop = false); + inline void c_sprite::assemble_world(int x, int y, int z, Block * b, bool chop=false) + { + assemble_world_offset_src(x, y, z, 0, b, b, chop); + } + inline void c_sprite::assemble_world_offset(int x, int y, int z, int tileoffset, Block * b, bool chop=false){ + assemble_world_offset_src(x, y, z, tileoffset, b, b, chop); + } + void assemble_world_ramp_bottom(int x, int y, int z, bool chop = false); void set_by_xml(TiXmlElement* elemSprite, int32_t fileindex); void set_by_xml(TiXmlElement* elemSprite); int32_t get_sheetindex(void) { diff --git a/WorldSegment.cpp b/WorldSegment.cpp index 6ffca548..6e5b047c 100644 --- a/WorldSegment.cpp +++ b/WorldSegment.cpp @@ -242,60 +242,76 @@ void WorldSegment::DrawAllBlocks() return; } - // x,y,z print pricess - ALLEGRO_BITMAP * temp = al_get_target_bitmap(); - int32_t vsxmax = sizex-1; - int32_t vsymax = sizey-1; - int32_t vszmax = sizez-1; // grabbing one tile +z more than we should for tile rules - //al_hold_bitmap_drawing(true); - - for(int32_t vsz=0; vsz < vszmax; vsz++) { - if(ssConfig.showRenderStatus) { - SetTitle("Stonesense - Drawing Terrain, Level %d/%d", (vsz+1), vszmax); - } - if(ssConfig.fogenable) { - if(!fog) { - fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); - al_set_target_bitmap(fog); - al_clear_to_color(premultiply(ssConfig.fogcol)); - al_set_target_bitmap(temp); - } - if(!((al_get_bitmap_width(fog) == al_get_bitmap_width(temp)) && (al_get_bitmap_height(fog) == al_get_bitmap_height(temp)))) { - al_destroy_bitmap(fog); - fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); - al_set_target_bitmap(fog); - al_clear_to_color(premultiply(ssConfig.fogcol)); - al_set_target_bitmap(temp); - } - al_draw_bitmap(fog, 0, 0, 0); - } - if(vsz == vszmax-1) { - if (ssConfig.show_osd) { - DrawCurrentLevelOutline(true); - } + //TODO bring fog back - figuring out allegro shaders would probably be a good idea + + //// x,y,z print pricess + //int32_t vsxmax = sizex-1; + //int32_t vsymax = sizey-1; + //int32_t vszmax = sizez-1; // grabbing one tile +z more than we should for tile rules + + //for(int32_t vsz=0; vsz < vszmax; vsz++) { + // if(ssConfig.fogenable) { + // if(!fog) { + // fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); + // al_set_target_bitmap(fog); + // al_clear_to_color(premultiply(ssConfig.fogcol)); + // al_set_target_bitmap(temp); + // } + // if(!((al_get_bitmap_width(fog) == al_get_bitmap_width(temp)) && (al_get_bitmap_height(fog) == al_get_bitmap_height(temp)))) { + // al_destroy_bitmap(fog); + // fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); + // al_set_target_bitmap(fog); + // al_clear_to_color(premultiply(ssConfig.fogcol)); + // al_set_target_bitmap(temp); + // } + // al_draw_bitmap(fog, 0, 0, 0); + // } + // if(vsz == vszmax-1) { + // } + + // al_hold_bitmap_drawing(false); + //} + if(ssConfig.fogenable) { + ALLEGRO_BITMAP* temp = al_get_target_bitmap(); + if(!fog) { + fog = al_create_bitmap(ssState.ScreenW, ssState.ScreenH); + al_set_target_bitmap(fog); + al_clear_to_color(premultiply(ssConfig.fogcol)); + al_set_target_bitmap(temp); } - for(int32_t vsx=1; vsx < vsxmax; vsx++) { - for(int32_t vsy=1; vsy < vsymax; vsy++) { - Block *b = getBlockLocal(vsx,vsy,vsz); - if (b) { - b->Draw(); - } - } + if(!((al_get_bitmap_width(fog) == ssState.ScreenW) && (al_get_bitmap_height(fog) == ssState.ScreenH))) { + al_destroy_bitmap(fog); + fog = al_create_bitmap(ssState.ScreenW, ssState.ScreenH); + al_set_target_bitmap(fog); + al_clear_to_color(premultiply(ssConfig.fogcol)); + al_set_target_bitmap(temp); } - al_hold_bitmap_drawing(false); + } + + if(todraw.size()>0){ al_hold_bitmap_drawing(true); - for(int32_t vsx=1; vsx < vsxmax; vsx++) { - for(int32_t vsy=1; vsy < vsymax; vsy++) { - Block *b = getBlockLocal(vsx,vsy,vsz); - if (b) { - b->Drawcreaturetext(); - } + for(int i=0; iAssemble(); + b->AssembleBlock(); } - //if (b==NULL || (b->tileShapeBasic!=tiletype_shape_basic::Floor && b->tileShapeBasic!=tiletype_shape_basic::Ramp && b->tileShapeBasic==tiletype_shape_basic::Wall)) { - // Block* bLow = getBlockLocal(vsx,vsy,vsz-1); - // if (bLow != NULL) { - // bLow->AddRamptop(); - // } - //} } } } @@ -371,4 +389,9 @@ bool WorldSegment::CoordinateInteriorSegment(uint32_t x, uint32_t y, uint32_t z, // b->DrawPixel(vsx, (vsz*this->sizey) + vsy); // } // } -//} \ No newline at end of file +//} + +void WorldSegment::AssembleSprite(Draw_Event d) +{ + todraw.push_back(d); +} \ No newline at end of file diff --git a/WorldSegment.h b/WorldSegment.h index 11e1b0b0..26bf9ef8 100644 --- a/WorldSegment.h +++ b/WorldSegment.h @@ -8,6 +8,7 @@ class WorldSegment { private: vector blocks; + vector todraw; public: bool loaded; bool processed; @@ -58,6 +59,7 @@ class WorldSegment void CorrectBlockForSegmentOffset(int32_t& x, int32_t& y, int32_t& z); void addBlock(Block* b); void AssembleAllBlocks(); + void AssembleSprite(Draw_Event d); void DrawAllBlocks(); //void drawPixels(); bool CoordinateInsideSegment(uint32_t x, uint32_t y, uint32_t z); diff --git a/commonTypes.h b/commonTypes.h index baeb2bd4..18b75028 100644 --- a/commonTypes.h +++ b/commonTypes.h @@ -153,6 +153,8 @@ struct GameConfiguration { unsigned int cellDimY; unsigned int cellDimZ; + int bitmapHolds; + bool saveImageCache; bool cache_images; int imageCacheSize; @@ -168,7 +170,6 @@ struct GameConfiguration { bool creditScreen; int currentSpriteOverlay; - bool showRenderStatus; bool dayNightCycle; bool show_creature_moods; diff --git a/main.cpp b/main.cpp index 63bfec5d..60141691 100644 --- a/main.cpp +++ b/main.cpp @@ -377,6 +377,7 @@ static void * stonesense_thread(ALLEGRO_THREAD * main_thread, void * parms) ssConfig.fogcol = al_map_rgba(255, 255, 255, 255); ssConfig.backcol = al_map_rgb(95, 95, 160); ssConfig.fogenable = true; + ssConfig.bitmapHolds = 4096; ssConfig.imageCacheSize = 4096; ssConfig.fontsize = 10; ssConfig.font = al_create_path("data/art/font.ttf"); diff --git a/resources/init.txt b/resources/init.txt index f050b1a9..69416310 100644 --- a/resources/init.txt +++ b/resources/init.txt @@ -108,6 +108,11 @@ if trying having issues with sprite configuration tweaking. --Troubleshooting-- +Thi is the number of draw operations that will be held at a time. Holding draw operations allows +for those draws to be carried out efficiently if they have the same source. May be tweaked for +performance gains. +[BITMAP_HOLDS:4096] + Stonesense will try to merge all loaded sprites into a single texture, for performance reasons. if your videocard has low memory, you may want to disable this. [CACHE_IMAGES:NO]