Browse Source

add prefixes to interface function names in renderer and gooey

master
cinnaboot 8 years ago
parent
commit
04757ec527
  1. 8
      src/gooey.cpp
  2. 11
      src/gooey.h
  3. 19
      src/hexgame.cpp
  4. 12
      src/renderer.cpp
  5. 17
      src/renderer.h

8
src/gooey.cpp

@ -15,7 +15,7 @@
#include "gooey.h" #include "gooey.h"
bool bool
initGooey(SDL_Handles &handles, v2i vp_dims) gooInit(SDL_Handles &handles, v2i vp_dims)
{ {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
@ -33,7 +33,7 @@ initGooey(SDL_Handles &handles, v2i vp_dims)
} }
void void
shutdownGooey() gooFree()
{ {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
@ -41,14 +41,14 @@ shutdownGooey()
} }
bool bool
gooeyProcessEvent(SDL_Event &event) gooProcessEvent(SDL_Event &event)
{ {
ImGui_ImplSDL2_ProcessEvent(&event); ImGui_ImplSDL2_ProcessEvent(&event);
return ImGui::GetIO().WantCaptureMouse; return ImGui::GetIO().WantCaptureMouse;
} }
void void
renderGooey(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam) gooRender(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam)
{ {
assert(grid != nullptr); assert(grid != nullptr);

11
src/gooey.h

@ -6,8 +6,11 @@
#include "hexgrid.h" #include "hexgrid.h"
#include "renderer.h" #include "renderer.h"
bool initGooey(SDL_Handles &handles, v2i vp_dims); bool gooInit(SDL_Handles &handles, v2i vp_dims);
void shutdownGooey();
bool gooeyProcessEvent(SDL_Event &event); void gooFree();
void renderGooey(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam);
bool gooProcessEvent(SDL_Event &event);
void gooRender(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam);

19
src/hexgame.cpp

@ -1,7 +1,6 @@
/******************************************************************************* /*******************************************************************************
* TODO: * TODO:
* - renderer * - renderer
* - add prefix to interface function names for eg) gooey.h, renderer.h
* - clean up main(), split out initialization and scene loading to new functions * - clean up main(), split out initialization and scene loading to new functions
* - check over renderer, camera, gooey init after changes * - check over renderer, camera, gooey init after changes
* - pass in frame time to camera movement functions to decouple speed from framerate * - pass in frame time to camera movement functions to decouple speed from framerate
@ -191,7 +190,7 @@ processSDLEvents()
// let gooey have event // let gooey have event
// TODO: need to check for both io.WantCaptureKeyboard and io.WantCaptureMouse // TODO: need to check for both io.WantCaptureKeyboard and io.WantCaptureMouse
// to fix bug with 'ESC' not passing through while in imgui // to fix bug with 'ESC' not passing through while in imgui
bool gooey_wants = gooeyProcessEvent(e); bool gooey_wants = gooProcessEvent(e);
game_state* g = g_game_state; game_state* g = g_game_state;
switch (e.type) switch (e.type)
@ -269,7 +268,7 @@ cleanUp(SDL_Handles &handles)
#if 0 #if 0
shutdownGooey(); shutdownGooey();
#endif #endif
freeBuffers(g_render_state); // renderer.h renFreeBuffers(g_render_state); // renderer.h
for (SDL_Surface *surface : handles.texSurfaces) for (SDL_Surface *surface : handles.texSurfaces)
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
meShutdownAssimp(); // mesh.h meShutdownAssimp(); // mesh.h
@ -324,12 +323,12 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
if (!initRenderer(g_render_state)) { if (!renInit(g_render_state)) {
LOG(ERROR) << "Unable to initialize graphics, exiting\n"; LOG(ERROR) << "Unable to initialize graphics, exiting\n";
return 1; return 1;
} }
if (!initGooey(g_render_state->handles, g_render_state->viewport_dims)) { if (!gooInit(g_render_state->handles, g_render_state->viewport_dims)) {
LOG(ERROR) << "Fooey, No Gooey!\n"; LOG(ERROR) << "Fooey, No Gooey!\n";
return 1; return 1;
} }
@ -347,7 +346,7 @@ int main(int argc, char* argv[])
// pre-load textures // pre-load textures
const char * path = "../data/coords.layout.flat.png"; const char * path = "../data/coords.layout.flat.png";
if (!addTexture(g_render_state->handles, path)) if (!renAddTexture(g_render_state->handles, path))
{ {
LOG(ERROR) << "Error adding " << path << "\n"; LOG(ERROR) << "Error adding " << path << "\n";
return 1; return 1;
@ -394,7 +393,7 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
if (!createScene(g_render_state, g_game_state->entities, g_game_state->entity_count)) if (!renCreateScene(g_render_state, g_game_state->entities, g_game_state->entity_count))
{ {
LOG(ERROR) << "Error in vertex data, exiting\n"; LOG(ERROR) << "Error in vertex data, exiting\n";
return 1; return 1;
@ -424,12 +423,12 @@ int main(int argc, char* argv[])
cameraMove(r->cam, g->is_moveup, g->is_moveleft, g->is_movedown, g->is_moveright, cameraMove(r->cam, g->is_moveup, g->is_moveleft, g->is_movedown, g->is_moveright,
g->is_moveforward, g->is_movebackward); g->is_moveforward, g->is_movebackward);
renderFrame(r, g->grid.hex_array, g->entities, g->entity_count); renRenderFrame(r, g->grid.hex_array, g->entities, g->entity_count);
if (r->is_debug_draw && g->grid.draw_mode == CONE_FILL) if (r->is_debug_draw && g->grid.draw_mode == CONE_FILL)
renderDebug(r, g_polygon_select_vertices); renRenderDebug(r, g_polygon_select_vertices);
renderGooey(r->handles, &g->grid, r->is_debug_draw, &r->cam); gooRender(r->handles, &g->grid, r->is_debug_draw, &r->cam);
SDL_GL_SwapWindow(r->handles.window); SDL_GL_SwapWindow(r->handles.window);

12
src/renderer.cpp

@ -42,7 +42,7 @@ void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
// interface // interface
bool bool
initRenderer(render_state* rs) renInit(render_state* rs)
{ {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
@ -119,7 +119,7 @@ initRenderer(render_state* rs)
} }
void void
freeBuffers(render_state* rs) renFreeBuffers(render_state* rs)
{ {
utilSafeFree(rs->lights); utilSafeFree(rs->lights);
rgFree(rs->filled_hex_render_group); rgFree(rs->filled_hex_render_group);
@ -128,7 +128,7 @@ freeBuffers(render_state* rs)
} }
bool bool
addTexture(SDL_Handles &handles, const char * path) renAddTexture(SDL_Handles &handles, const char * path)
{ {
// testing // testing
LOG(INFO) << "Loading image: " << path << "\n"; LOG(INFO) << "Loading image: " << path << "\n";
@ -156,7 +156,7 @@ addTexture(SDL_Handles &handles, const char * path)
} }
bool bool
createScene(render_state* rs, Entity* entities, uint32 entity_count) renCreateScene(render_state* rs, Entity* entities, uint32 entity_count)
{ {
// entities // entities
@ -195,7 +195,7 @@ createScene(render_state* rs, Entity* entities, uint32 entity_count)
} }
void void
renderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count) renRenderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, uint32 entity_count)
{ {
glClearColor(g_clear_col.R, g_clear_col.G, g_clear_col.B, g_clear_col.A); glClearColor(g_clear_col.R, g_clear_col.G, g_clear_col.B, g_clear_col.A);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@ -226,7 +226,7 @@ renderFrame(render_state* rs, std::vector<hex_info> *hexes, Entity* entities, ui
} }
void void
renderDebug(render_state* rs, std::vector<Point> &vertices) renRenderDebug(render_state* rs, std::vector<Point> &vertices)
{ {
GLfloat* buf = rs->debug_render_group->render_objects[0]->vertex_buffer.buffer; GLfloat* buf = rs->debug_render_group->render_objects[0]->vertex_buffer.buffer;
buf[0] = vertices[0].x; buf[1] = vertices[0].y; buf[2] = 0; buf[0] = vertices[0].x; buf[1] = vertices[0].y; buf[2] = 0;

17
src/renderer.h

@ -44,10 +44,15 @@ struct render_state
uint max_lights = 0; uint max_lights = 0;
}; };
bool initRenderer(render_state* rs); bool renInit(render_state* rs);
void freeBuffers(render_state* rs);
bool addTexture(SDL_Handles &handles, const char * path); void renFreeBuffers(render_state* rs);
bool createScene(render_state* rs, Entity* entities, uint32 entity_count);
void renderFrame(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count); bool renAddTexture(SDL_Handles &handles, const char * path);
void renderDebug(render_state* rs, std::vector<Point> &vertices);
bool renCreateScene(render_state* rs, Entity* entities, uint32 entity_count);
void renRenderFrame(render_state* rs, std::vector<hex_info>* hexes, Entity* entities, uint32 entity_count);
void renRenderDebug(render_state* rs, std::vector<Point> &vertices);

Loading…
Cancel
Save