2013-07-02 08:40:43 +02:00
|
|
|
#pragma once
|
2013-12-20 17:02:46 +01:00
|
|
|
#ifndef _GAMEWORLD_HPP_
|
|
|
|
#define _GAMEWORLD_HPP_
|
2013-07-02 08:40:43 +02:00
|
|
|
|
2015-03-30 03:45:58 +02:00
|
|
|
class Logger;
|
2015-03-05 04:37:13 +01:00
|
|
|
|
2013-12-20 17:02:46 +01:00
|
|
|
#include <engine/GameData.hpp>
|
2014-07-25 04:30:44 +02:00
|
|
|
#include <engine/GameState.hpp>
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
#include <ai/AIGraphNode.hpp>
|
2013-12-20 15:03:32 +01:00
|
|
|
#include <ai/AIGraph.hpp>
|
2015-02-04 18:16:46 +01:00
|
|
|
#include <audio/SoundManager.hpp>
|
2013-07-02 08:40:43 +02:00
|
|
|
|
2015-03-05 17:36:14 +01:00
|
|
|
class CutsceneObject;
|
2014-06-06 13:18:32 +02:00
|
|
|
class WorkContext;
|
|
|
|
|
2014-02-28 12:23:51 +01:00
|
|
|
class GameObject;
|
2014-06-06 16:22:26 +02:00
|
|
|
class CharacterObject;
|
|
|
|
class InstanceObject;
|
|
|
|
class VehicleObject;
|
2013-09-09 01:18:36 +02:00
|
|
|
|
2015-03-06 17:55:46 +01:00
|
|
|
#include <render/VisualFX.hpp>
|
|
|
|
|
2014-08-11 18:58:43 +02:00
|
|
|
struct WeaponScan;
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
2013-07-21 06:12:27 +02:00
|
|
|
#include <btBulletDynamicsCommon.h>
|
|
|
|
#include <btBulletCollisionCommon.h>
|
|
|
|
|
2013-07-02 08:40:43 +02:00
|
|
|
#include <vector>
|
2014-07-02 00:04:23 +02:00
|
|
|
#include <set>
|
2013-07-02 12:48:01 +02:00
|
|
|
#include <queue>
|
2013-07-04 01:23:12 +02:00
|
|
|
#include <random>
|
2015-04-06 05:06:35 +02:00
|
|
|
#include <array>
|
2013-07-02 08:40:43 +02:00
|
|
|
|
2015-01-23 18:18:16 +01:00
|
|
|
/**
|
|
|
|
* Information about "Goal" locations so they can be rendered
|
|
|
|
* (this doesn't really belong here).
|
|
|
|
*/
|
|
|
|
struct AreaIndicatorInfo
|
|
|
|
{
|
|
|
|
enum AreaIndicatorType
|
|
|
|
{
|
|
|
|
Cylinder
|
|
|
|
};
|
|
|
|
|
|
|
|
AreaIndicatorType type;
|
|
|
|
glm::vec3 position;
|
|
|
|
glm::vec3 radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
/**
|
2014-07-09 06:04:48 +02:00
|
|
|
* @brief Handles all data relating to object instances and other "worldly" state.
|
2013-07-02 08:06:03 +02:00
|
|
|
*/
|
2013-12-20 17:02:46 +01:00
|
|
|
class GameWorld
|
2013-07-02 08:06:03 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-07-22 05:39:58 +02:00
|
|
|
|
2015-03-30 03:45:58 +02:00
|
|
|
GameWorld(Logger* log, const std::string& gamepath);
|
2014-06-06 13:18:32 +02:00
|
|
|
|
|
|
|
~GameWorld();
|
2015-03-30 03:03:38 +02:00
|
|
|
|
2015-03-30 03:45:58 +02:00
|
|
|
Logger* logger;
|
2015-03-30 03:03:38 +02:00
|
|
|
|
2013-07-02 14:49:20 +02:00
|
|
|
/**
|
|
|
|
* Loads an IDE into the game
|
|
|
|
*/
|
|
|
|
bool defineItems(const std::string& name);
|
2014-07-24 00:57:21 +02:00
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
/**
|
|
|
|
* Loads an IPL into the game.
|
|
|
|
* @param name The name of the IPL as it appears in the games' gta.dat
|
|
|
|
*/
|
2013-07-02 14:49:20 +02:00
|
|
|
bool placeItems(const std::string& name);
|
2013-07-02 08:06:03 +02:00
|
|
|
|
2015-02-18 16:29:39 +01:00
|
|
|
void createTraffic(const glm::vec3& near);
|
2015-02-18 17:00:55 +01:00
|
|
|
void cleanupTraffic(const glm::vec3& focus);
|
2015-02-18 16:29:39 +01:00
|
|
|
|
2013-09-30 00:12:03 +02:00
|
|
|
/**
|
|
|
|
* Creates an instance
|
|
|
|
*/
|
2014-06-06 16:22:26 +02:00
|
|
|
InstanceObject *createInstance(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
2014-08-01 16:00:36 +02:00
|
|
|
uint16_t findModelDefinition(const std::string model);
|
2014-07-30 14:44:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creates an InstanceObject for use in the current Cutscene.
|
|
|
|
*/
|
|
|
|
CutsceneObject *createCutsceneObject(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
2013-09-30 00:12:03 +02:00
|
|
|
|
2013-07-02 19:37:19 +02:00
|
|
|
/**
|
|
|
|
* Creates a vehicle
|
|
|
|
*/
|
2014-06-06 16:22:26 +02:00
|
|
|
VehicleObject *createVehicle(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
2013-07-22 05:39:58 +02:00
|
|
|
|
2014-07-30 14:44:25 +02:00
|
|
|
/**
|
|
|
|
* Creates a pedestrian.
|
|
|
|
*/
|
2014-06-06 16:22:26 +02:00
|
|
|
CharacterObject* createPedestrian(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
2013-07-02 19:37:19 +02:00
|
|
|
|
2013-12-12 03:55:31 +01:00
|
|
|
/**
|
|
|
|
* Destroys an existing Object
|
|
|
|
*/
|
2014-02-28 12:23:51 +01:00
|
|
|
void destroyObject(GameObject* object);
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2014-07-20 22:21:51 +02:00
|
|
|
/**
|
|
|
|
* @brief Put an object on the deletion queue.
|
|
|
|
*/
|
|
|
|
void destroyObjectQueued(GameObject* object);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Destroys all objects on the destruction queue.
|
|
|
|
*/
|
|
|
|
void destroyQueuedObjects();
|
|
|
|
|
2014-06-28 04:22:53 +02:00
|
|
|
/**
|
|
|
|
* Performs a weapon scan against things in the world
|
|
|
|
*/
|
2014-06-30 02:56:45 +02:00
|
|
|
void doWeaponScan(const WeaponScan &scan );
|
2015-03-06 17:55:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new VisualFX of the given type
|
|
|
|
*/
|
|
|
|
VisualFX* createEffect(VisualFX::EffectType type);
|
2013-12-12 03:55:31 +01:00
|
|
|
|
2015-03-06 17:55:46 +01:00
|
|
|
/**
|
|
|
|
* Immediately destoys the given effect
|
|
|
|
*/
|
|
|
|
void destroyEffect(VisualFX* effect);
|
|
|
|
|
2013-12-27 23:57:11 +01:00
|
|
|
/**
|
|
|
|
* Returns the current hour
|
|
|
|
*/
|
2014-07-27 01:38:01 +02:00
|
|
|
int getHour();
|
2013-12-27 23:57:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current minute
|
|
|
|
*/
|
|
|
|
int getMinute();
|
2014-07-27 01:38:01 +02:00
|
|
|
|
|
|
|
glm::vec3 getGroundAtPosition(const glm::vec3& pos) const;
|
2013-12-27 23:57:11 +01:00
|
|
|
|
2013-07-02 12:48:01 +02:00
|
|
|
/**
|
|
|
|
* Game Clock
|
|
|
|
*/
|
|
|
|
float gameTime;
|
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
/**
|
|
|
|
* Game data
|
|
|
|
*/
|
2013-12-20 17:02:46 +01:00
|
|
|
GameData gameData;
|
2014-07-25 04:30:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gameplay state
|
|
|
|
*/
|
|
|
|
GameState state;
|
2013-07-02 09:53:23 +02:00
|
|
|
|
2015-02-04 18:16:46 +01:00
|
|
|
/**
|
|
|
|
* State of playing sounds
|
|
|
|
*/
|
|
|
|
SoundManager sound;
|
|
|
|
|
2013-07-02 08:06:03 +02:00
|
|
|
/**
|
2013-07-02 14:49:20 +02:00
|
|
|
* Object Definitions
|
2013-07-02 08:06:03 +02:00
|
|
|
*/
|
2014-09-17 04:13:02 +02:00
|
|
|
std::map<ObjectID, ObjectInformationPtr> objectTypes;
|
|
|
|
|
|
|
|
template<class T> std::shared_ptr<T> findObjectType(ObjectID id)
|
|
|
|
{
|
|
|
|
auto f = objectTypes.find(id);
|
|
|
|
/// @TODO don't instanciate an object here just to read .type
|
|
|
|
T tmp;
|
|
|
|
if( f != objectTypes.end() && f->second->class_type == tmp.class_type )
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<T>(f->second);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-26 17:14:13 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-09 06:04:48 +02:00
|
|
|
* Paths associated with each object definition.
|
|
|
|
*/
|
2013-11-26 17:14:13 +01:00
|
|
|
std::map<uint16_t, std::vector<std::shared_ptr<PathData>>> objectNodes;
|
|
|
|
|
2013-07-02 14:49:20 +02:00
|
|
|
/**
|
2014-07-02 00:04:23 +02:00
|
|
|
* @brief objects All active GameObjects in the world.
|
2014-07-09 06:04:48 +02:00
|
|
|
* @todo add some mechanism to allow objects to be "locked" preventing deletion.
|
|
|
|
* @todo add deletion queue to allow objects to self delete.
|
2013-07-02 14:49:20 +02:00
|
|
|
*/
|
2014-07-02 00:04:23 +02:00
|
|
|
std::set<GameObject*> objects;
|
|
|
|
|
2015-04-05 19:45:03 +02:00
|
|
|
std::set<GameObject*> characters;
|
|
|
|
|
2015-04-06 05:06:35 +02:00
|
|
|
/**
|
|
|
|
* Stores objects within a grid cell, and their maximum
|
|
|
|
* bounding radius
|
|
|
|
*/
|
|
|
|
struct GridCell
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Static instances within this grid cell
|
|
|
|
*/
|
|
|
|
std::set<GameObject*> instances;
|
|
|
|
float boundingRadius = 0.f;
|
|
|
|
};
|
|
|
|
std::array<GridCell, WORLD_GRID_CELLS> worldGrid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns true if the given object should be stored
|
|
|
|
* within the grid
|
|
|
|
*/
|
|
|
|
bool shouldBeOnGrid(GameObject* object);
|
|
|
|
void addToGrid(GameObject* object);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the grid coordinates for a world coordinates
|
|
|
|
*/
|
|
|
|
glm::ivec2 worldToGrid(const glm::vec2& world);
|
|
|
|
|
2013-08-16 01:05:41 +02:00
|
|
|
/**
|
|
|
|
* Map of Model Names to Instances
|
|
|
|
*/
|
2014-07-02 00:04:23 +02:00
|
|
|
std::map<std::string, InstanceObject*> modelInstances;
|
2013-07-02 14:49:20 +02:00
|
|
|
|
2013-09-21 04:27:33 +02:00
|
|
|
/**
|
|
|
|
* AI Graph
|
|
|
|
*/
|
|
|
|
AIGraph aigraph;
|
2015-03-06 17:55:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Visual Effects
|
|
|
|
* @todo Consider using lighter handing mechanism
|
|
|
|
*/
|
|
|
|
std::vector<VisualFX*> effects;
|
2013-07-30 17:59:44 +02:00
|
|
|
|
2013-07-04 01:23:12 +02:00
|
|
|
/**
|
|
|
|
* Randomness Engine
|
|
|
|
*/
|
|
|
|
std::default_random_engine randomEngine;
|
2013-07-21 06:12:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bullet
|
|
|
|
*/
|
|
|
|
btDefaultCollisionConfiguration* collisionConfig;
|
|
|
|
btCollisionDispatcher* collisionDispatcher;
|
|
|
|
btBroadphaseInterface* broadphase;
|
|
|
|
btSequentialImpulseConstraintSolver* solver;
|
|
|
|
btDiscreteDynamicsWorld* dynamicsWorld;
|
2014-06-06 13:18:32 +02:00
|
|
|
|
2014-06-11 22:00:53 +02:00
|
|
|
/**
|
2014-06-16 02:29:36 +02:00
|
|
|
* @brief physicsNearCallback
|
|
|
|
* Used to implement uprooting and other physics oddities.
|
2014-06-11 22:00:53 +02:00
|
|
|
*/
|
2014-06-16 02:29:36 +02:00
|
|
|
static bool ContactProcessedCallback(btManifoldPoint& mp, void* body0, void* body1);
|
2014-07-09 06:04:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief PhysicsTickCallback updates object each physics tick.
|
|
|
|
* @param physWorld
|
|
|
|
* @param timeStep
|
|
|
|
*/
|
2014-06-19 00:05:59 +02:00
|
|
|
static void PhysicsTickCallback(btDynamicsWorld* physWorld, btScalar timeStep);
|
2014-06-11 22:00:53 +02:00
|
|
|
|
2014-06-06 13:18:32 +02:00
|
|
|
/**
|
|
|
|
* Work related
|
|
|
|
*/
|
|
|
|
WorkContext* _work;
|
2014-07-20 22:21:51 +02:00
|
|
|
|
2014-07-28 03:27:55 +02:00
|
|
|
/**
|
|
|
|
* @brief Loads and starts the named cutscene.
|
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
void loadCutscene(const std::string& name);
|
2014-08-01 22:04:58 +02:00
|
|
|
void startCutscene();
|
2014-07-30 14:44:25 +02:00
|
|
|
void clearCutscene();
|
2015-01-25 19:42:29 +01:00
|
|
|
bool isCutsceneDone();
|
2014-07-30 14:44:25 +02:00
|
|
|
|
2015-01-26 15:40:09 +01:00
|
|
|
sf::SoundStream* cutsceneAudio;
|
2014-08-03 18:50:40 +02:00
|
|
|
bool cutsceneAudioLoaded;
|
2015-01-27 14:09:16 +01:00
|
|
|
sf::SoundBuffer* missionAudio;
|
2014-12-17 01:39:52 +01:00
|
|
|
sf::Sound missionSound;
|
2014-08-01 22:04:58 +02:00
|
|
|
|
2014-07-30 14:44:25 +02:00
|
|
|
/**
|
|
|
|
* @brief loads a model into a special character slot.
|
|
|
|
*/
|
|
|
|
void loadSpecialCharacter(const unsigned short index, const std::string& name);
|
|
|
|
void loadSpecialModel(const unsigned short index, const std::string& name);
|
2014-12-16 00:13:33 +01:00
|
|
|
|
|
|
|
void disableAIPaths(AIGraphNode::NodeType type, const glm::vec3& min, const glm::vec3& max);
|
|
|
|
void enableAIPaths(AIGraphNode::NodeType type, const glm::vec3& min, const glm::vec3& max);
|
2015-01-23 18:18:16 +01:00
|
|
|
|
|
|
|
void drawAreaIndicator(AreaIndicatorInfo::AreaIndicatorType type, glm::vec3 position, glm::vec3 radius);
|
|
|
|
|
|
|
|
const std::vector<AreaIndicatorInfo>& getAreaIndicators() const { return areaIndicators; }
|
|
|
|
|
|
|
|
void clearTickData();
|
2015-02-04 18:16:46 +01:00
|
|
|
|
|
|
|
void setPaused(bool pause);
|
|
|
|
bool isPaused() const;
|
2014-07-30 14:55:39 +02:00
|
|
|
|
2014-07-20 22:21:51 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Used by objects to delete themselves during updates.
|
|
|
|
*/
|
|
|
|
std::queue<GameObject*> deletionQueue;
|
2015-01-23 18:18:16 +01:00
|
|
|
|
|
|
|
std::vector<AreaIndicatorInfo> areaIndicators;
|
2015-02-04 18:16:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag for pausing the simulation
|
|
|
|
*/
|
|
|
|
bool paused;
|
2013-07-02 08:06:03 +02:00
|
|
|
};
|
|
|
|
|
2013-07-22 05:39:58 +02:00
|
|
|
#endif
|