diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-16 16:04:32 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-16 16:04:32 -0500 |
| commit | ed08b673c50b076042d8f0c49501372168142764 (patch) | |
| tree | 18ecda99942ef11ce4023c3ad4437976f96b75da /src/game.cpp | |
| parent | 224645d1071c14b4829dbb3ae35870868fcff85a (diff) | |
| download | therapy-ed08b673c50b076042d8f0c49501372168142764.tar.gz therapy-ed08b673c50b076042d8f0c49501372168142764.tar.bz2 therapy-ed08b673c50b076042d8f0c49501372168142764.zip | |
Refactored renderer
Renderer is basically now more C++'y, as it makes more use of classes (a lot of GL types have been wrapped), and the renderer itself is now a class. The monitor mesh is also now indexed. Tweaked the NTSC artifacting after inadvertently fixing a bug with the way the image was loaded.
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
| diff --git a/src/game.cpp b/src/game.cpp index 1182689..228ff23 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
| @@ -10,12 +10,11 @@ | |||
| 10 | #include "systems/mapping.h" | 10 | #include "systems/mapping.h" |
| 11 | #include "systems/orienting.h" | 11 | #include "systems/orienting.h" |
| 12 | #include "animation.h" | 12 | #include "animation.h" |
| 13 | #include "renderer.h" | ||
| 14 | #include "consts.h" | 13 | #include "consts.h" |
| 15 | 14 | ||
| 16 | void key_callback(GLFWwindow* window, int key, int, int action, int) | 15 | void key_callback(GLFWwindow* window, int key, int, int action, int) |
| 17 | { | 16 | { |
| 18 | Game& game = *((Game*) glfwGetWindowUserPointer(window)); | 17 | Game& game = *static_cast<Game*>(glfwGetWindowUserPointer(window)); |
| 19 | 18 | ||
| 20 | if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE)) | 19 | if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE)) |
| 21 | { | 20 | { |
| @@ -27,10 +26,7 @@ void key_callback(GLFWwindow* window, int key, int, int action, int) | |||
| 27 | game.systemManager_.input(key, action); | 26 | game.systemManager_.input(key, action); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | Game::Game( | 29 | Game::Game() : world_("res/maps.xml") |
| 31 | GLFWwindow* window) : | ||
| 32 | window_(window), | ||
| 33 | world_("res/maps.xml") | ||
| 34 | { | 30 | { |
| 35 | systemManager_.emplaceSystem<ControllingSystem>(*this); | 31 | systemManager_.emplaceSystem<ControllingSystem>(*this); |
| 36 | systemManager_.emplaceSystem<OrientingSystem>(*this); | 32 | systemManager_.emplaceSystem<OrientingSystem>(*this); |
| @@ -65,8 +61,8 @@ Game::Game( | |||
| 65 | systemManager_.getSystem<MappingSystem>().loadMap(world_.getStartingMapId()); | 61 | systemManager_.getSystem<MappingSystem>().loadMap(world_.getStartingMapId()); |
| 66 | 62 | ||
| 67 | glfwSwapInterval(1); | 63 | glfwSwapInterval(1); |
| 68 | glfwSetWindowUserPointer(window_, this); | 64 | glfwSetWindowUserPointer(renderer_.getWindow().getHandle(), this); |
| 69 | glfwSetKeyCallback(window_, key_callback); | 65 | glfwSetKeyCallback(renderer_.getWindow().getHandle(), key_callback); |
| 70 | } | 66 | } |
| 71 | 67 | ||
| 72 | void Game::execute() | 68 | void Game::execute() |
| @@ -76,7 +72,8 @@ void Game::execute() | |||
| 76 | double accumulator = 0.0; | 72 | double accumulator = 0.0; |
| 77 | Texture texture(GAME_WIDTH, GAME_HEIGHT); | 73 | Texture texture(GAME_WIDTH, GAME_HEIGHT); |
| 78 | 74 | ||
| 79 | while (!(shouldQuit_ || glfwWindowShouldClose(window_))) | 75 | while (!(shouldQuit_ || |
| 76 | glfwWindowShouldClose(renderer_.getWindow().getHandle()))) | ||
| 80 | { | 77 | { |
| 81 | double currentTime = glfwGetTime(); | 78 | double currentTime = glfwGetTime(); |
| 82 | double frameTime = currentTime - lastTime; | 79 | double frameTime = currentTime - lastTime; |
| @@ -93,8 +90,8 @@ void Game::execute() | |||
| 93 | } | 90 | } |
| 94 | 91 | ||
| 95 | // Render | 92 | // Render |
| 96 | texture.fill(texture.entirety(), 0, 0, 0); | 93 | renderer_.fill(texture, texture.entirety(), 0, 0, 0); |
| 97 | systemManager_.render(texture); | 94 | systemManager_.render(texture); |
| 98 | texture.renderScreen(); | 95 | renderer_.renderScreen(texture); |
| 99 | } | 96 | } |
| 100 | } | 97 | } |
