Browse Source

testing some new gooey layout and update level mesh

master
cinnaboot 8 years ago
parent
commit
3e9c008866
  1. 6
      TODO.md
  2. 20
      data/level.2.dae
  3. 11
      data/test_scene.json
  4. 149
      src/gooey.cpp
  5. 4
      src/gooey.h
  6. 84
      src/hexgame.cpp

6
TODO.md

@ -17,8 +17,10 @@
- pass in frame time to camera movement functions to decouple speed from framerate
- test camera speed when moving with composite vector
- may be fixed?? need to test by examining camera position between frames and compare the distance
- show debug mesh for light positions
- attenuate point lights in shader
- debug lighting (using multiple lights doesn't add correctly atm
- move glUniform call to lights[i].position out of rgDraw, and into scene_loader init phase
- show debug mesh for light positions
- attenuate point lights in shader
- remove checks for colors, textures from render_group functions
- actually cannot remove checks for texture because some meshes aren't loaded properly
- maybe can cause loading mesh to fail when more than one mesh per file

20
data/level.2.dae

File diff suppressed because one or more lines are too long

11
data/test_scene.json

@ -1,6 +1,6 @@
{
"camera" : {
"position" : {"x":0,"y":-400,"z":100},
"position" : {"x":400,"y":-275,"z":325},
"target" : {"x":140,"y":0,"z":0},
"world_up" : {"x":0,"y":0,"z":1}
},
@ -51,17 +51,12 @@
{
"intensity" : 1.0,
"color" : {"r":0,"g":0,"b":0},
"position" : {"x":-1000,"y":0,"z":100}
"position" : {"x":-1000,"y":0,"z":200}
},
{
"intensity" : 1.0,
"color" : {"r":0,"g":0,"b":0},
"position" : {"x":-400,"y":0,"z":100}
},
{
"intensity" : 1.0,
"color" : {"r":0,"g":0,"b":0},
"position" : {"x":200,"y":0,"z":100}
"position" : {"x":200,"y":0,"z":200}
}
]
}

149
src/gooey.cpp

@ -11,9 +11,17 @@
#include "examples/imgui_impl_sdl.h"
#include "examples/imgui_impl_opengl3.h"
#include "camera.h"
#include "hexgrid.h"
#include "util.h"
#include "gooey.h"
// forward declarations
void renderRendererWindow(render_state* rs, ImGuiWindowFlags window_flags = 0);
void renderHexgridWindow(hexgrid& grid, ImGuiWindowFlags window_flags = 0);
bool
gooInit(SDL_Handles &handles, v2i vp_dims)
{
@ -48,75 +56,118 @@ gooProcessEvent(SDL_Event &event)
}
void
gooRender(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam)
gooRender(game_state* gs, render_state* rs)
{
assert(grid != nullptr);
assert(gs != nullptr && rs != nullptr);
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(handles.window);
ImGui_ImplSDL2_NewFrame(rs->handles.window);
ImGui::NewFrame();
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("Test")) {
if (ImGui::MenuItem("Test 1")) {}
ImGui::Separator();
if (ImGui::BeginMenu("Add Widget")) {
if (ImGui::MenuItem("Renderer")) {}
if (ImGui::MenuItem("Hexgrid")) {}
ImGui::EndMenu();
}
static bool br = true;
static bool bh = true;
ImGui::Checkbox("Show Renderer Widget", &br);
ImGui::Checkbox("Show Hexgrid Widget", &bh);
ImGui::EndMenu();
}
ImGui::SameLine(0, 800);
ImGui::Text("%.3f ms/frame, (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::EndMainMenuBar();
ImGuiWindowFlags window_flags = 0;
window_flags |= ImGuiWindowFlags_NoTitleBar;
window_flags |= ImGuiWindowFlags_NoScrollbar;
window_flags |= ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
ImGui::SetNextWindowPos(ImVec2(0,0));
ImGui::SetNextWindowSize(ImVec2(300, 720));
renderRendererWindow(rs, window_flags);
renderHexgridWindow(gs->grid, window_flags);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// internal
void
renderRendererWindow(render_state* rs, ImGuiWindowFlags window_flags)
{
ImGui::SetNextWindowPos(ImVec2(0, 20));
ImGui::SetNextWindowSize(ImVec2(250, 250));
ImGui::SetNextWindowBgAlpha(0.3f);
ImGui::Begin("", nullptr, window_flags);
ImGui::Begin("Renderer", nullptr, window_flags);
ImGuiIO& io = ImGui::GetIO();
ImGui::Text("%.3f ms/frame, (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::Checkbox("Debug Render", &rs->is_debug_draw);
if (ImGui::CollapsingHeader("Camera Position", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("x: %f", rs->cam.position.x);
ImGui::Text("y: %f", rs->cam.position.y);
ImGui::Text("z: %f", rs->cam.position.z);
}
if (ImGui::CollapsingHeader("Camera Forward", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("x: %f", rs->cam.forward.x);
ImGui::Text("y: %f", rs->cam.forward.y);
ImGui::Text("z: %f", rs->cam.forward.z);
}
ImGui::Spacing();
ImGui::Text("hAngle: %f", rs->cam.hAngle);
ImGui::Text("vAngle: %f", rs->cam.vAngle);
ImGui::End();
}
void
renderHexgridWindow(hexgrid& grid, ImGuiWindowFlags window_flags)
{
ImGui::SetNextWindowPos(ImVec2(250,20));
ImGui::SetNextWindowSize(ImVec2(250, 300));
ImGui::SetNextWindowBgAlpha(0.3f);
ImGui::Begin("Hexgrid", nullptr, window_flags);
ImGui::Text("Draw Mode:");
if (ImGui::RadioButton("None", (grid->draw_mode == NONE)))
grid->draw_mode = NONE;
if (ImGui::RadioButton("Fill", (grid->draw_mode == FILL)))
grid->draw_mode = FILL;
if (ImGui::RadioButton("Line", (grid->draw_mode == LINE)))
grid->draw_mode = LINE;
if (ImGui::RadioButton("Cone Fill", (grid->draw_mode == CONE_FILL)))
grid->draw_mode = CONE_FILL;
ImGui::Checkbox("Debug Render", &is_debug);
ImGui::SameLine(); ImGui::TextUnformatted(is_debug ? "true" : "false");
if (ImGui::RadioButton("None", (grid.draw_mode == NONE)))
grid.draw_mode = NONE;
if (ImGui::RadioButton("Fill", (grid.draw_mode == FILL)))
grid.draw_mode = FILL;
if (ImGui::RadioButton("Line", (grid.draw_mode == LINE)))
grid.draw_mode = LINE;
if (ImGui::RadioButton("Cone Fill", (grid.draw_mode == CONE_FILL)))
grid.draw_mode = CONE_FILL;
ImGui::Separator();
ImGui::Text("is_selecting");
ImGui::SameLine(); ImGui::TextUnformatted(grid->is_selecting ? "true" : "false");
if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent();
if (ImGui::CollapsingHeader("Camera Position", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("x: %f", cam->position.x);
ImGui::Text("y: %f", cam->position.y);
ImGui::Text("z: %f", cam->position.z);
}
ImGui::SameLine(); ImGui::TextUnformatted(grid.is_selecting ? "true" : "false");
if (ImGui::CollapsingHeader("Camera Forward", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("x: %f", cam->forward.x);
ImGui::Text("y: %f", cam->forward.y);
ImGui::Text("z: %f", cam->forward.z);
}
ImGui::Spacing();
ImGui::Text("hAngle: %f", cam->hAngle);
ImGui::Text("vAngle: %f", cam->vAngle);
ImGui::Unindent();
ImGui::Text("current_hex: ");
if (grid.current_hex) {
Hex ch = grid.current_hex->hex;
ImGui::SameLine(); ImGui::Text("%i, %i, %i", ch.q, ch.r, ch.s);
}
if (grid->current_hex) {
Hex ch = grid->current_hex->hex;
ImGui::Text("current_hex: %i, %i, %i", ch.q, ch.r, ch.s);
}
if (grid->start_hex) {
Hex sh = grid->start_hex->hex;
ImGui::Text("start_hex: %i, %i, %i", sh.q, sh.r, sh.s);
ImGui::Text("start_hex: ");
if (grid.start_hex) {
Hex sh = grid.start_hex->hex;
ImGui::SameLine(); ImGui::Text("%i, %i, %i", sh.q, sh.r, sh.s);
}
ImGui::Separator();
ImGui::Button("Add Hex");
ImGui::SameLine(); ImGui::Button("Remove Hex");
ImGui::TextWrapped("TODO: need to add more state to hexgame.cpp for adding/removing hexes, and modifying entities");
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

4
src/gooey.h

@ -1,9 +1,7 @@
#pragma once
#include "camera.h"
#include "hexgame.h"
#include "hexgrid.h"
#include "renderer.h"
bool gooInit(SDL_Handles &handles, v2i vp_dims);
@ -12,5 +10,5 @@ void gooFree();
bool gooProcessEvent(SDL_Event &event);
void gooRender(SDL_Handles &handles, hexgrid* grid, bool &is_debug, camera* cam);
void gooRender(game_state* gs, render_state* rs);

84
src/hexgame.cpp

@ -50,19 +50,19 @@ loadSceneFromJson(game_state* s, render_state* rs)
slSceneDoc* sd = slLoadFile(DATA_DIR, DEFAULT_SCENE_FILE, SCENE_SCHEMA_FILE);
if (sd != nullptr) {
game_state* g = g_game_state;
game_state* gs = g_game_state;
render_state* rs = g_render_state;
if (!slParseEntities(sd, g->entities, g->entity_count, MAX_ENTITIES, DATA_DIR)) {
if (!slParseEntities(sd, gs->entities, gs->entity_count, MAX_ENTITIES, DATA_DIR)) {
LOG(ERROR) << "Error loading Entities, exiting\n";
return false;
}
slParseCamera(sd, rs->cam);
slParseHexGrid(sd, g->grid, rs->palette_image);
hgCreateHexes(g->grid);
slParseHexGrid(sd, gs->grid, rs->palette_image);
hgCreateHexes(gs->grid);
if (!slCreateHexRenderGroups(g->grid, rs))
if (!slCreateHexRenderGroups(gs->grid, rs))
{
LOG(ERROR) << "Error creating hex render groups\n";
return false;
@ -245,7 +245,7 @@ processSDLEvents()
// TODO: need to check for both io.WantCaptureKeyboard and io.WantCaptureMouse
// to fix bug with 'ESC' not passing through while in imgui
bool gooey_wants = gooProcessEvent(e);
game_state* g = g_game_state;
game_state* gs = g_game_state;
switch (e.type)
{
@ -256,27 +256,27 @@ processSDLEvents()
switch (e.key.keysym.sym)
{
case SDLK_ESCAPE: run = false; break;
case SDLK_e: g->is_moveforward = true; break;
case SDLK_s: g->is_moveleft = true; break;
case SDLK_d: g->is_movebackward = true; break;
case SDLK_f: g->is_moveright = true; break;
case SDLK_SPACE: g->is_moveup = true; break;
case SDLK_c: g->is_movedown = true; break;
case SDLK_r: g->is_rotateCW = true; break;
case SDLK_w: g->is_rotateCCW = true; break;
case SDLK_e: gs->is_moveforward = true; break;
case SDLK_s: gs->is_moveleft = true; break;
case SDLK_d: gs->is_movebackward = true; break;
case SDLK_f: gs->is_moveright = true; break;
case SDLK_SPACE: gs->is_moveup = true; break;
case SDLK_c: gs->is_movedown = true; break;
case SDLK_r: gs->is_rotateCW = true; break;
case SDLK_w: gs->is_rotateCCW = true; break;
}
break;
case SDL_KEYUP:
switch (e.key.keysym.sym)
{
case SDLK_e: g->is_moveforward = false; break;
case SDLK_s: g->is_moveleft = false; break;
case SDLK_d: g->is_movebackward = false; break;
case SDLK_f: g->is_moveright = false; break;
case SDLK_SPACE: g->is_moveup = false; break;
case SDLK_c: g->is_movedown = false; break;
case SDLK_r: g->is_rotateCW = false; break;
case SDLK_w: g->is_rotateCCW = false; break;
case SDLK_e: gs->is_moveforward = false; break;
case SDLK_s: gs->is_moveleft = false; break;
case SDLK_d: gs->is_movebackward = false; break;
case SDLK_f: gs->is_moveright = false; break;
case SDLK_SPACE: gs->is_moveup = false; break;
case SDLK_c: gs->is_movedown = false; break;
case SDLK_r: gs->is_rotateCW = false; break;
case SDLK_w: gs->is_rotateCCW = false; break;
}
break;
case SDL_MOUSEBUTTONDOWN:
@ -284,12 +284,12 @@ processSDLEvents()
{
if (e.button.button == SDL_BUTTON_LEFT)
{
g->grid.is_selecting = true;
gs->grid.is_selecting = true;
handleMouseDown(e.button);
}
else if (e.button.button == SDL_BUTTON_RIGHT)
{
g->is_camera_rotate = true;
gs->is_camera_rotate = true;
}
}
break;
@ -297,15 +297,15 @@ processSDLEvents()
if (!gooey_wants)
{
if (e.button.button == SDL_BUTTON_LEFT)
g->grid.is_selecting = false;
gs->grid.is_selecting = false;
else if (e.button.button == SDL_BUTTON_RIGHT)
g->is_camera_rotate = false;
gs->is_camera_rotate = false;
}
break;
case SDL_MOUSEMOTION:
if (!gooey_wants && g->grid.is_selecting)
if (!gooey_wants && gs->grid.is_selecting)
handleMouseMove(e.motion);
else if(!gooey_wants && g->is_camera_rotate)
else if(!gooey_wants && gs->is_camera_rotate)
cameraRotate(g_render_state->cam, e.motion.xrel, e.motion.yrel);
break;
default:
@ -328,17 +328,17 @@ cleanUp(SDL_Handles &handles)
SDL_DestroyWindow(handles.window);
SDL_Quit();
game_state* g = g_game_state;
game_state* gs = g_game_state;
if (g_game_state->grid.hex_array)
delete g_game_state->grid.hex_array;
for (uint i = 0; i < g->entity_count; i++) {
meFreeMeshGroup(g->entities[i].mesh_group);
rgFree(g->entities[i].ren_group);
for (uint i = 0; i < gs->entity_count; i++) {
meFreeMeshGroup(gs->entities[i].mesh_group);
rgFree(gs->entities[i].ren_group);
}
utilSafeFree(g->entities);
utilSafeFree(gs->entities);
utilSafeFree(g_render_state);
utilSafeFree(g_game_state);
@ -373,20 +373,20 @@ int main(int argc, char* argv[])
while (processSDLEvents()) {
frameStart = SDL_GetTicks();
game_state* g = g_game_state;
render_state* r = g_render_state;
game_state* gs = g_game_state;
render_state* rs = g_render_state;
cameraMove(r->cam, g->is_moveup, g->is_moveleft, g->is_movedown, g->is_moveright,
g->is_moveforward, g->is_movebackward);
cameraMove(rs->cam, gs->is_moveup, gs->is_moveleft, gs->is_movedown, gs->is_moveright,
gs->is_moveforward, gs->is_movebackward);
renRenderFrame(r, g->grid, g->entities, g->entity_count);
renRenderFrame(rs, gs->grid, gs->entities, gs->entity_count);
if (r->is_debug_draw && g->grid.draw_mode == CONE_FILL)
renRenderDebug(r, g_polygon_select_vertices);
if (rs->is_debug_draw && gs->grid.draw_mode == CONE_FILL)
renRenderDebug(rs, g_polygon_select_vertices);
gooRender(r->handles, &g->grid, r->is_debug_draw, &r->cam);
gooRender(gs, rs);
SDL_GL_SwapWindow(r->handles.window);
SDL_GL_SwapWindow(rs->handles.window);
// TODO: test SDL_Delay on Win32
//platform_wait_for_vblank(VSYNC_ENABLED);

Loading…
Cancel
Save