2016-10-16 21:39:05 +02:00
|
|
|
#ifndef RWGAME_RWGAME_HPP
|
|
|
|
#define RWGAME_RWGAME_HPP
|
2015-03-30 03:45:58 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
#include "game.hpp"
|
|
|
|
#include "GameBase.hpp"
|
|
|
|
#include "HUDDrawer.hpp"
|
|
|
|
#include "RWConfig.hpp"
|
2018-12-18 22:43:49 +01:00
|
|
|
#include "StateManager.hpp"
|
2017-11-01 03:13:07 +01:00
|
|
|
|
2018-08-30 17:37:27 +02:00
|
|
|
#ifdef _MSC_VER
|
2018-12-12 13:53:32 +01:00
|
|
|
#pragma warning(disable : 4305)
|
2018-08-30 17:37:27 +02:00
|
|
|
#endif
|
2018-05-21 12:13:09 +02:00
|
|
|
// FIXME: should be in rwengine, deeply hidden
|
2017-11-01 03:13:07 +01:00
|
|
|
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
2018-08-30 17:37:27 +02:00
|
|
|
#ifdef _MSC_VER
|
2018-12-12 13:53:32 +01:00
|
|
|
#pragma warning(default : 4305)
|
2018-08-30 17:37:27 +02:00
|
|
|
#endif
|
2017-11-01 03:13:07 +01:00
|
|
|
|
2015-04-18 02:11:17 +02:00
|
|
|
#include <engine/GameData.hpp>
|
2016-10-20 01:01:18 +02:00
|
|
|
#include <engine/GameState.hpp>
|
2014-09-16 20:22:43 +02:00
|
|
|
#include <engine/GameWorld.hpp>
|
2016-10-16 21:37:07 +02:00
|
|
|
#include <render/DebugDraw.hpp>
|
2016-10-20 01:01:18 +02:00
|
|
|
#include <render/GameRenderer.hpp>
|
2018-08-25 17:51:48 +02:00
|
|
|
#include <script/SCMFile.hpp>
|
2015-04-04 04:12:28 +02:00
|
|
|
#include <script/ScriptMachine.hpp>
|
2016-10-21 00:10:52 +02:00
|
|
|
#include <script/modules/GTA3Module.hpp>
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
#include <chrono>
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2015-05-03 06:22:03 +02:00
|
|
|
class PlayerController;
|
2015-04-19 22:38:01 +02:00
|
|
|
|
2018-07-07 22:55:10 +02:00
|
|
|
class RWGame final : public GameBase {
|
2016-10-16 21:37:07 +02:00
|
|
|
GameData data;
|
|
|
|
GameRenderer renderer;
|
|
|
|
DebugDraw debug;
|
2016-10-20 01:01:18 +02:00
|
|
|
GameState state;
|
2018-10-29 16:54:13 +01:00
|
|
|
HUDDrawer hudDrawer{};
|
2016-10-16 21:37:07 +02:00
|
|
|
|
2016-10-20 01:49:15 +02:00
|
|
|
std::unique_ptr<GameWorld> world;
|
2016-10-21 00:10:52 +02:00
|
|
|
|
|
|
|
GTA3Module opcodes;
|
|
|
|
std::unique_ptr<ScriptMachine> vm;
|
2018-08-25 17:51:48 +02:00
|
|
|
SCMFile script;
|
2016-10-21 00:10:52 +02:00
|
|
|
|
2018-12-18 22:43:49 +01:00
|
|
|
StateManager stateManager;
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
bool inFocus = true;
|
2016-11-30 00:28:53 +01:00
|
|
|
ViewCamera currentCam;
|
2016-10-12 01:29:24 +02:00
|
|
|
|
|
|
|
enum class DebugViewMode {
|
|
|
|
Disabled,
|
|
|
|
General,
|
|
|
|
Physics,
|
|
|
|
Navigation,
|
|
|
|
Objects
|
|
|
|
};
|
|
|
|
|
|
|
|
DebugViewMode debugview_ = DebugViewMode::Disabled;
|
2018-05-19 23:55:27 +02:00
|
|
|
int lastDraws{0}; /// Number of draws issued for the last frame.
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
std::string cheatInputWindow = std::string(32, ' ');
|
|
|
|
|
|
|
|
public:
|
2018-12-12 18:51:04 +01:00
|
|
|
RWGame(Logger& log, const std::optional<RWArgConfigLayer> &args);
|
2018-01-01 04:21:58 +01:00
|
|
|
~RWGame() override;
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
int run();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initalizes a new game
|
|
|
|
*/
|
|
|
|
void newGame();
|
|
|
|
|
2018-12-18 22:43:49 +01:00
|
|
|
StateManager& getStateManager() {
|
|
|
|
return stateManager;
|
|
|
|
}
|
|
|
|
|
2016-10-20 01:01:18 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-16 21:37:07 +02:00
|
|
|
const GameData& getGameData() const {
|
2016-09-09 22:13:20 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2016-10-16 21:37:07 +02:00
|
|
|
GameRenderer& getRenderer() {
|
2016-09-09 22:13:20 +02:00
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:13:09 +02:00
|
|
|
ScriptMachine* getScriptVM() const {
|
2016-10-21 00:10:52 +02:00
|
|
|
return vm.get();
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-29 14:52:18 +01:00
|
|
|
HUDDrawer& getHUDDrawer() {
|
|
|
|
return hudDrawer;
|
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal,
|
|
|
|
GameObject** object = nullptr) {
|
2016-11-30 00:28:53 +01:00
|
|
|
auto vc = currentCam;
|
2016-09-09 22:13:20 +02:00
|
|
|
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);
|
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
private:
|
2016-09-09 22:13:20 +02:00
|
|
|
void tick(float dt);
|
|
|
|
void render(float alpha, float dt);
|
|
|
|
|
2016-10-12 01:36:05 +02:00
|
|
|
void renderDebugStats(float time);
|
2016-09-09 22:13:20 +02:00
|
|
|
void renderDebugPaths(float time);
|
2016-10-12 03:12:15 +02:00
|
|
|
void renderDebugObjects(float time, ViewCamera& camera);
|
2014-09-16 20:22:43 +02:00
|
|
|
|
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);
|
2018-08-28 20:35:49 +02:00
|
|
|
|
|
|
|
bool updateInput();
|
|
|
|
|
|
|
|
float tickWorld(const float deltaTime, float accumulatedTime);
|
|
|
|
|
|
|
|
void renderDebugView(float time, ViewCamera &viewCam);
|
2018-08-31 21:01:50 +02:00
|
|
|
|
|
|
|
void tickObjects(float dt) const;
|
2014-09-16 20:22:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|