Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor out Crd3D and Crd2D to use df::coord and df::coord2d #207

Closed
2 changes: 1 addition & 1 deletion Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ bool loadConfigFile()
// apply configuration settings to app state
stonesenseState.ssState.ScreenH = newConfig.defaultScreenHeight;
stonesenseState.ssState.ScreenW = newConfig.defaultScreenWidth;
stonesenseState.ssState.Size = newConfig.defaultSegmentSize + Crd3D{ 2, 2, 0 };
stonesenseState.ssState.Size = newConfig.defaultSegmentSize + df::coord{ 2, 2, 0 };
stonesenseState.lift_segment_offscreen_x = 0;
stonesenseState.lift_segment_offscreen_y = newConfig.lift_segment;

Expand Down
8 changes: 2 additions & 6 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ class Config {
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
};
df::coord defaultSegmentSize{ DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE_Z };
bool show_all_creatures = false;
int automatic_reload_time = 50;
int automatic_reload_step = 50;
Expand All @@ -53,7 +49,7 @@ class Config {
ALLEGRO_COLOR fogcol = al_map_rgba(128, 158, 177, 30);
bool fogenable = true;
ALLEGRO_COLOR backcol = al_map_rgb(128, 158, 177);
Crd3D viewOffset{ 0,0,0 };
df::coord viewOffset{ 0,0,0 };
int bitmapHolds = 4096;
bool saveImageCache = false;
int fontsize = 10;
Expand Down
2 changes: 1 addition & 1 deletion Creatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)
for(uint32_t index=0; index<world->units.active.size(); index++) {
unit_ptr = world->units.active[index];

if(!segment->CoordinateInsideSegment(unit_ptr->pos.x,unit_ptr->pos.y,unit_ptr->pos.z)
if (!segment->CoordinateInsideSegment(df::coord(unit_ptr->pos.x, unit_ptr->pos.y, unit_ptr->pos.z))
|| (!IsCreatureVisible(unit_ptr) && !ssConfig.config.show_all_creatures)){
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion DumpInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void dumpSegment()
al_lock_mutex(ssConfig.readMutex);

//back up all the relevant values
Crd3D tempSize = ssState.Size;
df::coord tempSize = ssState.Size;
int tempViewx = Position.x;
int tempViewy = Position.y;
bool tempFollow = ssConfig.follow_DFscreen;
Expand Down
70 changes: 35 additions & 35 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ImageFileList

namespace
{
void ScreenToPoint(int inx, int iny, int& x1, int& y1, int& z1, int segSizeX, int segSizeY, int segSizeZ, int ScreenW, int ScreenH)
void ScreenToPoint(int inx, int iny, df::coord& coord, int segSizeX, int segSizeY, int segSizeZ, int ScreenW, int ScreenH)
{
auto& ssConfig = stonesenseState.ssConfig;

Expand All @@ -176,8 +176,8 @@ namespace
y = y / ssConfig.scale;
y += TILETOPHEIGHT * 5.0 / 4.0;
y += stonesenseState.lift_segment_offscreen_y;
z1 = segSizeZ - 2;
y += z1 * TILEHEIGHT;
coord.z = segSizeZ - 2;
y += coord.z * TILEHEIGHT;
y = 2 * y / TILETOPHEIGHT;
y += (segSizeX / 2) + (segSizeY / 2);

Expand All @@ -186,19 +186,19 @@ namespace
x = 2 * x / TILEWIDTH;
x += (segSizeX / 2) - (segSizeY / 2);

x1 = (x + y) / 2;
y1 = (y - x) / 2;
coord.x = (x + y) / 2;
coord.y = (y - x) / 2;

}
}

void ScreenToPoint(int x,int y,int &x1, int &y1, int &z1)
void ScreenToPoint(int x,int y,df::coord& coord)
{
auto& ssState = stonesenseState.ssState;
if(stonesenseState.ssConfig.track_screen_center){
ScreenToPoint(x, y, x1, y1, z1, ssState.Size.x, ssState.Size.y, ssState.Size.z, ssState.ScreenW, ssState.ScreenH);
ScreenToPoint(x, y, coord, ssState.Size.x, ssState.Size.y, ssState.Size.z, ssState.ScreenW, ssState.ScreenH);
} else {
ScreenToPoint(x, y, x1, y1, z1, 0, 0, ssState.Size.z, 0, 0);
ScreenToPoint(x, y, coord, 0, 0, ssState.Size.z, 0, 0);
}
}

Expand Down Expand Up @@ -391,21 +391,21 @@ void draw_loading_message(const char *format, ...)
al_flip_display();
}

void correctTileForDisplayedOffset(int32_t& x, int32_t& y, int32_t& z)
void correctTileForDisplayedOffset(df::coord& coord)
{
auto& ssState = stonesenseState.ssState;

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
coord.x -= ssState.Position.x;
coord.y -= ssState.Position.y; //Position.y;
coord.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).
*/
void correctForRotation(int32_t& x, int32_t& y, unsigned char rot, int32_t szx, int32_t szy){
int32_t oldx = x;
int32_t oldy = y;
void correctForRotation(int16_t& x, int16_t& y, unsigned char rot, int16_t szx, int16_t szy){
auto oldx = x;
auto oldy = y;

if(rot == 1) {
x = szy - oldy -1;
Expand All @@ -421,16 +421,16 @@ void correctForRotation(int32_t& x, int32_t& y, unsigned char rot, int32_t szx,
}
}

Crd2D WorldTileToScreen(int32_t x, int32_t y, int32_t z)
df::coord2d WorldTileToScreen(df::coord in)
{
correctTileForDisplayedOffset( x, y, z);
return LocalTileToScreen(x, y, z-1);
correctTileForDisplayedOffset(in);
return LocalTileToScreen(in.x, in.y, in.z-1);
}

Crd2D LocalTileToScreen(int32_t x, int32_t y, int32_t z)
df::coord2d LocalTileToScreen(int16_t x, int16_t y, int16_t z)
{
pointToScreen((int*)&x, (int*)&y, z);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is casting a int16_t* to int*.

Crd2D result;
df::coord2d result;
result.x = x;
result.y = y;
return result;
Expand All @@ -454,10 +454,10 @@ void DrawCurrentLevelOutline(bool backPart)
sizey -= 2;
}

Crd2D p1 = WorldTileToScreen(x, y, z);
Crd2D p2 = WorldTileToScreen(x, y + sizey , z);
Crd2D p3 = WorldTileToScreen(x + sizex , y, z);
Crd2D p4 = WorldTileToScreen(x + sizex , y + sizey , z);
df::coord2d p1 = WorldTileToScreen(df::coord(x, y, z));
df::coord2d p2 = WorldTileToScreen(df::coord(x, y + sizey, z));
df::coord2d p3 = WorldTileToScreen(df::coord(x + sizex, y, z));
df::coord2d p4 = WorldTileToScreen(df::coord(x + sizex, y + sizey, z));
p1.y += FLOORHEIGHT*ssConfig.scale;
p2.y += FLOORHEIGHT*ssConfig.scale;
p3.y += FLOORHEIGHT*ssConfig.scale;
Expand All @@ -484,13 +484,13 @@ void DrawCurrentLevelOutline(bool backPart)

namespace
{
void drawCursorAt(WorldSegment* segment, Crd3D& cursor, const ALLEGRO_COLOR& color)
void drawCursorAt(WorldSegment* segment, df::coord& cursor, const ALLEGRO_COLOR& color)
{
auto& ssConfig = stonesenseState.ssConfig;
segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z);
segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z);
segment->CorrectTileForSegmentOffset(cursor);
segment->CorrectTileForSegmentRotation(cursor.x,cursor.y);

Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z);
df::coord2d point = LocalTileToScreen(cursor.x, cursor.y, cursor.z);
int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE;
int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE;
al_draw_tinted_scaled_bitmap(
Expand All @@ -510,7 +510,7 @@ namespace
void drawSelectionCursor(WorldSegment* segment)
{
auto& ssConfig = stonesenseState.ssConfig;
Crd3D& selection = segment->segState.dfSelection;
df::coord selection = segment->segState.dfSelection;
if ((selection.x != -30000 && ssConfig.config.follow_DFcursor)) {
drawCursorAt(segment, selection, uiColor(3));
}
Expand All @@ -521,7 +521,7 @@ namespace

void drawDebugCursor(WorldSegment* segment)
{
Crd3D& cursor = segment->segState.dfCursor;
df::coord cursor = segment->segState.dfCursor;
drawCursorAt(segment, cursor, uiColor(2));
}

Expand Down Expand Up @@ -907,7 +907,7 @@ void paintboard()
int line = 1;
al_hold_bitmap_drawing(true);

for(int32_t i=1; true; i++){
for(int16_t i=1; true; i++){
if(getKeyStrings(i, keyname, actionname)){
draw_textf_border(font, uiColor(1), 10, line*fontHeight, 0, "%s: %s%s", keyname->c_str(), actionname->c_str(), isRepeatable(i) ? " (repeats)" : "");
line++;
Expand Down Expand Up @@ -1180,8 +1180,8 @@ void saveMegashot(bool tall)
auto& ssConfig = stonesenseState.ssConfig;
GameConfiguration tempConfig = ssConfig;
GameState tempState = ssState;
uint32_t templiftX = stonesenseState.lift_segment_offscreen_x;
uint32_t templiftY = stonesenseState.lift_segment_offscreen_y;
uint16_t templiftX = stonesenseState.lift_segment_offscreen_x;
uint16_t templiftY = stonesenseState.lift_segment_offscreen_y;
int tempflags = al_get_new_bitmap_flags();

//now make them real big.
Expand Down Expand Up @@ -1282,7 +1282,7 @@ void saveMegashot(bool tall)
ssState.Position.z = tall ? 0 : ssState.Position.z;

//set up the pixel-shifts
int32_t movexx, moveyx, movexy, moveyy;
int16_t movexx, moveyx, movexy, moveyy;
if(ssState.Rotation == 1 || ssState.Rotation == 3) {
movexx = -sizey;
moveyx = sizey;
Expand All @@ -1298,7 +1298,7 @@ void saveMegashot(bool tall)
}

//now actually loop through and draw the subsegments
int32_t startstartlifty = startlifty;
int16_t startstartlifty = startlifty;
for(int k=0; k<numz; k++) {
startlifty = startstartlifty - TILEHEIGHT*(numz-k-1)*(ssState.Size.z - 1);
for(int i=0; i<numy; i++) {
Expand Down
8 changes: 4 additions & 4 deletions GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "common.h"
#include <filesystem>

void ScreenToPoint(int x,int y,int &x1, int &y1, int &z1);
void ScreenToPoint(int x,int y, df::coord& coord);
void pointToScreen(int *inx, int *iny, int inz);
void correctForRotation(int32_t& x, int32_t& y, unsigned char rot, int32_t szx, int32_t szy);
Crd2D WorldTileToScreen(int32_t x, int32_t y, int32_t z);
Crd2D LocalTileToScreen(int32_t x, int32_t y, int32_t z);
void correctForRotation(int16_t& x, int16_t& y, unsigned char rot, int16_t szx, int16_t szy);
df::coord2d WorldTileToScreen(df::coord in);
df::coord2d LocalTileToScreen(int16_t x, int16_t y, int16_t z);
void DrawCurrentLevelOutline(bool backPart);
void DrawMinimap(WorldSegment *);
void paintboard();
Expand Down
2 changes: 1 addition & 1 deletion GameConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct GameConfiguration {
uint8_t truncate_walls;
bool track_screen_center = true;

uint32_t menustate;
uint16_t menustate;
//DFHack::t_viewscreen viewscreen;

bool spriteIndexOverlay;
Expand Down
10 changes: 5 additions & 5 deletions GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

struct GameState{
//properties of the currently viewed portion of the segment
Crd3D Position;
df::coord Position;
int Rotation;

//the size of the next segment to load, and the map region
Crd3D Size;
Crd3D RegionDim;
df::coord Size;
df::coord RegionDim;

//position of the cursor
Crd3D dfCursor;
df::coord dfCursor;
//position of the selection cursor
Crd3D dfSelection;
df::coord dfSelection;

//the width and height of the stonesense window
int ScreenW;
Expand Down
Loading