1
0
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:
Daniel Evans 2015-05-01 03:53:42 +01:00
parent 60cf899c1e
commit a7da8ea424
6 changed files with 16 additions and 12 deletions

View File

@ -6,6 +6,7 @@
#include <string>
#include <map>
#include <vector>
#include <objects/ObjectTypes.hpp>
class GameWorld;
class GameObject;
@ -110,6 +111,7 @@ struct GameState
unsigned int numRampages;
unsigned int maxWantedLevel;
PlayerController* player;
GameObjectID playerObject;
unsigned int currentWeather;
@ -119,7 +121,7 @@ struct GameState
unsigned int *scriptOnMissionFlag;
/** Objects created by the current mission */
std::vector<GameObject*> missionObjects;
std::vector<GameObjectID> missionObjects;
bool overrideNextStart;
glm::vec4 nextRestartLocation;
@ -164,8 +166,8 @@ struct GameState
bool cameraFixed;
glm::vec3 cameraPosition;
glm::quat cameraRotation;
GameObject* cameraTarget;
GameObjectID cameraTarget;
std::vector<VehicleGenerator> vehicleGenerators;

View File

@ -25,7 +25,7 @@ hour(0),
minute(0),
cameraNear(0.1f),
cameraFixed(false),
cameraTarget(nullptr),
cameraTarget(0),
world(nullptr)
{

View File

@ -145,13 +145,13 @@ void game_camera_follow_character(const ScriptArguments& args)
auto character = static_cast<CharacterObject*>(args.getGameObject(0));
if( character != nullptr )
{
args.getWorld()->state->cameraTarget = character;
args.getWorld()->state->cameraTarget = character->getGameObjectID();
}
}
void game_reset_camera(const ScriptArguments& args)
{
args.getWorld()->state->cameraTarget = nullptr;
args.getWorld()->state->cameraTarget = 0;
args.getWorld()->state->cameraFixed = false;
}

View File

@ -40,6 +40,7 @@ void game_create_player(const ScriptArguments& args)
auto pc = args.getWorld()->createPedestrian(1, position + spawnMagic);
args.getState()->player = new PlayerController(pc);
args.getState()->playerObject = pc->getGameObjectID();
*args[4].globalInteger = pc->getGameObjectID();
}
@ -110,7 +111,7 @@ void game_create_character(const ScriptArguments& args)
if ( args.getThread()->isMission )
{
args.getState()->missionObjects.push_back(character);
args.getState()->missionObjects.push_back(character->getGameObjectID());
}
*args[5].globalInteger = character->getGameObjectID();
@ -148,7 +149,7 @@ void game_create_vehicle(const ScriptArguments& args)
if ( args.getThread()->isMission )
{
args.getState()->missionObjects.push_back(vehicle);
args.getState()->missionObjects.push_back(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.
void game_dont_remove_object(const ScriptArguments& args)
{
auto object = args.getGameObject(0);
auto object = args.getGameObject(0)->getGameObjectID();
auto& mO = args.getState()->missionObjects;
mO.erase(std::remove(mO.begin(), mO.end(), object), mO.end());

View File

@ -159,9 +159,10 @@ void vm_new_mission_thread(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();

View File

@ -135,7 +135,7 @@ void IngameState::tick(float dt)
player->updateMovementDirection(angle * _movement, _movement);
auto target = getWorld()->state->cameraTarget;
auto target = getWorld()->findObject(getWorld()->state->cameraTarget);
if( target == nullptr )
{