From d3d21659476b18d27c39bab2287f1ce22ddf5887 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Fri, 27 Dec 2013 22:57:11 +0000 Subject: [PATCH] Adjusted game clock for 24 minute day --- framework2/include/engine/GameWorld.hpp | 10 ++++++++++ framework2/src/engine/GameWorld.cpp | 14 +++++++++++++- framework2/src/render/GTARenderer.cpp | 7 ++++--- viewer/main.cpp | 7 ++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/framework2/include/engine/GameWorld.hpp b/framework2/include/engine/GameWorld.hpp index c1750e9f..f0742a5f 100644 --- a/framework2/include/engine/GameWorld.hpp +++ b/framework2/include/engine/GameWorld.hpp @@ -103,6 +103,16 @@ public: */ void destroyObject(GTAObject* object); + /** + * Returns the current hour + */ + int getHour(); + + /** + * Returns the current minute + */ + int getMinute(); + /** * Game Clock */ diff --git a/framework2/src/engine/GameWorld.cpp b/framework2/src/engine/GameWorld.cpp index b051ce73..296e3f62 100644 --- a/framework2/src/engine/GameWorld.cpp +++ b/framework2/src/engine/GameWorld.cpp @@ -330,4 +330,16 @@ void GameWorld::destroyObject(GTAObject* object) } } delete object; -} \ No newline at end of file +} + +int GameWorld::getHour() +{ + const float dayseconds = (24.f * 60.f); + float daytime = fmod(gameTime, dayseconds); + return daytime / 60.f; +} + +int GameWorld::getMinute() +{ + return fmod(gameTime, 60.f); +} diff --git a/framework2/src/render/GTARenderer.cpp b/framework2/src/render/GTARenderer.cpp index b716494d..0c378bbd 100644 --- a/framework2/src/render/GTARenderer.cpp +++ b/framework2/src/render/GTARenderer.cpp @@ -220,16 +220,17 @@ void GTARenderer::renderWorld() { glBindVertexArray( vao ); - float gameTime = fmod(engine->gameTime, 24.f); + float tod = fmod(engine->gameTime, 24.f * 60.f); - auto weather = engine->gameData.weatherLoader.getWeatherData(WeatherLoader::Sunny, gameTime); + // Requires a float 0-24 + auto weather = engine->gameData.weatherLoader.getWeatherData(WeatherLoader::Sunny, tod / 60.f); glm::vec3 skyTop = weather.skyTopColor; glm::vec3 skyBottom = weather.skyBottomColor; glm::vec3 ambient = weather.ambientColor; glm::vec3 dynamic = weather.directLightColor; - float theta = (gameTime - 12.f)/24.0 * 2 * 3.14159265; + float theta = (tod/(60.f * 24.f) - 0.5f) * 2 * 3.14159265; glm::vec3 sunDirection{ sin(theta), 0.0, diff --git a/viewer/main.cpp b/viewer/main.cpp index 9c3ed96b..cd83067f 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -400,6 +401,9 @@ void init(std::string gtapath, bool loadWorld) gta->load(); + // Set time to noon. + gta->gameTime = 12.f * 60.f; + // Loade all of the IDEs. for(std::map::iterator it = gta->gameData.ideLocations.begin(); it != gta->gameData.ideLocations.end(); @@ -550,7 +554,8 @@ void render() window.resetGLStates(); std::stringstream ss; - ss << "Time: " << fmod(floor(gta->gameTime), 24.f) << ":" << (floor(fmod(gta->gameTime, 1.f) * 60.f)) << std::endl; + ss << std::setfill('0') << "Time: " << std::setw(2) << gta->getHour() + << ":" << std::setw(2) << gta->getMinute() << std::endl; ss << "Game Time: " << gta->gameTime << std::endl; ss << "Camera: " << plyPos.x << " " << plyPos.y << " " << plyPos.z << std::endl;