Skip to content

Commit

Permalink
remove terrible ancient global variable
Browse files Browse the repository at this point in the history
BREAK MEGASHOTS AGAIN ಠ_ಠ
  • Loading branch information
Caldfir committed Sep 8, 2013
1 parent 787ad84 commit 3601170
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 240 deletions.
18 changes: 9 additions & 9 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ void parseConfigLine( string line )
string result = parseStrFromLine( "WINDOWED", line );
ssConfig.Fullscreen = (result == "NO");
}
if( line.find("[SEGMENTSIZE_XY") != -1) {
int value = parseIntFromLine( "SEGMENTSIZE_XY", line );
if( line.find("[Size_XY") != -1) {
int value = parseIntFromLine( "Size_XY", line );
if(value < 1) {
value = DEFAULT_SEGMENTSIZE;
value = DEFAULT_Size;
}
if(value > 100) {
value = 100;
}
//plus 2 to allow edge readings
ssState.SegmentSize.x = value+2;
ssState.SegmentSize.y = value+2;
ssState.Size.x = value+2;
ssState.Size.y = value+2;
}
if( line.find("[SEGMENTSIZE_Z") != -1) {
int value = parseIntFromLine( "SEGMENTSIZE_Z", line );
if( line.find("[Size_Z") != -1) {
int value = parseIntFromLine( "Size_Z", line );
if(value < 1) {
value = DEFAULT_SEGMENTSIZE_Z;
value = DEFAULT_Size_Z;
}
ssState.SegmentSize.z = value;
ssState.Size.z = value;
}

if( line.find("[ALLCREATURES") != -1) {
Expand Down
12 changes: 6 additions & 6 deletions DumpInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void dumpSegment()
al_lock_mutex(ssConfig.readMutex);
//back up all the relevant values
Crd3D tempSize = ssState.SegmentSize;
int tempViewx = DisplayedSegment.x;
int tempViewy = DisplayedSegment.y;
Crd3D tempSize = ssState.Size;
int tempViewx = Position.x;
int tempViewy = Position.y;
bool tempFollow = ssConfig.follow_DFscreen;
int tempLift = ssConfig.lift_segment_offscreen_y;
int currentFlags = al_get_new_bitmap_flags();
Expand Down Expand Up @@ -95,9 +95,9 @@ void dumpSegment()
al_set_new_bitmap_flags(tempFlags);
//restore everything that we changed.
ssState.SegmentSize = tempSize;
DisplayedSegment.x = tempViewx;
DisplayedSegment.y = tempViewy;
ssState.Size = tempSize;
Position.x = tempViewx;
Position.y = tempViewy;
ssConfig.follow_DFscreen = tempFollow;
ssConfig.lift_segment_offscreen_y = tempLift;
Expand Down
73 changes: 40 additions & 33 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void ScreenToPoint(int x,int y,int &x1, int &y1, int &z1, int segSizeX, int segS
void ScreenToPoint(int x,int y,int &x1, int &y1, int &z1)
{
if(ssConfig.track_screen_center){
ScreenToPoint(x, y, x1, y1, z1, ssState.SegmentSize.x, ssState.SegmentSize.y, ssState.ScreenW, ssState.ScreenH);
ScreenToPoint(x, y, x1, y1, z1, ssState.Size.x, ssState.Size.y, ssState.ScreenW, ssState.ScreenH);
} else {
ScreenToPoint(x, y, x1, y1, z1, 0, 0, 0, 0);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ void pointToScreen(int *inx, int *iny, int inz, int segSizeX, int segSizeY, int
void pointToScreen(int *inx, int *iny, int inz)
{
if(ssConfig.track_screen_center){
pointToScreen(inx, iny, inz, ssState.SegmentSize.x, ssState.SegmentSize.y, ssState.ScreenW, ssState.ScreenH);
pointToScreen(inx, iny, inz, ssState.Size.x, ssState.Size.y, ssState.ScreenW, ssState.ScreenH);
} else {
pointToScreen(inx, iny, inz, 0, 0, 0, 0);
}
Expand Down Expand Up @@ -312,6 +312,13 @@ void draw_ustr_border(const ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, fl
al_draw_ustr(font, color, x, y, flags, ustr);
}

void correctTileForDisplayedOffset(int32_t& x, int32_t& y, int32_t& z)
{
x -= ssState.Position.x;
y -= ssState.Position.y; //Position.y;
z -= ssState.Position.z - 1; // + viewedSegment->sizez - 2; // loading one above the top of the displayed segment for tile rules
}

/**
* Corrects the coordinate (x,y) for rotation in a region of size (szx, szy).
*/
Expand Down Expand Up @@ -350,11 +357,11 @@ Crd2D LocalTileToScreen(int32_t x, int32_t y, int32_t z)

void DrawCurrentLevelOutline(bool backPart)
{
int x = ssState.DisplayedSegment.x+1;
int y = ssState.DisplayedSegment.y+1;
int z = ssState.DisplayedSegment.z;
int sizex = ssState.SegmentSize.x-2;
int sizey = ssState.SegmentSize.y-2;
int x = ssState.Position.x+1;
int y = ssState.Position.y+1;
int z = ssState.Position.z;
int sizex = ssState.Size.x-2;
int sizey = ssState.Size.y-2;

if(ssConfig.hide_outer_tiles) {
x++;
Expand Down Expand Up @@ -424,7 +431,7 @@ void drawDebugCursorAndInfo(WorldSegment * segment)
0);

//get tile info
Tile* b = segment->getTileLocal( debugCursor.x, debugCursor.y, debugCursor.z+segment->size.z-2);
Tile* b = segment->getTileLocal( debugCursor.x, debugCursor.y, debugCursor.z+segment->segState.Size.z-2);
int i = 10;
draw_textf_border(font, al_map_rgb(255,255,255), 2, (i++*al_get_font_line_height(font)), 0, "Tile 0x%x", b);

Expand Down Expand Up @@ -870,10 +877,10 @@ void DrawMinimap(WorldSegment * segment)
int mapheight = (int)(segment->segState.RegionDim.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->pos.x+1)) / segment->segState.RegionDim.x;
int y = (mapheight * (segment->pos.y+1)) / segment->segState.RegionDim.y;
MiniMapSegmentWidth = (segment->size.x-2) * oneTileInPixels;
MiniMapSegmentHeight = (segment->size.y-2) * oneTileInPixels;
int x = (size * (segment->segState.Position.x+1)) / segment->segState.RegionDim.x;
int y = (mapheight * (segment->segState.Position.y+1)) / segment->segState.RegionDim.y;
MiniMapSegmentWidth = (segment->segState.Size.x-2) * oneTileInPixels;
MiniMapSegmentHeight = (segment->segState.Size.y-2) * oneTileInPixels;
al_draw_rectangle(posx+x, posy+y, posx+x+MiniMapSegmentWidth, posy+y+MiniMapSegmentHeight,al_map_rgb(0,0,0),0);
MiniMapTopLeftX = posx;
MiniMapTopLeftY = posy;
Expand Down Expand Up @@ -1005,7 +1012,7 @@ void paintboard()
al_hold_bitmap_drawing(false);
} else if (ssConfig.show_osd) {
al_hold_bitmap_drawing(true);
draw_textf_border(font, al_map_rgb(255,255,255), 10,al_get_font_line_height(font), 0, "%i,%i,%i, r%i, z%i", ssState.DisplayedSegment.x,ssState.DisplayedSegment.y,ssState.DisplayedSegment.z, ssState.DisplayedRotation, ssConfig.zoom);
draw_textf_border(font, al_map_rgb(255,255,255), 10,al_get_font_line_height(font), 0, "%i,%i,%i, r%i, z%i", ssState.Position.x,ssState.Position.y,ssState.Position.z, ssState.DisplayedRotation, ssConfig.zoom);

if(ssConfig.debug_mode) {
draw_textf_border(font, al_map_rgb(255,255,255), 10, 3*al_get_font_line_height(font), 0, "Map Read Time: %.2fms", ssTimers.read_time);
Expand Down Expand Up @@ -1381,7 +1388,7 @@ void saveMegashot(bool tall)
if(tall) {
ssState.ScreenH = ( ((ssState.RegionDim.x + ssState.RegionDim.y) * TILETOPHEIGHT / 2) + (ssState.RegionDim.z * TILEHEIGHT) )*ssConfig.scale;
} else {
ssState.ScreenH = ( ((ssState.RegionDim.x + ssState.RegionDim.y) * TILETOPHEIGHT / 2) + ((ssState.SegmentSize.z - 1) * TILEHEIGHT) )*ssConfig.scale;
ssState.ScreenH = ( ((ssState.RegionDim.x + ssState.RegionDim.y) * TILETOPHEIGHT / 2) + ((ssState.Size.z - 1) * TILEHEIGHT) )*ssConfig.scale;
}

bigFile = al_create_bitmap(ssState.ScreenW, ssState.ScreenH);
Expand Down Expand Up @@ -1418,45 +1425,45 @@ void saveMegashot(bool tall)
switch(ssState.DisplayedRotation){
case 0:
case 2:
incrx = parms.sizex-2;
incry = parms.sizey-2;
incrx = ssState.Size.x-2;
incry = ssState.Size.y-2;
numx = (int)(ssState.RegionDim.x+3);
numy = (int)(ssState.RegionDim.y+3);
break;
case 1:
case 3:
incrx = parms.sizey-2;
incry = parms.sizex-2;
incrx = ssState.Size.y-2;
incry = ssState.Size.x-2;
numx = (int)(ssState.RegionDim.y+3);
numy = (int)(ssState.RegionDim.x+3);
break;
}
numx = numx/incrx + (numx%incrx==0 ? 0 : 1);
numy = numy/incry + (numx%incry==0 ? 0 : 1);
numz = tall ? ((ssState.RegionDim.z/(parms.sizez-1)) + 1) : 1;
numz = tall ? ((ssState.RegionDim.z/(ssState.Size.z-1)) + 1) : 1;


if(ssState.DisplayedRotation == 1 || ssState.DisplayedRotation == 2) {
starty = (int)ssState.RegionDim.y + 2 - incry;
ssState.DisplayedSegment.y = (int)ssState.RegionDim.y - incry - 1;
ssState.Position.y = (int)ssState.RegionDim.y - incry - 1;
incry = -incry;
} else {
ssState.DisplayedSegment.y = -1;
ssState.Position.y = -1;
}

if(ssState.DisplayedRotation == 3 || ssState.DisplayedRotation == 2) {
startx = (int)ssState.RegionDim.x + 2 - incrx;
ssState.DisplayedSegment.x = (int)ssState.RegionDim.x - incrx - 1;
ssState.Position.x = (int)ssState.RegionDim.x - incrx - 1;
incrx = -incrx;
} else {
ssState.DisplayedSegment.x = -1;
ssState.Position.x = -1;
}
if(tall) {
ssState.DisplayedSegment.z = ssState.RegionDim.z;
ssState.Position.z = ssState.RegionDim.z;
}
parms.x = startx;
parms.y = starty;
parms.z = tall ? 0 : parms.z;
ssState.Position.x = startx;
ssState.Position.y = starty;
ssState.Position.z = tall ? 0 : ssState.Position.z;

//now actually loop through and draw the subsegments
for(int k=0; k<numz; k++) {
Expand All @@ -1469,14 +1476,14 @@ void saveMegashot(bool tall)
segment->DrawAllTiles();
map_segment.unlockDraw();

parms.x += incrx;
ssState.Position.x += incrx;
}
parms.x = startx;
parms.y += incry;
ssState.Position.x = startx;
ssState.Position.y += incry;
}
parms.x=startx;
parms.y=starty;
parms.z += parms.sizez - 1;
ssState.Position.x=startx;
ssState.Position.y=starty;
ssState.Position.z += ssState.Size.z - 1;
}


Expand Down
49 changes: 17 additions & 32 deletions MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

bool connected = 0;
bool threadrunnng = 0;
segParams parms;

//==============================Map Read ==============================//
/*
Expand Down Expand Up @@ -483,7 +482,7 @@ void readBlockToSegment(DFHack::Core& DF, WorldSegment& segment,
}
}

void readMapSegment(WorldSegment* segment, int x, int y, int z, int sizex, int sizey, int sizez)
void readMapSegment(WorldSegment* segment, GameState inState)
{
uint32_t index;
DFHack::Core & DF = Core::getInstance();
Expand All @@ -501,7 +500,7 @@ void readMapSegment(WorldSegment* segment, int x, int y, int z, int sizex, int s
}

if(ssConfig.skipMaps || !Maps::IsValid()) {
segment->Reset(x,y,z + 1,sizex,sizey,sizez + 1,true);
segment->Reset(inState,true);
return;
}

Expand All @@ -522,7 +521,7 @@ void readMapSegment(WorldSegment* segment, int x, int y, int z, int sizex, int s
Gui::getCursorCoords(ssState.dfCursor.x, ssState.dfCursor.y, ssState.dfCursor.z);

//setup new world segment
segment->Reset(x,y,z,sizex,sizey,sizez,false);
segment->Reset(inState,false);

//read world wide buildings
vector<Buildings::t_building> allBuildings;
Expand Down Expand Up @@ -553,13 +552,13 @@ void readMapSegment(WorldSegment* segment, int x, int y, int z, int sizex, int s
}

if(segment->segState.DisplayedRotation % 2) {
int temp = sizex;
sizex = sizey;
sizey = temp;
int temp = inState.Size.x;
inState.Size.x = inState.Size.y;
inState.Size.y = temp;
}

//figure out what blocks to read
int32_t firstTileToReadX = x;
int32_t firstTileToReadX = inState.Position.x;
if( firstTileToReadX < 0 ) {
firstTileToReadX = 0;
}
Expand All @@ -571,22 +570,22 @@ void readMapSegment(WorldSegment* segment, int x, int y, int z, int sizex, int s
LogError("Can't get region geology.\n");
}

while(firstTileToReadX < x + sizex) {
while(firstTileToReadX < inState.Position.x + inState.Size.x) {
int blockx = firstTileToReadX / BLOCKEDGESIZE;
int32_t lastTileInBlockX = (blockx+1) * BLOCKEDGESIZE - 1;
int32_t lastTileToReadX = min<int32_t>(lastTileInBlockX, x+sizex-1);
int32_t lastTileToReadX = min<int32_t>(lastTileInBlockX, inState.Position.x + inState.Size.x-1);

int32_t firstTileToReadY = y;
int32_t firstTileToReadY = inState.Position.y;
if( firstTileToReadY < 0 ) {
firstTileToReadY = 0;
}

while(firstTileToReadY < y + sizey) {
while(firstTileToReadY < inState.Position.y + inState.Size.y) {
int blocky = firstTileToReadY / BLOCKEDGESIZE;
int32_t lastTileInBlockY = (blocky+1) * BLOCKEDGESIZE - 1;
int32_t lastTileToReadY = min<uint32_t>(lastTileInBlockY, y+sizey-1);
int32_t lastTileToReadY = min<uint32_t>(lastTileInBlockY, inState.Position.y + inState.Size.y-1);

for(int lz=z-sizez; lz <= z; lz++) {
for(int lz=inState.Position.z - inState.Size.z; lz <= inState.Position.z; lz++) {
//load the tiles from this block to the map segment
readBlockToSegment(DF, *segment, blockx, blocky, lz,
firstTileToReadX, firstTileToReadY,
Expand Down Expand Up @@ -664,15 +663,15 @@ void read_segment( void *arg)
}
}
segment = map_segment.getRead();
readMapSegment(segment, parms.x, parms.y, parms.z,parms.sizex, parms.sizey, parms.sizez);
readMapSegment(segment, ssState);
ssConfig.threadstarted = 0;
}

if(segment) {
beautifySegment(segment);

//putting these here to increase responsiveness of the UI and to make megashots work
segment->segState.DisplayedSegment = ssState.DisplayedSegment;
segment->segState.Position = ssState.Position;
segment->segState.dfCursor = ssState.dfCursor;

segment->AssembleAllTiles();
Expand All @@ -695,24 +694,17 @@ static void * threadedSegment(ALLEGRO_THREAD *read_thread, void *arg)
return 0;
}

void reloadDisplayedSegment()
void reloadPosition()
{
//create handle to dfHack API
static bool firstLoad = 1;

if (timeToReloadConfig) {
parms.thread_connect = 0;
contentLoader->Load();
timeToReloadConfig = false;
}

if (firstLoad || ssConfig.track_mode != GameConfiguration::TRACKING_NONE) {
ssState.DisplayedSegment.x = parms.x;
ssState.DisplayedSegment.y = parms.y;
ssState.DisplayedSegment.z = parms.z;
}

int segmentHeight = ssConfig.single_layer_view ? 2 : ssState.SegmentSize.z;
int segmentHeight = ssConfig.single_layer_view ? 2 : ssState.Size.z;
//load segment
if(ssConfig.threading_enable) {
if(!ssConfig.threadmade) {
Expand All @@ -721,13 +713,6 @@ void reloadDisplayedSegment()
}
}

parms.x = ssState.DisplayedSegment.x;
parms.y = ssState.DisplayedSegment.y;
parms.z = ssState.DisplayedSegment.z;
parms.sizex = ssState.SegmentSize.x;
parms.sizey = ssState.SegmentSize.y;
parms.sizez = segmentHeight;

if(ssConfig.threading_enable) {
al_start_thread(ssConfig.readThread);
} else {
Expand Down
Loading

0 comments on commit 3601170

Please sign in to comment.