mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 20:02:40 +01:00
Remove GameRenderer from GameWorld
- Particle rendering is broken, since objects can't access renderer
This commit is contained in:
parent
dfd68abd8e
commit
a967e190de
@ -6,12 +6,12 @@
|
||||
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
|
||||
#include <ai/AIGraphNode.hpp>
|
||||
#include <ai/AIGraph.hpp>
|
||||
#include <audio/SoundManager.hpp>
|
||||
|
||||
class CutsceneObject;
|
||||
class WorkContext;
|
||||
|
||||
class GameObject;
|
||||
@ -159,11 +159,6 @@ public:
|
||||
* Game data
|
||||
*/
|
||||
GameData gameData;
|
||||
|
||||
/**
|
||||
* Renderer
|
||||
*/
|
||||
GameRenderer renderer;
|
||||
|
||||
/**
|
||||
* Gameplay state
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
};
|
||||
|
||||
GameWorld::GameWorld(const std::string& path)
|
||||
: gameTime(0.f), gameData(path), renderer(this), randomEngine(rand()),
|
||||
: gameTime(0.f), gameData(path), randomEngine(rand()),
|
||||
_work( new WorkContext( this ) ), script(nullptr), cutsceneAudio(nullptr), missionAudio(nullptr),
|
||||
paused(false)
|
||||
{
|
||||
|
@ -45,7 +45,8 @@ void WeaponItem::fireHitscan()
|
||||
float flashtime = 0.015f;
|
||||
auto shotdir = glm::normalize(farTarget - fireOrigin);
|
||||
|
||||
_character->engine->renderer.addParticle({
|
||||
/// @TODO move this into rendering logic.
|
||||
/*_character->engine->renderer.addParticle({
|
||||
fireOrigin + shotdir * tracersize / 2.f,
|
||||
shotdir,
|
||||
tracerspeed,
|
||||
@ -88,6 +89,7 @@ void WeaponItem::fireHitscan()
|
||||
{0.2f, 0.2f},
|
||||
flashUp
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
void WeaponItem::fireProjectile()
|
||||
|
@ -67,7 +67,8 @@ void PickupObject::tick(float dt)
|
||||
|
||||
auto tex = engine->gameData.findTexture("coronacircle")->getName();
|
||||
|
||||
engine->renderer.addParticle({
|
||||
/// @TODO move this into rendering logic.
|
||||
/*engine->renderer.addParticle({
|
||||
position,
|
||||
{0.f, 0.f, 1.f},
|
||||
0.f,
|
||||
@ -75,8 +76,8 @@ void PickupObject::tick(float dt)
|
||||
engine->gameTime, dt,
|
||||
tex,
|
||||
{1.f, 1.f},
|
||||
{}, {0.75f, 0.f, 0.f, 1.f} /** @todo configurable tint colour */
|
||||
});
|
||||
{}, {0.75f, 0.f, 0.f, 1.f}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,8 +73,7 @@ void ProjectileObject::explode()
|
||||
|
||||
auto tex = engine->gameData.findTexture("explo02")->getName();
|
||||
|
||||
/// @todo add support for image sets and opacity to the particle system.
|
||||
engine->renderer.addParticle({
|
||||
/*engine->renderer.addParticle({
|
||||
position,
|
||||
{0.f, 0.f, 1.f},
|
||||
0.f,
|
||||
@ -82,7 +81,7 @@ void ProjectileObject::explode()
|
||||
engine->gameTime, 0.5f,
|
||||
tex,
|
||||
{exp_size, exp_size}
|
||||
});
|
||||
});*/
|
||||
|
||||
_exploded = true;
|
||||
engine->destroyObjectQueued(this);
|
||||
|
@ -37,9 +37,9 @@ void drawHUD(PlayerController* player, GameWorld* world, GameRenderer* render)
|
||||
drawMap(player, world, render);
|
||||
}
|
||||
|
||||
void drawOnScreenText(GameWorld* world)
|
||||
void drawOnScreenText(GameWorld* world, GameRenderer* renderer)
|
||||
{
|
||||
const glm::ivec2& vp = world->renderer.getRenderer()->getViewport();
|
||||
const glm::ivec2& vp = renderer->getRenderer()->getViewport();
|
||||
|
||||
TextRenderer::TextInfo ti;
|
||||
ti.font = 2;
|
||||
@ -127,10 +127,10 @@ void drawOnScreenText(GameWorld* world)
|
||||
shadow.baseColour = glm::vec3(0.f);
|
||||
shadow.screenPosition += shadowOffset;
|
||||
|
||||
world->renderer.text.renderText(shadow);
|
||||
renderer->text.renderText(shadow);
|
||||
}
|
||||
|
||||
world->renderer.text.renderText(ti);
|
||||
renderer->text.renderText(ti);
|
||||
}
|
||||
|
||||
for(auto& t : world->state.texts) {
|
||||
@ -141,6 +141,6 @@ void drawOnScreenText(GameWorld* world)
|
||||
ti.size = 20.f;
|
||||
ti.text = t.text;
|
||||
|
||||
world->renderer.text.renderText(ti);
|
||||
renderer->text.renderText(ti);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
|
||||
class PlayerController;
|
||||
|
||||
void drawHUD(PlayerController* player, GameWorld* world, GameRenderer* render);
|
||||
|
||||
void drawOnScreenText(GameWorld* world);
|
||||
void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
|
@ -22,7 +22,7 @@ DebugDraw* debug;
|
||||
StdOutReciever logPrinter;
|
||||
|
||||
RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
|
||||
: engine(nullptr), inFocus(true), showDebugStats(false),
|
||||
: engine(nullptr), renderer(nullptr), inFocus(true), showDebugStats(false),
|
||||
accum(0.f), timescale(1.f)
|
||||
{
|
||||
size_t w = GAME_WINDOW_WIDTH, h = GAME_WINDOW_HEIGHT;
|
||||
@ -67,16 +67,19 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
|
||||
|
||||
engine = new GameWorld(gamepath);
|
||||
engine->logger.addReciever(&logPrinter);
|
||||
|
||||
|
||||
// Initalize all the archives.
|
||||
engine->gameData.loadIMG("/models/gta3");
|
||||
engine->gameData.loadIMG("/models/txd");
|
||||
engine->gameData.loadIMG("/anim/cuts");
|
||||
|
||||
// Initialize renderer
|
||||
renderer = new GameRenderer(engine);
|
||||
|
||||
// Set up text renderer
|
||||
engine->renderer.text.setFontTexture(0, "pager");
|
||||
engine->renderer.text.setFontTexture(1, "font1");
|
||||
engine->renderer.text.setFontTexture(2, "font2");
|
||||
renderer->text.setFontTexture(0, "pager");
|
||||
renderer->text.setFontTexture(1, "font1");
|
||||
renderer->text.setFontTexture(2, "font2");
|
||||
|
||||
/// @TODO expand this here.
|
||||
engine->load();
|
||||
@ -114,6 +117,7 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
|
||||
|
||||
RWGame::~RWGame()
|
||||
{
|
||||
delete renderer;
|
||||
delete engine;
|
||||
}
|
||||
|
||||
@ -173,7 +177,7 @@ int RWGame::run()
|
||||
|
||||
render(alpha, timer);
|
||||
|
||||
StateManager::get().draw(&engine->renderer);
|
||||
StateManager::get().draw(renderer);
|
||||
|
||||
window.display();
|
||||
|
||||
@ -245,7 +249,7 @@ void RWGame::tick(float dt)
|
||||
void RWGame::render(float alpha, float time)
|
||||
{
|
||||
auto size = getWindow().getSize();
|
||||
engine->renderer.getRenderer()->setViewport({size.x, size.y});
|
||||
renderer->getRenderer()->setViewport({size.x, size.y});
|
||||
|
||||
ViewCamera viewCam;
|
||||
if( engine->state.currentCutscene != nullptr && engine->state.cutsceneStartTime >= 0.f )
|
||||
@ -307,7 +311,7 @@ void RWGame::render(float alpha, float time)
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
|
||||
|
||||
engine->renderer.renderWorld(viewCam, alpha);
|
||||
renderer->renderWorld(viewCam, alpha);
|
||||
|
||||
#if 0
|
||||
debug->setShaderProgram(engine->renderer.worldProg);
|
||||
@ -334,14 +338,14 @@ void RWGame::render(float alpha, float time)
|
||||
renderDebugStats(time);
|
||||
}
|
||||
|
||||
drawOnScreenText(engine);
|
||||
drawOnScreenText(engine, renderer);
|
||||
}
|
||||
|
||||
void RWGame::renderDebugStats(float time)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Frametime: " << time << " (FPS " << (1.f/time) << ")\n";
|
||||
ss << "Draws: " << engine->renderer.rendered << " (" << engine->renderer.culled << " Culled)\n";
|
||||
ss << "Draws: " << renderer->rendered << " (" << renderer->culled << " Culled)\n";
|
||||
|
||||
// Count the number of interesting objects.
|
||||
int peds = 0, cars = 0;
|
||||
@ -373,7 +377,7 @@ void RWGame::renderDebugStats(float time)
|
||||
ti.font = 2;
|
||||
ti.screenPosition = glm::vec2( 10.f, 10.f );
|
||||
ti.size = 15.f;
|
||||
engine->renderer.text.renderText(ti);
|
||||
renderer->text.renderText(ti);
|
||||
|
||||
/*while( engine->log.size() > 0 && engine->log.front().time + 10.f < engine->gameTime ) {
|
||||
engine->log.pop_front();
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _RWGAME_HPP_
|
||||
#define _RWGAME_HPP_
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
#include "game.hpp"
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
@ -8,6 +9,8 @@
|
||||
class RWGame
|
||||
{
|
||||
GameWorld* engine;
|
||||
// must be allocated after Logger setup.
|
||||
GameRenderer* renderer;
|
||||
sf::RenderWindow window;
|
||||
sf::Clock clock;
|
||||
bool inFocus;
|
||||
@ -27,6 +30,11 @@ public:
|
||||
{
|
||||
return engine;
|
||||
}
|
||||
|
||||
GameRenderer* getRenderer() const
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
sf::RenderWindow& getWindow()
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ void PauseState::draw(GameRenderer* r)
|
||||
map.mapScreenTop = glm::vec2(vp.x, vp.y);
|
||||
map.mapScreenBottom = glm::vec2(0.f, 0.f);
|
||||
|
||||
getWorld()->renderer.map.draw(map);
|
||||
game->getRenderer()->map.draw(map);
|
||||
|
||||
State::draw(r);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user