Skip to content

Commit

Permalink
Reshuffle GameConfiguration
Browse files Browse the repository at this point in the history
Phase 1:

Ensure that every setting in the configuration file corresponds to a variable in `GameConfiguration`, and segregate the variables in `GameConfiguration` that are set from the configuration file from the other stuff in the structure
  • Loading branch information
ab9rf committed Jan 20, 2025
1 parent d310a45 commit 8c8b97f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 74 deletions.
23 changes: 16 additions & 7 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ namespace {

if (line.find("[WIDTH") != string::npos) {
int width = parseIntFromLine("WIDTH", line);
ssState.ScreenW = width;
ssConfig.defaultScreenWidth = width;
}
if (line.find("[HEIGHT") != string::npos) {
int height = parseIntFromLine("HEIGHT", line);
ssState.ScreenH = height;
ssConfig.defaultScreenHeight = height;
}
if (line.find("[WINDOWED") != string::npos) {
string result = parseStrFromLine("WINDOWED", line);
Expand All @@ -91,17 +91,16 @@ namespace {
value = 100;
}
//plus 2 to allow edge readings
ssState.Size.x = value + 2;
ssState.Size.y = value + 2;
ssConfig.defaultSegmentSize.x = value;
ssConfig.defaultSegmentSize.y = value;
}
if (line.find("[SEGMENTSIZE_Z") != string::npos) {
int value = parseIntFromLine("SEGMENTSIZE_Z", line);
if (value < 1) {
value = DEFAULT_SIZE_Z;
}
ssState.Size.z = value;
ssConfig.defaultSegmentSize.z = value;
}

if (line.find("[ALLCREATURES") != string::npos) {
string result = parseStrFromLine("ALLCREATURES", line);
ssConfig.show_all_creatures = (result == "YES");
Expand Down Expand Up @@ -130,7 +129,7 @@ namespace {
}
if (line.find("[LIFTSEGMENT") != string::npos) {
int value = parseIntFromLine("LIFTSEGMENT", line);
ssConfig.lift_segment_offscreen_y = value;
ssConfig.lift_segment = value;
}
if (line.find("[ANIMATION_RATE") != string::npos) {
int value = parseIntFromLine("ANIMATION_RATE", line);
Expand Down Expand Up @@ -829,6 +828,16 @@ bool loadConfigFile()
getline (myfile,line);
parseConfigLine( line );
}

// apply configuration settings to initial app state
stonesenseState.ssState.ScreenH = stonesenseState.ssConfig.defaultScreenHeight;
stonesenseState.ssState.ScreenW = stonesenseState.ssConfig.defaultScreenWidth;
stonesenseState.ssState.Size.x = stonesenseState.ssConfig.defaultSegmentSize.x + 2;
stonesenseState.ssState.Size.y = stonesenseState.ssConfig.defaultSegmentSize.y + 2;
stonesenseState.ssState.Size.z = stonesenseState.ssConfig.defaultSegmentSize.z;
stonesenseState.lift_segment_offscreen_x = 0;
stonesenseState.lift_segment_offscreen_y = stonesenseState.ssConfig.lift_segment;

// update allegro colors loaded from file
stonesenseState.ssConfig.colors.update();
//close file, etc.
Expand Down
20 changes: 10 additions & 10 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ namespace

y = y / ssConfig.scale;
y += TILETOPHEIGHT * 5.0 / 4.0;
y += ssConfig.lift_segment_offscreen_y;
y += stonesenseState.lift_segment_offscreen_y;
z1 = segSizeZ - 2;
y += z1 * TILEHEIGHT;
y = 2 * y / TILETOPHEIGHT;
y += (segSizeX / 2) + (segSizeY / 2);

x = x / ssConfig.scale;
x -= ssConfig.lift_segment_offscreen_x;
x -= stonesenseState.lift_segment_offscreen_x;
x = 2 * x / TILEWIDTH;
x += (segSizeX / 2) - (segSizeY / 2);

Expand Down Expand Up @@ -214,15 +214,15 @@ namespace
int x = *inx - *iny;
x -= (segSizeX / 2) - (segSizeY / 2);
x = x * TILEWIDTH / 2;
x += ssConfig.lift_segment_offscreen_x;
x += stonesenseState.lift_segment_offscreen_x;
x *= ssConfig.scale;

int y = *inx + *iny;
y -= (segSizeX / 2) + (segSizeY / 2);
y = y * TILETOPHEIGHT / 2;
y -= z * TILEHEIGHT;
y -= TILETOPHEIGHT * 5 / 4;
y -= ssConfig.lift_segment_offscreen_y;
y -= stonesenseState.lift_segment_offscreen_y;
y *= ssConfig.scale;

x += ScreenW / 2;
Expand Down Expand Up @@ -1226,8 +1226,8 @@ void saveMegashot(bool tall)
{
startliftx = (TILEWIDTH/2)*ssState.RegionDim.x;
}
ssConfig.lift_segment_offscreen_y = startlifty;
ssConfig.lift_segment_offscreen_x = startliftx;
stonesenseState.lift_segment_offscreen_y = startlifty;
stonesenseState.lift_segment_offscreen_x = startliftx;

//here we deal with the rotations
int startx, incrx, numx;
Expand Down Expand Up @@ -1301,8 +1301,8 @@ void saveMegashot(bool tall)
for(int k=0; k<numz; k++) {
startlifty = startstartlifty - TILEHEIGHT*(numz-k-1)*(ssState.Size.z - 1);
for(int i=0; i<numy; i++) {
ssConfig.lift_segment_offscreen_x = startliftx - (TILEWIDTH/2)*i*movexy;
ssConfig.lift_segment_offscreen_y = startlifty - (TILETOPHEIGHT/2)*i*moveyy;
stonesenseState.lift_segment_offscreen_x = startliftx - (TILEWIDTH/2)*i*movexy;
stonesenseState.lift_segment_offscreen_y = startlifty - (TILETOPHEIGHT/2)*i*moveyy;
for(int j=0; j<numx; j++) {
//read and draw each individual segment
read_segment(NULL);
Expand All @@ -1312,8 +1312,8 @@ void saveMegashot(bool tall)
stonesenseState.map_segment.unlockDraw();

ssState.Position.x += incrx;
ssConfig.lift_segment_offscreen_x += (TILEWIDTH/2)*movexx;
ssConfig.lift_segment_offscreen_y -= (TILETOPHEIGHT/2)*moveyx;
stonesenseState.lift_segment_offscreen_x += (TILEWIDTH/2)*movexx;
stonesenseState.lift_segment_offscreen_y -= (TILETOPHEIGHT/2)*moveyx;
}
ssState.Position.x = startx;
ssState.Position.y += incry;
Expand Down
110 changes: 55 additions & 55 deletions GameConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,77 @@
#include "allegro5/color.h"

struct GameConfiguration {
bool overlay_mode;
bool show_zones;
bool show_stockpiles;
bool show_designations = true;
bool show_osd = false;
bool show_announcements = false;
bool show_keybinds = false;
bool closeOnEsc = true;
bool single_layer_view;
bool shade_hidden_tiles = false;
bool show_hidden_tiles;
bool show_creature_names = false;
bool names_use_nick;
bool names_use_species;
bool show_all_creatures;
bool load_ground_materials = false;
bool hide_outer_tiles = false;
bool debug_mode = false;
int lift_segment_offscreen_x = 0;
int lift_segment_offscreen_y = 0;
uint8_t truncate_walls;
bool verbose_logging;
int viewXoffset;
int viewYoffset;
int viewZoffset;
bool track_screen_center = true;
int automatic_reload_time = 0;
int automatic_reload_step = 500;
int animation_step = 300;
int fontsize = 10;
std::filesystem::path font =
std::filesystem::path{ } / "data" / "art" / "font.ttf";
bool Fullscreen = DEFAULT_FULLSCREEN_MODE;
bool show_intro = true;
ALLEGRO_COLOR fogcol = al_map_rgba(255, 255, 255, 255);
ALLEGRO_COLOR backcol = al_map_rgb(95, 95, 160);
bool fogenable = true;

bool follow_DFcursor;

enum trackingmode : uint8_t {
TRACKING_NONE,
TRACKING_CENTER,
TRACKING_FOCUS,

TRACKING_INVALID
};
trackingmode track_mode = TRACKING_CENTER;

bool closeOnEsc = true;
int defaultScreenWidth{ DEFAULT_RESOLUTION_WIDTH };
int defaultScreenHeight{ DEFAULT_RESOLUTION_HEIGHT };
bool Fullscreen{ DEFAULT_FULLSCREEN_MODE };
Crd3D defaultSegmentSize{
.x = DEFAULT_SIZE,
.y = DEFAULT_SIZE,
.z = DEFAULT_SIZE_Z
};
bool show_all_creatures;
int automatic_reload_time = 0;
int automatic_reload_step = 500;
bool debug_mode = false;
bool transparentScreenshots;
int lift_segment = 0;
int animation_step = 300;
bool verbose_logging;
trackingmode track_mode = TRACKING_CENTER;
bool invert_mouse_z;

bool follow_DFcursor;
bool show_creature_names = false;
bool show_creature_moods;
bool show_creature_jobs;
uint8_t show_creature_professions;
bool names_use_nick;
bool names_use_species;
bool show_osd = false;
bool cache_images;
bool show_stockpiles;
bool show_zones;
bool show_intro = true;
ALLEGRO_COLOR fogcol = al_map_rgba(255, 255, 255, 255);
bool fogenable = true;
ALLEGRO_COLOR backcol = al_map_rgb(95, 95, 160);
int viewXoffset;
int viewYoffset;
int viewZoffset;
int bitmapHolds = 4096;

bool saveImageCache;
bool cache_images;
int imageCacheSize = 4096;
int fontsize = 10;
std::filesystem::path font =
std::filesystem::path{ } / "data" / "art" / "font.ttf";
bool useDfColors = false;
dfColors colors;
bool opengl;
bool directX;
bool software;
bool dayNightCycle;
int imageCacheSize = 4096;
bool fog_of_war = true;

// below items are not configurable via the config file
bool overlay_mode;
bool show_designations = true;
bool show_announcements = false;
bool show_keybinds = false;
bool single_layer_view;
bool shade_hidden_tiles = false;
bool show_hidden_tiles;
bool load_ground_materials = false;
bool hide_outer_tiles = false;
uint8_t truncate_walls;
bool track_screen_center = true;

uint32_t menustate;
//DFHack::t_viewscreen viewscreen;
Expand All @@ -77,16 +87,6 @@ struct GameConfiguration {
bool creditScreen = true;
int currentSpriteOverlay;

bool dayNightCycle;

bool show_creature_moods;
bool show_creature_jobs;
uint8_t show_creature_professions;

bool transparentScreenshots;

bool fog_of_war = true;

bool occlusion = true;
bool tile_count;

Expand Down
3 changes: 3 additions & 0 deletions StonesenseState.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class StonesenseState
unsigned int mouse_b;

SegmentWrap map_segment;

int lift_segment_offscreen_x;
int lift_segment_offscreen_y;
};

extern StonesenseState stonesenseState;
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ static void* stonesense_thread(ALLEGRO_THREAD* main_thread, void* parms)
out.print("Stonesense launched\n");

stonesenseState.ssConfig = GameConfiguration{};
stonesenseState.ssState.ScreenH = DEFAULT_RESOLUTION_HEIGHT;
stonesenseState.ssState.ScreenW = DEFAULT_RESOLUTION_WIDTH;
stonesenseState.ssState.ScreenH = stonesenseState.ssConfig.defaultScreenHeight;
stonesenseState.ssState.ScreenW = stonesenseState.ssConfig.defaultScreenWidth;
stonesenseState.ssState.Size = { DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE_Z };
stonesenseState.timeToReloadConfig = true;
stonesenseState.contentLoader = std::make_unique<ContentLoader>();
Expand Down

0 comments on commit 8c8b97f

Please sign in to comment.