1
0
mirror of https://github.com/rwengine/openrw.git synced 2025-01-31 12:01:38 +01:00

improved viewer with debuging information

This commit is contained in:
Daniel Evans 2013-07-06 01:39:54 +01:00
parent bdaf85af75
commit 68b1be9b4b
7 changed files with 77 additions and 22 deletions

View File

@ -1,4 +1,5 @@
#include <renderwure/engine/GTAData.hpp>
#include <renderwure/engine/GTAEngine.hpp>
#include <renderwure/loaders/LoaderIPL.hpp>
#include <renderwure/loaders/LoaderDFF.hpp>
#include <renderwure/loaders/LoaderIDE.hpp>
@ -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;

View File

@ -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);

View File

@ -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>& model, const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scale, const std::string& name)

View File

@ -12,6 +12,7 @@
#include <map>
#include <memory>
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
*/

View File

@ -40,7 +40,7 @@ public:
std::string message;
};
std::queue<LogEntry> log;
std::deque<LogEntry> 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

View File

@ -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);

View File

@ -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;