mirror of
https://github.com/rwengine/openrw.git
synced 2025-01-31 20:11:37 +01:00
improved viewer with debuging information
This commit is contained in:
parent
bdaf85af75
commit
68b1be9b4b
@ -1,4 +1,5 @@
|
|||||||
#include <renderwure/engine/GTAData.hpp>
|
#include <renderwure/engine/GTAData.hpp>
|
||||||
|
#include <renderwure/engine/GTAEngine.hpp>
|
||||||
#include <renderwure/loaders/LoaderIPL.hpp>
|
#include <renderwure/loaders/LoaderIPL.hpp>
|
||||||
#include <renderwure/loaders/LoaderDFF.hpp>
|
#include <renderwure/loaders/LoaderDFF.hpp>
|
||||||
#include <renderwure/loaders/LoaderIDE.hpp>
|
#include <renderwure/loaders/LoaderIDE.hpp>
|
||||||
@ -61,7 +62,7 @@ std::string fixPath(std::string path) {
|
|||||||
|
|
||||||
|
|
||||||
GTAData::GTAData(const 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
|
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;
|
return nullptr;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
GTAEngine::GTAEngine(const std::string& path)
|
GTAEngine::GTAEngine(const std::string& path)
|
||||||
: itemCount(0), gameData(path), gameTime(0.f), randomEngine(rand())
|
: itemCount(0), gameData(path), gameTime(0.f), randomEngine(rand())
|
||||||
{
|
{
|
||||||
|
gameData.engine = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GTAEngine::load()
|
bool GTAEngine::load()
|
||||||
@ -32,12 +32,17 @@ bool GTAEngine::load()
|
|||||||
|
|
||||||
void GTAEngine::logInfo(const std::string& info)
|
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)
|
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)
|
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];
|
sec = gameData.vehicleColours[palit->second[set].second];
|
||||||
}
|
}
|
||||||
else {
|
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);
|
auto wi = objectTypes.find(vti->second->wheelModelID);
|
||||||
|
@ -157,6 +157,8 @@ GTARenderer::GTARenderer()
|
|||||||
skyUniTop = glGetUniformLocation(skyProgram, "TopColor");
|
skyUniTop = glGetUniformLocation(skyProgram, "TopColor");
|
||||||
skyUniBottom = glGetUniformLocation(skyProgram, "BottomColor");
|
skyUniBottom = glGetUniformLocation(skyProgram, "BottomColor");
|
||||||
|
|
||||||
|
glGenVertexArrays( 1, &vao );
|
||||||
|
|
||||||
// prepare our special internal plane.
|
// prepare our special internal plane.
|
||||||
glGenBuffers(1, &planeVBO);
|
glGenBuffers(1, &planeVBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 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)
|
void GTARenderer::renderWorld(GTAEngine* engine)
|
||||||
{
|
{
|
||||||
|
glBindVertexArray( vao );
|
||||||
|
|
||||||
float gameTime = fmod(engine->gameTime, 24.f);
|
float gameTime = fmod(engine->gameTime, 24.f);
|
||||||
int hour = floor(gameTime);
|
int hour = floor(gameTime);
|
||||||
int hournext = (hour + 1) % 24;
|
int hournext = (hour + 1) % 24;
|
||||||
|
|
||||||
// std::cout << leclock << " " << hour << std::endl;
|
// std::cout << leclock << " " << hour << std::endl;
|
||||||
auto weather = engine->gameData.weatherLoader.weather[hour/2];
|
auto weather = engine->gameData.weatherLoader.weather[hour];
|
||||||
auto weathernext = engine->gameData.weatherLoader.weather[hournext/2];
|
auto weathernext = engine->gameData.weatherLoader.weather[hournext];
|
||||||
|
|
||||||
float interpolate = gameTime - hour;
|
float interpolate = gameTime - hour;
|
||||||
glm::vec3 skyTop{
|
glm::vec3 skyTop{
|
||||||
@ -457,6 +461,11 @@ void GTARenderer::renderWorld(GTAEngine* engine)
|
|||||||
glUniform4f(skyUniBottom, skyBottom.r, skyBottom.g, skyBottom.b, 1.f);
|
glUniform4f(skyUniBottom, skyBottom.r, skyBottom.g, skyBottom.b, 1.f);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, skydomeSegments * skydomeRows * 2 + 1);
|
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)
|
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)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class GTAEngine;
|
||||||
/**
|
/**
|
||||||
* Handles loading and management of the Game's DAT
|
* Handles loading and management of the Game's DAT
|
||||||
*/
|
*/
|
||||||
@ -40,6 +41,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
GTAData(const std::string& path);
|
GTAData(const std::string& path);
|
||||||
|
|
||||||
|
GTAEngine* engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current platform
|
* Returns the current platform
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::queue<LogEntry> log;
|
std::deque<LogEntry> log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays an informative message
|
* Displays an informative message
|
||||||
@ -52,6 +52,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void logError(const std::string& error);
|
void logError(const std::string& error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a comforting warning
|
||||||
|
*/
|
||||||
|
void logWarning(const std::string& warning);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct GTAObject
|
* @struct GTAObject
|
||||||
* Stores references to the Object data and the instance
|
* Stores references to the Object data and the instance
|
||||||
|
@ -28,6 +28,9 @@ public:
|
|||||||
GLuint skyProgram;
|
GLuint skyProgram;
|
||||||
GLint skyUniView, skyUniProj, skyUniTop, skyUniBottom;
|
GLint skyUniView, skyUniProj, skyUniTop, skyUniBottom;
|
||||||
|
|
||||||
|
/// Internal VAO to avoid clobbering global state.
|
||||||
|
GLuint vao;
|
||||||
|
|
||||||
GLuint planeVBO, skydomeVBO;
|
GLuint planeVBO, skydomeVBO;
|
||||||
|
|
||||||
void renderWorld(GTAEngine* engine);
|
void renderWorld(GTAEngine* engine);
|
||||||
|
@ -21,7 +21,6 @@ constexpr double PiOver180 = 3.1415926535897932384626433832795028/180;
|
|||||||
|
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
|
|
||||||
LoaderDFF dffLoader;
|
|
||||||
GTAEngine* gta = nullptr;
|
GTAEngine* gta = nullptr;
|
||||||
|
|
||||||
glm::vec3 plyPos;
|
glm::vec3 plyPos;
|
||||||
@ -68,8 +67,6 @@ void handleEvent(sf::Event &event)
|
|||||||
|
|
||||||
void init(std::string gtapath)
|
void init(std::string gtapath)
|
||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
// GTA GET
|
// GTA GET
|
||||||
gta = new GTAEngine(gtapath);
|
gta = new GTAEngine(gtapath);
|
||||||
|
|
||||||
@ -152,19 +149,48 @@ void render()
|
|||||||
// Update aspect ratio..
|
// Update aspect ratio..
|
||||||
gta->renderer.camera.frustum.aspectRatio = window.getSize().x / (float) window.getSize().y;
|
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);
|
gta->renderer.renderWorld(gta);
|
||||||
|
|
||||||
glUseProgram(0);
|
|
||||||
window.pushGLStates();
|
|
||||||
window.resetGLStates();
|
window.resetGLStates();
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << floor(gta->gameTime) << " (Hour " << fmod(floor(gta->gameTime), 24.f) << ")";
|
ss << fmod(floor(gta->gameTime), 24.f) << ":" << (floor(fmod(gta->gameTime, 1.f) * 60.f)) << " (" << gta->gameTime << ")";
|
||||||
sf::Text t(ss.str(), font, 20);
|
sf::Text text(ss.str(), font, 15);
|
||||||
t.setPosition(10, 10);
|
text.setPosition(10, 10);
|
||||||
window.draw(t);
|
window.draw(text);
|
||||||
window.popGLStates();
|
|
||||||
|
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;
|
static size_t fc = 0;
|
||||||
if(fc++ == 60)
|
if(fc++ == 60)
|
||||||
@ -181,8 +207,8 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! font.loadFromFile("DejaVuSansCondensed.ttf")) {
|
if(! font.loadFromFile("DejaVuSansMono.ttf")) {
|
||||||
std::cerr << "Failed to load font DejaVuSansCondensed" << std::endl;
|
std::cerr << "Failed to load font" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user