mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
Remove raw GameObject pointer usage in GameState
This commit is contained in:
parent
60cf899c1e
commit
a7da8ea424
@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <objects/ObjectTypes.hpp>
|
||||||
|
|
||||||
class GameWorld;
|
class GameWorld;
|
||||||
class GameObject;
|
class GameObject;
|
||||||
@ -110,6 +111,7 @@ struct GameState
|
|||||||
unsigned int numRampages;
|
unsigned int numRampages;
|
||||||
unsigned int maxWantedLevel;
|
unsigned int maxWantedLevel;
|
||||||
PlayerController* player;
|
PlayerController* player;
|
||||||
|
GameObjectID playerObject;
|
||||||
|
|
||||||
unsigned int currentWeather;
|
unsigned int currentWeather;
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ struct GameState
|
|||||||
unsigned int *scriptOnMissionFlag;
|
unsigned int *scriptOnMissionFlag;
|
||||||
|
|
||||||
/** Objects created by the current mission */
|
/** Objects created by the current mission */
|
||||||
std::vector<GameObject*> missionObjects;
|
std::vector<GameObjectID> missionObjects;
|
||||||
|
|
||||||
bool overrideNextStart;
|
bool overrideNextStart;
|
||||||
glm::vec4 nextRestartLocation;
|
glm::vec4 nextRestartLocation;
|
||||||
@ -164,8 +166,8 @@ struct GameState
|
|||||||
bool cameraFixed;
|
bool cameraFixed;
|
||||||
glm::vec3 cameraPosition;
|
glm::vec3 cameraPosition;
|
||||||
glm::quat cameraRotation;
|
glm::quat cameraRotation;
|
||||||
|
|
||||||
GameObject* cameraTarget;
|
GameObjectID cameraTarget;
|
||||||
|
|
||||||
std::vector<VehicleGenerator> vehicleGenerators;
|
std::vector<VehicleGenerator> vehicleGenerators;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ hour(0),
|
|||||||
minute(0),
|
minute(0),
|
||||||
cameraNear(0.1f),
|
cameraNear(0.1f),
|
||||||
cameraFixed(false),
|
cameraFixed(false),
|
||||||
cameraTarget(nullptr),
|
cameraTarget(0),
|
||||||
world(nullptr)
|
world(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -145,13 +145,13 @@ void game_camera_follow_character(const ScriptArguments& args)
|
|||||||
auto character = static_cast<CharacterObject*>(args.getGameObject(0));
|
auto character = static_cast<CharacterObject*>(args.getGameObject(0));
|
||||||
if( character != nullptr )
|
if( character != nullptr )
|
||||||
{
|
{
|
||||||
args.getWorld()->state->cameraTarget = character;
|
args.getWorld()->state->cameraTarget = character->getGameObjectID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_reset_camera(const ScriptArguments& args)
|
void game_reset_camera(const ScriptArguments& args)
|
||||||
{
|
{
|
||||||
args.getWorld()->state->cameraTarget = nullptr;
|
args.getWorld()->state->cameraTarget = 0;
|
||||||
args.getWorld()->state->cameraFixed = false;
|
args.getWorld()->state->cameraFixed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ void game_create_player(const ScriptArguments& args)
|
|||||||
|
|
||||||
auto pc = args.getWorld()->createPedestrian(1, position + spawnMagic);
|
auto pc = args.getWorld()->createPedestrian(1, position + spawnMagic);
|
||||||
args.getState()->player = new PlayerController(pc);
|
args.getState()->player = new PlayerController(pc);
|
||||||
|
args.getState()->playerObject = pc->getGameObjectID();
|
||||||
|
|
||||||
*args[4].globalInteger = pc->getGameObjectID();
|
*args[4].globalInteger = pc->getGameObjectID();
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ void game_create_character(const ScriptArguments& args)
|
|||||||
|
|
||||||
if ( args.getThread()->isMission )
|
if ( args.getThread()->isMission )
|
||||||
{
|
{
|
||||||
args.getState()->missionObjects.push_back(character);
|
args.getState()->missionObjects.push_back(character->getGameObjectID());
|
||||||
}
|
}
|
||||||
|
|
||||||
*args[5].globalInteger = character->getGameObjectID();
|
*args[5].globalInteger = character->getGameObjectID();
|
||||||
@ -148,7 +149,7 @@ void game_create_vehicle(const ScriptArguments& args)
|
|||||||
|
|
||||||
if ( args.getThread()->isMission )
|
if ( args.getThread()->isMission )
|
||||||
{
|
{
|
||||||
args.getState()->missionObjects.push_back(vehicle);
|
args.getState()->missionObjects.push_back(vehicle->getGameObjectID());
|
||||||
}
|
}
|
||||||
|
|
||||||
*args[4].globalInteger = vehicle->getGameObjectID();
|
*args[4].globalInteger = vehicle->getGameObjectID();
|
||||||
@ -431,7 +432,7 @@ bool game_vehicle_stopped(const ScriptArguments& args)
|
|||||||
/// Remove object from cleanup at end of missions.
|
/// Remove object from cleanup at end of missions.
|
||||||
void game_dont_remove_object(const ScriptArguments& args)
|
void game_dont_remove_object(const ScriptArguments& args)
|
||||||
{
|
{
|
||||||
auto object = args.getGameObject(0);
|
auto object = args.getGameObject(0)->getGameObjectID();
|
||||||
|
|
||||||
auto& mO = args.getState()->missionObjects;
|
auto& mO = args.getState()->missionObjects;
|
||||||
mO.erase(std::remove(mO.begin(), mO.end(), object), mO.end());
|
mO.erase(std::remove(mO.begin(), mO.end(), object), mO.end());
|
||||||
|
@ -159,9 +159,10 @@ void vm_new_mission_thread(const ScriptArguments& args)
|
|||||||
|
|
||||||
void vm_mission_over(const ScriptArguments& args)
|
void vm_mission_over(const ScriptArguments& args)
|
||||||
{
|
{
|
||||||
for( auto& o : args.getState()->missionObjects )
|
for( auto oid : args.getState()->missionObjects )
|
||||||
{
|
{
|
||||||
args.getWorld()->destroyObjectQueued(o);
|
auto obj = args.getWorld()->objects[oid];
|
||||||
|
args.getWorld()->destroyObjectQueued(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.getState()->missionObjects.clear();
|
args.getState()->missionObjects.clear();
|
||||||
|
@ -135,7 +135,7 @@ void IngameState::tick(float dt)
|
|||||||
|
|
||||||
player->updateMovementDirection(angle * _movement, _movement);
|
player->updateMovementDirection(angle * _movement, _movement);
|
||||||
|
|
||||||
auto target = getWorld()->state->cameraTarget;
|
auto target = getWorld()->findObject(getWorld()->state->cameraTarget);
|
||||||
|
|
||||||
if( target == nullptr )
|
if( target == nullptr )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user