mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 15:02:34 +02:00
Refactor: moved getPlayer to World class
This commit is contained in:
parent
4a9444fdee
commit
ca576ac3cf
@ -1022,4 +1022,13 @@ void GameWorld::clearObjectsWithinArea(const glm::vec3 center,
|
|||||||
|
|
||||||
// @todo Remove all temp objects, extinguish all fires, remove all
|
// @todo Remove all temp objects, extinguish all fires, remove all
|
||||||
// explosions, remove all projectiles
|
// explosions, remove all projectiles
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerController* GameWorld::getPlayer() {
|
||||||
|
auto object = pedestrianPool.find(state->playerObject);
|
||||||
|
if (object) {
|
||||||
|
auto controller = static_cast<CharacterObject*>(object)->controller;
|
||||||
|
return static_cast<PlayerController*>(controller);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
@ -363,6 +363,8 @@ public:
|
|||||||
void clearObjectsWithinArea(const glm::vec3 center, const float radius,
|
void clearObjectsWithinArea(const glm::vec3 center, const float radius,
|
||||||
const bool clearParticles);
|
const bool clearParticles);
|
||||||
|
|
||||||
|
PlayerController* getPlayer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Used by objects to delete themselves during updates.
|
* @brief Used by objects to delete themselves during updates.
|
||||||
|
@ -12,11 +12,9 @@
|
|||||||
#include "script/ScriptModule.hpp"
|
#include "script/ScriptModule.hpp"
|
||||||
|
|
||||||
void ScriptMachine::executeThread(SCMThread& t, int msPassed) {
|
void ScriptMachine::executeThread(SCMThread& t, int msPassed) {
|
||||||
auto& players = getState()->world->players;
|
auto player = state->world->getPlayer();
|
||||||
|
|
||||||
if (!players.empty()) {
|
if (player) {
|
||||||
// @todo Add support for multiple players
|
|
||||||
PlayerController* player = players.at(0);
|
|
||||||
if (t.isMission && t.deathOrArrestCheck &&
|
if (t.isMission && t.deathOrArrestCheck &&
|
||||||
(player->isWasted() || player->isBusted())) {
|
(player->isWasted() || player->isBusted())) {
|
||||||
t.wastedOrBusted = true;
|
t.wastedOrBusted = true;
|
||||||
|
@ -6743,8 +6743,7 @@ void opcode_0254(const ScriptArguments& args) {
|
|||||||
void opcode_0255(const ScriptArguments& args, ScriptVec3 coord, const ScriptFloat heading) {
|
void opcode_0255(const ScriptArguments& args, ScriptVec3 coord, const ScriptFloat heading) {
|
||||||
coord = script::getGround(args, coord);
|
coord = script::getGround(args, coord);
|
||||||
args.getState()->overrideRestart(glm::vec4(coord, heading));
|
args.getState()->overrideRestart(glm::vec4(coord, heading));
|
||||||
// @todo Add support for multiple players
|
auto player = args.getWorld()->getPlayer();
|
||||||
PlayerController* player = args.getState()->world->players.at(0);
|
|
||||||
player->requestMissionRestart();
|
player->requestMissionRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8180,6 +8179,7 @@ void opcode_02fa(const ScriptArguments& args, const ScriptGarage garage0, const
|
|||||||
*/
|
*/
|
||||||
void opcode_02fb(const ScriptArguments& args, const ScriptFloat arg1, const ScriptFloat arg2, const ScriptFloat arg3, const ScriptFloat arg4, const ScriptFloat arg5, const ScriptFloat arg6, const ScriptFloat arg7, const ScriptFloat arg8, const ScriptFloat arg9, const ScriptFloat arg10) {
|
void opcode_02fb(const ScriptArguments& args, const ScriptFloat arg1, const ScriptFloat arg2, const ScriptFloat arg3, const ScriptFloat arg4, const ScriptFloat arg5, const ScriptFloat arg6, const ScriptFloat arg7, const ScriptFloat arg8, const ScriptFloat arg9, const ScriptFloat arg10) {
|
||||||
RW_UNIMPLEMENTED_OPCODE(0x02fb);
|
RW_UNIMPLEMENTED_OPCODE(0x02fb);
|
||||||
|
RW_UNUSED(args);
|
||||||
RW_UNUSED(arg1);
|
RW_UNUSED(arg1);
|
||||||
RW_UNUSED(arg2);
|
RW_UNUSED(arg2);
|
||||||
RW_UNUSED(arg3);
|
RW_UNUSED(arg3);
|
||||||
|
@ -160,15 +160,6 @@ void RWGame::startScript(const std::string& name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController* RWGame::getPlayer() {
|
|
||||||
auto object = world->pedestrianPool.find(state.playerObject);
|
|
||||||
if (object) {
|
|
||||||
auto controller = static_cast<CharacterObject*>(object)->controller;
|
|
||||||
return static_cast<PlayerController*>(controller);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifiers for GTA3 we try to recreate
|
// Modifiers for GTA3 we try to recreate
|
||||||
#define RW_GAME_VERSION 1100
|
#define RW_GAME_VERSION 1100
|
||||||
#define RW_GAME_GTA3_GERMAN 0
|
#define RW_GAME_GTA3_GERMAN 0
|
||||||
@ -192,7 +183,7 @@ void RWGame::handleCheatInput(char symbol) {
|
|||||||
|
|
||||||
// Player related cheats
|
// Player related cheats
|
||||||
{
|
{
|
||||||
auto player = getPlayer()->getCharacter();
|
auto player = getWorld()->getPlayer()->getCharacter();
|
||||||
|
|
||||||
#ifdef RW_GAME_GTA3_GERMAN // Germans got their own cheat
|
#ifdef RW_GAME_GTA3_GERMAN // Germans got their own cheat
|
||||||
std::string health_cheat = "GESUNDHEIT";
|
std::string health_cheat = "GESUNDHEIT";
|
||||||
@ -893,7 +884,7 @@ void RWGame::globalKeyEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string keyName = SDL_GetKeyName(event.key.keysym.sym);
|
std::string keyName = SDL_GetKeyName(event.key.keysym.sym);
|
||||||
if (getPlayer() && keyName.length() == 1) {
|
if (getWorld()->getPlayer() && keyName.length() == 1) {
|
||||||
char symbol = keyName[0];
|
char symbol = keyName[0];
|
||||||
handleCheatInput(symbol);
|
handleCheatInput(symbol);
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,6 @@ public:
|
|||||||
void saveGame(const std::string& savename);
|
void saveGame(const std::string& savename);
|
||||||
void loadGame(const std::string& savename);
|
void loadGame(const std::string& savename);
|
||||||
|
|
||||||
/** shortcut for getWorld()->state.player->getCharacter() */
|
|
||||||
PlayerController* getPlayer();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tick(float dt);
|
void tick(float dt);
|
||||||
void render(float alpha, float dt);
|
void render(float alpha, float dt);
|
||||||
|
@ -35,8 +35,8 @@ static void jumpCharacter(RWGame* game, CharacterObject* player,
|
|||||||
|
|
||||||
std::shared_ptr<Menu> DebugState::createDebugMenu() {
|
std::shared_ptr<Menu> DebugState::createDebugMenu() {
|
||||||
CharacterObject* player = nullptr;
|
CharacterObject* player = nullptr;
|
||||||
if (game->getPlayer()) {
|
if (game->getWorld()->getPlayer()) {
|
||||||
player = game->getPlayer()->getCharacter();
|
player = game->getWorld()->getPlayer()->getCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto menu = Menu::create(
|
auto menu = Menu::create(
|
||||||
@ -78,8 +78,8 @@ std::shared_ptr<Menu> DebugState::createDebugMenu() {
|
|||||||
|
|
||||||
std::shared_ptr<Menu> DebugState::createMapMenu() {
|
std::shared_ptr<Menu> DebugState::createMapMenu() {
|
||||||
CharacterObject* player = nullptr;
|
CharacterObject* player = nullptr;
|
||||||
if (game->getPlayer()) {
|
if (game->getWorld()->getPlayer()) {
|
||||||
player = game->getPlayer()->getCharacter();
|
player = game->getWorld()->getPlayer()->getCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto menu = Menu::create(
|
auto menu = Menu::create(
|
||||||
@ -468,7 +468,7 @@ void DebugState::printCameraDetails() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DebugState::spawnVehicle(unsigned int id) {
|
void DebugState::spawnVehicle(unsigned int id) {
|
||||||
auto ch = game->getPlayer()->getCharacter();
|
auto ch = game->getWorld()->getPlayer()->getCharacter();
|
||||||
if (!ch) return;
|
if (!ch) return;
|
||||||
|
|
||||||
auto playerRot = ch->getRotation();
|
auto playerRot = ch->getRotation();
|
||||||
@ -480,7 +480,7 @@ void DebugState::spawnVehicle(unsigned int id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DebugState::spawnFollower(unsigned int id) {
|
void DebugState::spawnFollower(unsigned int id) {
|
||||||
auto ch = game->getPlayer()->getCharacter();
|
auto ch = game->getWorld()->getPlayer()->getCharacter();
|
||||||
if (!ch) return;
|
if (!ch) return;
|
||||||
|
|
||||||
glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f);
|
glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f);
|
||||||
@ -498,8 +498,8 @@ void DebugState::spawnFollower(unsigned int id) {
|
|||||||
|
|
||||||
void DebugState::giveItem(int slot) {
|
void DebugState::giveItem(int slot) {
|
||||||
CharacterObject* player = nullptr;
|
CharacterObject* player = nullptr;
|
||||||
if (game->getPlayer()) {
|
if (game->getWorld()->getPlayer()) {
|
||||||
player = game->getPlayer()->getCharacter();
|
player = game->getWorld()->getPlayer()->getCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player) {
|
if (player) {
|
||||||
|
@ -166,7 +166,7 @@ void IngameState::tick(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = game->getPlayer();
|
auto player = game->getWorld()->getPlayer();
|
||||||
|
|
||||||
if (player) {
|
if (player) {
|
||||||
// Force all input to 0 if player input is disabled
|
// Force all input to 0 if player input is disabled
|
||||||
@ -280,14 +280,14 @@ void IngameState::tick(float dt) {
|
|||||||
|
|
||||||
void IngameState::draw(GameRenderer* r) {
|
void IngameState::draw(GameRenderer* r) {
|
||||||
if (!getWorld()->state->isCinematic && getWorld()->isCutsceneDone()) {
|
if (!getWorld()->state->isCinematic && getWorld()->isCutsceneDone()) {
|
||||||
drawHUD(_look, game->getPlayer(), getWorld(), r);
|
drawHUD(_look, game->getWorld()->getPlayer(), getWorld(), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
State::draw(r);
|
State::draw(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IngameState::handleEvent(const SDL_Event& event) {
|
void IngameState::handleEvent(const SDL_Event& event) {
|
||||||
auto player = game->getPlayer();
|
auto player = game->getWorld()->getPlayer();
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
@ -323,7 +323,7 @@ void IngameState::handleEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IngameState::handlePlayerInput(const SDL_Event& event) {
|
void IngameState::handlePlayerInput(const SDL_Event& event) {
|
||||||
auto player = game->getPlayer();
|
auto player = game->getWorld()->getPlayer();
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
switch (event.button.button) {
|
switch (event.button.button) {
|
||||||
@ -373,7 +373,7 @@ bool IngameState::shouldWorldUpdate() {
|
|||||||
|
|
||||||
const ViewCamera& IngameState::getCamera(float alpha) {
|
const ViewCamera& IngameState::getCamera(float alpha) {
|
||||||
auto state = game->getState();
|
auto state = game->getState();
|
||||||
auto player = game->getPlayer();
|
auto player = game->getWorld()->getPlayer();
|
||||||
auto world = getWorld();
|
auto world = getWorld();
|
||||||
|
|
||||||
if (state->currentCutscene && state->cutsceneStartTime >= 0.f) {
|
if (state->currentCutscene && state->cutsceneStartTime >= 0.f) {
|
||||||
@ -508,8 +508,8 @@ GameObject* IngameState::getCameraTarget() const {
|
|||||||
auto target =
|
auto target =
|
||||||
getWorld()->pedestrianPool.find(game->getState()->cameraTarget);
|
getWorld()->pedestrianPool.find(game->getState()->cameraTarget);
|
||||||
|
|
||||||
if (target == nullptr && game->getPlayer()) {
|
if (target == nullptr && game->getWorld()->getPlayer()) {
|
||||||
target = game->getPlayer()->getCharacter();
|
target = game->getWorld()->getPlayer()->getCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the target is a character in a vehicle, make the vehicle the target
|
// If the target is a character in a vehicle, make the vehicle the target
|
||||||
|
Loading…
Reference in New Issue
Block a user