Skip to content

Commit

Permalink
Changed WorldSegment position to use Crd3D struct. Misc changes to ma…
Browse files Browse the repository at this point in the history
…ke Tiles take less memory.
  • Loading branch information
Caldfir authored and RosaryMala committed Dec 15, 2012
1 parent a576af7 commit a57449a
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CreatureConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<Creature
int defaultFile = basefile;
c_sprite sprite;
sprite.set_fileindex(basefile);
int baseShadow = DEFAULT_SHADOW;
uint8_t baseShadow = DEFAULT_SHADOW;
const char* shadowStr = elemCreature->Attribute("shadow");
if (shadowStr != NULL && shadowStr[0] != 0) {
baseShadow = atoi( shadowStr );
Expand Down
18 changes: 9 additions & 9 deletions Creatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)
if(ssConfig.skipCreatures) {
return;
}
int x1 = segment->x;
int x2 = segment->x + segment->size.x;
int y1 = segment->y;
int y2 = segment->y + segment->size.y;
int z1 = segment->z;
int z2 = segment->z + segment->size.z;
int x1 = segment->pos.x;
int x2 = segment->pos.x + segment->size.x;
int y1 = segment->pos.y;
int y2 = segment->pos.y + segment->size.y;
int z1 = segment->pos.z;
int z2 = segment->pos.z + segment->size.z;
uint32_t numcreatures;

numcreatures = DFHack::Units::getNumCreatures();
Expand Down Expand Up @@ -413,7 +413,7 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)
floor_tile->tileShapeBasic()==tiletype_shape_basic::Wall ||
floor_tile->tileShapeBasic()==tiletype_shape_basic::Ramp) {
// todo figure out appropriate shadow size
int tempShadow = GetCreatureShadowMap( tempcreature );
uint8_t tempShadow = GetCreatureShadowMap( tempcreature );
if (floor_tile->shadow < tempShadow) {
floor_tile->shadow=tempShadow;
}
Expand Down Expand Up @@ -587,11 +587,11 @@ c_sprite* GetCreatureSpriteMap( t_unit* c )
return &(testConfig->sprite);
}

int GetCreatureShadowMap( t_unit* c )
uint8_t GetCreatureShadowMap( t_unit* c )
{
CreatureConfiguration *testConfig = GetCreatureConfig( c );
if (testConfig == NULL) {
return 4;
return DEFAULT_SHADOW;
}
return testConfig->shadow;
}
Expand Down
2 changes: 1 addition & 1 deletion Creatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void AssembleCreature(int drawx, int drawy, t_unit* creature, Tile * b);
void AssembleCreatureText(int drawx, int drawy, t_unit* creature, WorldSegment * b);
void DrawCreatureText(int drawx, int drawy, t_unit* creature );
c_sprite* GetCreatureSpriteMap( t_unit* c );
int GetCreatureShadowMap( t_unit* c );
uint8_t GetCreatureShadowMap( t_unit* c );


void generateCreatureDebugString( t_unit* c, char* strbuffer);
Expand Down
4 changes: 2 additions & 2 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ void DrawMinimap(WorldSegment * segment)
int mapheight = (int)(segment->regionSize.y * oneTileInPixels);
al_draw_rectangle(posx, posy, posx+size, posy+mapheight, al_map_rgb(0,0,0),0);
//current segment outline
int x = (size * (segment->x+1)) / segment->regionSize.x;
int y = (mapheight * (segment->y+1)) / segment->regionSize.y;
int x = (size * (segment->pos.x+1)) / segment->regionSize.x;
int y = (mapheight * (segment->pos.y+1)) / segment->regionSize.y;
MiniMapSegmentWidth = (segment->size.x-2) * oneTileInPixels;
MiniMapSegmentHeight = (segment->size.y-2) * oneTileInPixels;
al_draw_rectangle(posx+x, posy+y, posx+x+MiniMapSegmentWidth, posy+y+MiniMapSegmentHeight,al_map_rgb(0,0,0),0);
Expand Down
28 changes: 14 additions & 14 deletions MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool threadrunnng = 0;
segParams parms;

//big look up table
char rampblut[] =
uint8_t rampblut[] =
// generated by blutmaker.py
{
1 , 2 , 8 , 2 , 4 , 12 , 4 , 12 , 9 , 2 , 21 , 2 , 4 , 12 , 4 , 12 ,
Expand Down Expand Up @@ -85,12 +85,12 @@ inline bool isTileHighRampTop(uint32_t x, uint32_t y, uint32_t z, WorldSegment*

inline bool isTileOnTopOfSegment(WorldSegment* segment, Tile* b)
{
return b->z == segment->z + segment->size.z - 2;
return b->z == segment->pos.z + segment->size.z - 2;
}

int CalculateRampType(uint32_t x, uint32_t y, uint32_t z, WorldSegment* segment)
uint8_t CalculateRampType(uint32_t x, uint32_t y, uint32_t z, WorldSegment* segment)
{
int ramplookup = 0;
int32_t ramplookup = 0;
if (isTileHighRampEnd(x, y, z, segment, eUp) && isTileHighRampTop(x, y, z+1, segment, eUp)) {
ramplookup ^= 1;
}
Expand Down Expand Up @@ -152,38 +152,38 @@ int CalculateRampType(uint32_t x, uint32_t y, uint32_t z, WorldSegment* segment)

bool isTileOnVisibleEdgeOfSegment(WorldSegment* segment, Tile* b)
{
if(b->z == segment->z + segment->size.z - 2) {
if(b->z == segment->pos.z + segment->size.z - 2) {
return true;
}

if (ssState.DisplayedRotation == 0 &&
(
b->x == segment->x + segment->size.x - 2
|| b->y == segment->y + segment->size.y - 2
b->x == segment->pos.x + segment->size.x - 2
|| b->y == segment->pos.y + segment->size.y - 2
|| b->x == segment->regionSize.x - 1
|| b->y == segment->regionSize.y - 1
)) {
return true;
} else if (ssState.DisplayedRotation == 1 &&
(
b->x == segment->x + segment->size.x - 2
|| b->y == segment->y + 1
b->x == segment->pos.x + segment->size.x - 2
|| b->y == segment->pos.y + 1
|| b->x == segment->regionSize.x - 1
|| b->y == 0
)) {
return true;
} else if (ssState.DisplayedRotation == 2 &&
(
b->x == segment->x + 1
|| b->y == segment->y + 1
b->x == segment->pos.x + 1
|| b->y == segment->pos.y + 1
|| b->x == 0
|| b->y == 0
)) {
return true;
} else if (ssState.DisplayedRotation == 3 &&
(
b->x == segment->x + 1
|| b->y == segment->y + segment->size.y - 2
b->x == segment->pos.x + 1
|| b->y == segment->pos.y + segment->size.y - 2
|| b->x == 0
|| b->y == segment->regionSize.y - 1
)) {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ void beautify_Segment(WorldSegment * segment)

//setup ramps
if(b->tileShapeBasic()==tiletype_shape_basic::Ramp) {
b->ramp.index = CalculateRampType(b->x, b->y, b->z, segment);
b->rampindex = CalculateRampType(b->x, b->y, b->z, segment);
}
//add edges to tiles and floors

Expand Down
4 changes: 2 additions & 2 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,10 @@ void c_sprite::assemble_world_offset_src(int x, int y, int z, int plateoffset, T
sheetx = ((sheetindex+plateoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth;
sheety = ((sheetindex+plateoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight;
} else if(platelayout == RAMPBOTTOMPLATE) {
sheetx = SPRITEWIDTH * src->ramp.index;
sheetx = SPRITEWIDTH * src->rampindex;
sheety = ((PLATEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+plateoffset+randoffset))+(PLATEHEIGHT + FLOORHEIGHT);
} else if(platelayout == RAMPTOPPLATE) {
sheetx = SPRITEWIDTH * src->ramp.index;
sheetx = SPRITEWIDTH * src->rampindex;
sheety = (PLATEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+plateoffset+randoffset);
} else {
sheetx = ((sheetindex+plateoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth;
Expand Down
16 changes: 8 additions & 8 deletions Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ void Tile::AssembleTile()
t_SpriteWithOffset sprite;
c_sprite* spriteobject;

drawx = x;
drawy = y;
drawz = z;
int32_t drawx = x;
int32_t drawy = y;
int32_t drawz = z;

ownerSegment->CorrectTileForSegmentOffset( drawx, drawy, drawz);
ownerSegment->CorrectTileForSegmentRotation( drawx, drawy, drawz);
Expand Down Expand Up @@ -202,7 +202,7 @@ void Tile::AssembleTile()
spriteobject->set_size(SPRITEWIDTH, PLATEHEIGHT);
spriteobject->set_plate_layout(RAMPTOPPLATE);
spriteobject->set_offset(0, WALLHEIGHT);
spriteobject->assemble_world_offset_src(x, y, z, 0, this, b, (chopThisTile && this->z == ownerSegment->z + ownerSegment->size.z -2));
spriteobject->assemble_world_offset_src(x, y, z, 0, this, b, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2));
spriteobject->set_offset(0, 0);
}
spriteobject->set_plate_layout(TILEPLATE);
Expand Down Expand Up @@ -274,7 +274,7 @@ void Tile::AssembleTile()
if (spriteobject->get_sheetindex() != INVALID_INDEX) {
spriteobject->set_size(SPRITEWIDTH, SPRITEHEIGHT);
spriteobject->set_plate_layout(RAMPBOTTOMPLATE);
spriteobject->assemble_world_offset(x, y, z, 0, this, (chopThisTile && this->z == ownerSegment->z + ownerSegment->size.z -2));
spriteobject->assemble_world_offset(x, y, z, 0, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2));
}
spriteobject->set_plate_layout(TILEPLATE);
}
Expand Down Expand Up @@ -380,7 +380,7 @@ void Tile::AssembleTile()
if (spriteobject->get_sheetindex() == INVALID_INDEX) {
//skip
} else {
spriteobject->assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->z + ownerSegment->size.z -2));
spriteobject->assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2));
}
}

Expand Down Expand Up @@ -424,9 +424,9 @@ void Tile::AssembleTile()
if(water.index > 0) {
//if(waterlevel == 7) waterlevel--;
if(water.type == 0) {
contentLoader->water[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->z + ownerSegment->size.z -2));
contentLoader->water[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2));
} else {
contentLoader->lava[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->z + ownerSegment->size.z -2));
contentLoader->lava[water.index-1].sprite.assemble_world(x, y, z, this, (chopThisTile && this->z == ownerSegment->pos.z + ownerSegment->size.z -2));
}
}

Expand Down
18 changes: 11 additions & 7 deletions Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Tile
WorldSegment* ownerSegment;

uint32_t x, y, z;
int drawx, drawy, drawz;
//int drawx, drawy, drawz;
df::tiletype tileType;
DFHack::t_matglossPair material;
DFHack::t_matglossPair layerMaterial;
Expand All @@ -45,7 +45,8 @@ class Tile
bool depthBorderNorth;
bool depthBorderWest;
bool depthBorderDown;
int shadow;

uint8_t shadow;

uint8_t wallborders;
uint8_t floorborders;
Expand All @@ -55,11 +56,13 @@ class Tile
uint8_t downstairborders;
uint8_t lightborders;

bool creaturePresent;
bool buildingPresent;
bool fog_of_war;
DFHack::t_matglossPair ramp;
DFHack::t_matglossPair water;
bool creaturePresent;//contained in occ
bool buildingPresent;//contained in occ
bool fog_of_war;//contained in designation

uint8_t rampindex;

DFHack::t_matglossPair water;//contained in designation

//following are neighbor water levels (unused)
//DFHack::t_matglossPair abovewater;
Expand All @@ -69,6 +72,7 @@ class Tile

DFHack::t_designation designation;
DFHack::t_occupancy occ;

DFHack::Units::t_unit * creature;
DFHack::t_matglossPair tree;

Expand Down
2 changes: 1 addition & 1 deletion TileTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void c_tile_tree::insert_sprites(WorldSegment *w, int x, int y, int z, Tile * pa
b->tileShapeBasic()==tiletype_shape_basic::Floor ||
b->tileShapeBasic()==tiletype_shape_basic::Wall ||
b->tileShapeBasic()==tiletype_shape_basic::Stair)) ||
((z + i + 1) > w->z + w->size.z)
((z + i + 1) > w->pos.z + w->size.z)
) {
break;
}
Expand Down
Loading

0 comments on commit a57449a

Please sign in to comment.