Skip to content

Commit

Permalink
Merge pull request SFTtech#138 from franciscod/debug_overlay_grid
Browse files Browse the repository at this point in the history
game: add debug overlay grid, togglable with F4
  • Loading branch information
inakoll committed Nov 9, 2014
2 parents 00a29e4 + e1ca9fb commit a145fa3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
60 changes: 60 additions & 0 deletions cpp/game_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ GameMain::GameMain(Engine *engine)
:
editor_current_terrain{0},
editor_current_building{0},
debug_grid_active{false},
clicking_active{true},
ctrl_active{false},
scrolling_active{false},
Expand Down Expand Up @@ -512,6 +513,10 @@ bool GameMain::on_input(SDL_Event *e) {
engine.drawing_debug_overlay = !engine.drawing_debug_overlay;
break;

case SDLK_F4:
this->debug_grid_active = !this->debug_grid_active;
break;

case SDLK_SPACE:
this->terrain->blending_enabled = !terrain->blending_enabled;
break;
Expand Down Expand Up @@ -589,6 +594,10 @@ bool GameMain::on_draw() {
// draw terrain
terrain->draw(&engine);

if (this->debug_grid_active) {
this->draw_debug_grid();
}

return true;
}

Expand All @@ -607,6 +616,57 @@ bool GameMain::on_drawhud() {
return true;
}

void GameMain::draw_debug_grid() {
Engine &e = Engine::get();

coord::camgame camera = coord::tile{0, 0}.to_tile3().to_phys3().to_camgame();

int cam_offset_x = util::mod(camera.x, e.tile_halfsize.x * 2);
int cam_offset_y = util::mod(camera.y, e.tile_halfsize.y * 2);

int line_half_width = e.window_size.x / 2;
int line_half_height = e.window_size.y / 2;

// rounding so we get 2:1 proportion needed for the isometric perspective

if (line_half_width > line_half_height * 2) {

if (line_half_width & 1) {
line_half_width += 1; // round up if it's odd
}

line_half_height = line_half_width / 2;

} else {
line_half_width = line_half_height * 2;
}

// quantity of lines to draw to each side from the center
int k = line_half_width / (e.tile_halfsize.x);

int tilesize_x = e.tile_halfsize.x * 2;
int common_x = cam_offset_x + e.tile_halfsize.x;
int x0 = common_x - line_half_width;
int x1 = common_x + line_half_width;
int y0 = cam_offset_y - line_half_height;
int y1 = cam_offset_y + line_half_height;

glLineWidth(1);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES); {

for (int i = -k; i < k; i++) {
glVertex3f(i * tilesize_x + x0, y1, 0);
glVertex3f(i * tilesize_x + x1, y0, 0);

glVertex3f(i * tilesize_x + x0, y0 - 1, 0);
glVertex3f(i * tilesize_x + x1, y1 - 1, 0);
}

} glEnd();

}

void TestSound::play() {
if (this->sound_items.size() <= 0) {
return;
Expand Down
6 changes: 6 additions & 0 deletions cpp/game_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ class GameMain :
*/
std::unordered_set<openage::TerrainObject *> placed_buildings;

/**
* debug function that draws a simple overlay grid
*/
void draw_debug_grid();

// currently selected terrain id
openage::terrain_t editor_current_terrain;
int editor_current_building;

bool debug_grid_active;
bool clicking_active;
bool ctrl_active;
bool scrolling_active;
Expand Down

0 comments on commit a145fa3

Please sign in to comment.