diff --git a/framework2/GTAData.cpp b/framework2/GTAData.cpp index 9aa1aeee..d47a34e7 100644 --- a/framework2/GTAData.cpp +++ b/framework2/GTAData.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -61,7 +62,7 @@ std::string fixPath(std::string path) { GTAData::GTAData(const std::string& path) -: datpath(path) +: datpath(path), engine(nullptr) { } @@ -371,7 +372,10 @@ char* GTAData::loadFile(const std::string& name) } else { - std::cerr << "Unable to locate file " << name << std::endl; + std::stringstream err; + err << "Unable to locate file " << name; + engine->logError(err.str()); + std::cerr << err.str() << std::endl; } return nullptr; diff --git a/framework2/GTAEngine.cpp b/framework2/GTAEngine.cpp index 8ed7a4b6..d57a4f58 100644 --- a/framework2/GTAEngine.cpp +++ b/framework2/GTAEngine.cpp @@ -5,7 +5,7 @@ GTAEngine::GTAEngine(const std::string& path) : itemCount(0), gameData(path), gameTime(0.f), randomEngine(rand()) { - + gameData.engine = this; } bool GTAEngine::load() @@ -32,12 +32,17 @@ bool GTAEngine::load() void GTAEngine::logInfo(const std::string& info) { - log.push({LogEntry::Info, gameTime, info}); + log.push_back({LogEntry::Info, gameTime, info}); } void GTAEngine::logError(const std::string& error) { - log.push({LogEntry::Error, gameTime, error}); + log.push_back({LogEntry::Error, gameTime, error}); +} + +void GTAEngine::logWarning(const std::string& warning) +{ + log.push_back({LogEntry::Warning, gameTime, warning}); } bool GTAEngine::defineItems(const std::string& name) @@ -167,7 +172,7 @@ void GTAEngine::createVehicle(const uint16_t id, const glm::vec3& pos) sec = gameData.vehicleColours[palit->second[set].second]; } else { - std::cerr << "No colour palette for vehicle " << vti->second->modelName << std::endl; + logWarning("No colour palette for vehicle " + vti->second->modelName); } auto wi = objectTypes.find(vti->second->wheelModelID); diff --git a/framework2/GTARenderer.cpp b/framework2/GTARenderer.cpp index b88cf8a9..040d0837 100644 --- a/framework2/GTARenderer.cpp +++ b/framework2/GTARenderer.cpp @@ -157,6 +157,8 @@ GTARenderer::GTARenderer() skyUniTop = glGetUniformLocation(skyProgram, "TopColor"); skyUniBottom = glGetUniformLocation(skyProgram, "BottomColor"); + glGenVertexArrays( 1, &vao ); + // prepare our special internal plane. glGenBuffers(1, &planeVBO); glBindBuffer(GL_ARRAY_BUFFER, planeVBO); @@ -194,13 +196,15 @@ float mix(uint8_t a, uint8_t b, float num) void GTARenderer::renderWorld(GTAEngine* engine) { + glBindVertexArray( vao ); + float gameTime = fmod(engine->gameTime, 24.f); int hour = floor(gameTime); int hournext = (hour + 1) % 24; // std::cout << leclock << " " << hour << std::endl; - auto weather = engine->gameData.weatherLoader.weather[hour/2]; - auto weathernext = engine->gameData.weatherLoader.weather[hournext/2]; + auto weather = engine->gameData.weatherLoader.weather[hour]; + auto weathernext = engine->gameData.weatherLoader.weather[hournext]; float interpolate = gameTime - hour; glm::vec3 skyTop{ @@ -457,6 +461,11 @@ void GTARenderer::renderWorld(GTAEngine* engine) glUniform4f(skyUniBottom, skyBottom.r, skyBottom.g, skyBottom.b, 1.f); glDrawArrays(GL_TRIANGLE_STRIP, 0, skydomeSegments * skydomeRows * 2 + 1); + + glUseProgram(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray( 0 ); } void GTARenderer::renderNamedFrame(GTAEngine* engine, const std::unique_ptr& model, const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scale, const std::string& name) diff --git a/framework2/include/renderwure/engine/GTAData.hpp b/framework2/include/renderwure/engine/GTAData.hpp index a59587c0..6133809b 100644 --- a/framework2/include/renderwure/engine/GTAData.hpp +++ b/framework2/include/renderwure/engine/GTAData.hpp @@ -12,6 +12,7 @@ #include #include +class GTAEngine; /** * Handles loading and management of the Game's DAT */ @@ -40,6 +41,8 @@ public: */ GTAData(const std::string& path); + GTAEngine* engine; + /** * Returns the current platform */ diff --git a/framework2/include/renderwure/engine/GTAEngine.hpp b/framework2/include/renderwure/engine/GTAEngine.hpp index b8713c2e..aa1dabb7 100644 --- a/framework2/include/renderwure/engine/GTAEngine.hpp +++ b/framework2/include/renderwure/engine/GTAEngine.hpp @@ -40,7 +40,7 @@ public: std::string message; }; - std::queue log; + std::deque log; /** * Displays an informative message @@ -52,6 +52,11 @@ public: */ void logError(const std::string& error); + /** + * Displays a comforting warning + */ + void logWarning(const std::string& warning); + /** * @struct GTAObject * Stores references to the Object data and the instance diff --git a/framework2/include/renderwure/render/GTARenderer.hpp b/framework2/include/renderwure/render/GTARenderer.hpp index bd663090..d7fc788e 100644 --- a/framework2/include/renderwure/render/GTARenderer.hpp +++ b/framework2/include/renderwure/render/GTARenderer.hpp @@ -28,6 +28,9 @@ public: GLuint skyProgram; GLint skyUniView, skyUniProj, skyUniTop, skyUniBottom; + /// Internal VAO to avoid clobbering global state. + GLuint vao; + GLuint planeVBO, skydomeVBO; void renderWorld(GTAEngine* engine); diff --git a/viewer/main.cpp b/viewer/main.cpp index afd91ceb..eb7d3923 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -21,7 +21,6 @@ constexpr double PiOver180 = 3.1415926535897932384626433832795028/180; sf::RenderWindow window; -LoaderDFF dffLoader; GTAEngine* gta = nullptr; glm::vec3 plyPos; @@ -68,8 +67,6 @@ void handleEvent(sf::Event &event) void init(std::string gtapath) { - glEnable(GL_DEPTH_TEST); - // GTA GET gta = new GTAEngine(gtapath); @@ -152,19 +149,48 @@ void render() // Update aspect ratio.. gta->renderer.camera.frustum.aspectRatio = window.getSize().x / (float) window.getSize().y; - glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + //glEnable(GL_CULL_FACE); gta->renderer.renderWorld(gta); - glUseProgram(0); - window.pushGLStates(); window.resetGLStates(); + std::stringstream ss; - ss << floor(gta->gameTime) << " (Hour " << fmod(floor(gta->gameTime), 24.f) << ")"; - sf::Text t(ss.str(), font, 20); - t.setPosition(10, 10); - window.draw(t); - window.popGLStates(); + ss << fmod(floor(gta->gameTime), 24.f) << ":" << (floor(fmod(gta->gameTime, 1.f) * 60.f)) << " (" << gta->gameTime << ")"; + sf::Text text(ss.str(), font, 15); + text.setPosition(10, 10); + window.draw(text); + + while( gta->log.size() > 0 && gta->log.front().time + 10.f < gta->gameTime ) { + gta->log.pop_front(); + } + + sf::Vector2f tpos(10.f, 40.f); + text.setCharacterSize(15); + for(auto it = gta->log.begin(); it != gta->log.end(); ++it) { + text.setString(it->message); + switch(it->type) { + case GTAEngine::LogEntry::Error: + text.setColor(sf::Color::Red); + break; + case GTAEngine::LogEntry::Warning: + text.setColor(sf::Color::Yellow); + break; + default: + text.setColor(sf::Color::White); + break; + } + + // Interpolate the color + auto c = text.getColor(); + c.a = (gta->gameTime - it->time > 5.f) ? 255 - (((gta->gameTime - it->time) - 5.f)/5.f) * 255 : 255; + text.setColor(c); + + text.setPosition(tpos); + window.draw(text); + tpos.y += text.getLocalBounds().height; + } static size_t fc = 0; if(fc++ == 60) @@ -181,8 +207,8 @@ int main(int argc, char *argv[]) exit(1); } - if(! font.loadFromFile("DejaVuSansCondensed.ttf")) { - std::cerr << "Failed to load font DejaVuSansCondensed" << std::endl; + if(! font.loadFromFile("DejaVuSansMono.ttf")) { + std::cerr << "Failed to load font" << std::endl; } glewExperimental = GL_TRUE;