1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-02 00:42:33 +01:00
openrw/rwgame/RWGame.hpp

138 lines
3.4 KiB
C++
Raw Normal View History

#ifndef _RWGAME_HPP_
#define _RWGAME_HPP_
2015-03-30 03:45:58 +02:00
2016-09-09 22:13:20 +02:00
#include <chrono>
2015-04-18 02:11:17 +02:00
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp>
#include <render/DebugDraw.hpp>
#include <script/ScriptMachine.hpp>
#include "game.hpp"
#include "GameBase.hpp"
class PlayerController;
class RWGame : public GameBase {
WorkContext work;
GameData data;
GameRenderer renderer;
DebugDraw debug;
2016-09-09 22:13:20 +02:00
GameState* state = nullptr;
GameWorld* world = nullptr;
ScriptMachine* script = nullptr;
2016-09-09 22:13:20 +02:00
std::chrono::steady_clock clock;
std::chrono::steady_clock::time_point last_clock_time;
bool inFocus = true;
ViewCamera lastCam, nextCam;
2016-10-12 01:29:24 +02:00
enum class DebugViewMode {
Disabled,
General,
Physics,
Navigation,
Objects
};
DebugViewMode debugview_ = DebugViewMode::Disabled;
2016-09-09 22:13:20 +02:00
int lastDraws; /// Number of draws issued for the last frame.
2016-09-09 22:13:20 +02:00
std::string cheatInputWindow = std::string(32, ' ');
float accum = 0.f;
float timescale = 1.f;
public:
2016-10-15 02:39:15 +02:00
RWGame(Logger& log, int argc, char* argv[]);
2016-09-09 22:13:20 +02:00
~RWGame();
int run();
/**
* Initalizes a new game
*/
void newGame();
GameState* getState() const {
return state;
}
GameWorld* getWorld() const {
return world;
}
const GameData& getGameData() const {
2016-09-09 22:13:20 +02:00
return data;
}
GameRenderer& getRenderer() {
2016-09-09 22:13:20 +02:00
return renderer;
}
ScriptMachine* getScript() const {
return script;
}
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal,
GameObject** object = nullptr) {
auto vc = nextCam;
glm::vec3 from(vc.position.x, vc.position.y, vc.position.z);
glm::vec3 tmp = vc.rotation * glm::vec3(1000.f, 0.f, 0.f);
return hitWorldRay(from, tmp, hit, normal, object);
}
bool hitWorldRay(const glm::vec3& start, const glm::vec3& direction,
glm::vec3& hit, glm::vec3& normal,
GameObject** object = nullptr) {
auto from = btVector3(start.x, start.y, start.z);
auto to = btVector3(start.x + direction.x, start.y + direction.y,
start.z + direction.z);
btCollisionWorld::ClosestRayResultCallback ray(from, to);
world->dynamicsWorld->rayTest(from, to, ray);
if (ray.hasHit()) {
hit = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
ray.m_hitPointWorld.z());
normal =
glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
ray.m_hitNormalWorld.z());
if (object) {
*object = static_cast<GameObject*>(
ray.m_collisionObject->getUserPointer());
}
return true;
}
return false;
}
void startScript(const std::string& name);
bool hasFocus() const {
return inFocus;
}
void saveGame(const std::string& savename);
void loadGame(const std::string& savename);
/** shortcut for getWorld()->state.player->getCharacter() */
PlayerController* getPlayer();
private:
2016-09-09 22:13:20 +02:00
void tick(float dt);
void render(float alpha, float dt);
void renderDebugStats(float time);
2016-09-09 22:13:20 +02:00
void renderDebugPaths(float time);
void renderDebugObjects(float time, ViewCamera& camera);
2016-09-09 22:13:20 +02:00
void renderProfile();
2016-09-09 22:13:20 +02:00
void handleCheatInput(char symbol);
2016-09-01 23:14:15 +02:00
2016-09-09 22:13:20 +02:00
void globalKeyEvent(const SDL_Event& event);
};
#endif