1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02:00
openrw/rwgame/RWGame.hpp

137 lines
2.8 KiB
C++
Raw Normal View History

2016-10-16 21:39:05 +02:00
#ifndef RWGAME_RWGAME_HPP
#define RWGAME_RWGAME_HPP
2015-03-30 03:45:58 +02:00
#include "GameBase.hpp"
#include "HUDDrawer.hpp"
2018-12-20 20:31:14 +01:00
#include "RWConfig.hpp"
#include "RWImGui.hpp"
#include "StateManager.hpp"
2018-12-09 22:43:42 +01:00
#include "game.hpp"
2015-04-18 02:11:17 +02:00
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
#include <engine/GameWorld.hpp>
#include <render/DebugDraw.hpp>
#include <render/GameRenderer.hpp>
#include <script/SCMFile.hpp>
#include <script/ScriptMachine.hpp>
#include <script/modules/GTA3Module.hpp>
2018-12-09 22:43:42 +01:00
#include <SDL_events.h>
#include <chrono>
class RWGame final : public GameBase {
2019-05-21 21:04:55 +02:00
public:
enum class DebugViewMode {
Disabled,
General,
Physics,
Navigation,
Objects
};
private:
GameData data;
GameRenderer renderer;
2018-12-20 20:31:14 +01:00
RWImGui imgui;
DebugDraw debug;
GameState state;
2018-10-29 16:54:13 +01:00
HUDDrawer hudDrawer{};
2016-10-20 01:49:15 +02:00
std::unique_ptr<GameWorld> world;
GTA3Module opcodes;
std::unique_ptr<ScriptMachine> vm;
SCMFile script;
StateManager stateManager;
2016-09-09 22:13:20 +02:00
bool inFocus = true;
ViewCamera currentCam;
2016-10-12 01:29:24 +02:00
DebugViewMode debugview_ = DebugViewMode::Disabled;
2018-05-19 23:55:27 +02:00
int lastDraws{0}; /// Number of draws issued for the last frame.
2016-09-09 22:13:20 +02:00
std::string cheatInputWindow = std::string(32, ' ');
public:
RWGame(Logger& log, const std::optional<RWArgConfigLayer> &args);
~RWGame() override;
2016-09-09 22:13:20 +02:00
int run();
/**
* Initalizes a new game
*/
void newGame();
StateManager& getStateManager() {
return stateManager;
}
GameState* getState() {
return &state;
2016-09-09 22:13:20 +02:00
}
2016-10-20 01:49:15 +02:00
GameWorld* getWorld() {
return world.get();
2016-09-09 22:13:20 +02:00
}
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* getScriptVM() const {
return vm.get();
2016-09-09 22:13:20 +02:00
}
2018-10-29 14:52:18 +01:00
HUDDrawer& getHUDDrawer() {
return hudDrawer;
}
2019-05-21 21:04:55 +02:00
DebugViewMode getDebugViewMode() const {
return debugview_;
}
2016-09-09 22:13:20 +02:00
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal,
2018-12-09 22:43:42 +01:00
GameObject** object = nullptr);
2016-09-09 22:13:20 +02:00
bool hitWorldRay(const glm::vec3& start, const glm::vec3& direction,
glm::vec3& hit, glm::vec3& normal,
2018-12-09 22:43:42 +01:00
GameObject** object = nullptr);
2016-09-09 22:13:20 +02:00
void startScript(const std::string& name);
bool hasFocus() const {
return inFocus;
}
void saveGame(const std::string& savename);
void loadGame(const std::string& savename);
private:
2016-09-09 22:13:20 +02:00
void tick(float dt);
void render(float alpha, float dt);
2019-05-21 21:04:55 +02:00
void renderDebugPaths();
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);
bool updateInput();
float tickWorld(const float deltaTime, float accumulatedTime);
2019-05-21 21:04:55 +02:00
void renderDebugView();
void tickObjects(float dt) const;
};
#endif