From 926106cf8c072c5fb5d0c6985a98b807d6e733ff Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 13 Nov 2017 05:33:27 +0200 Subject: [PATCH] [General] Rework CharGen slightly for clarity purposes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, charGenStage.end was doing double duty as both the variable indicating the number of CharGen stages and – when set to 0 – the variable indicating that CharGen was over. The latter role is now filled by a new boolean. --- apps/openmw-mp/Player.cpp | 9 ++--- apps/openmw-mp/Player.hpp | 2 +- .../player/ProcessorPlayerCharGen.hpp | 2 +- apps/openmw/mwmp/LocalPlayer.cpp | 33 +++++++++---------- apps/openmw/mwmp/LocalPlayer.hpp | 3 +- apps/openmw/mwmp/Main.cpp | 3 +- components/openmw-mp/Base/BasePlayer.hpp | 7 ++-- .../Packets/Player/PacketPlayerCharGen.cpp | 2 +- 8 files changed, 29 insertions(+), 32 deletions(-) diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index b24ee43c3..6c47dc882 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -44,7 +44,7 @@ void Player::Init(LuaState &lua) "guid", sol::readonly_property(&Player::getGUID), "name", sol::property(&Player::getName, &Player::setName), - "setCharGenStage", &Player::setCharGenStage, + "setCharGenStages", &Player::setCharGenStages, "isMale", &Player::isMale, "setIsMake", &Player::setIsMale, "level", sol::property(&Player::getLevel, &Player::setLevel), @@ -314,10 +314,11 @@ std::string Player::getName() return npc.mName; } -void Player::setCharGenStage(int start, int end) +void Player::setCharGenStages(int currentStage, int endStage) { - charGenStage.current = start; - charGenStage.end = end; + charGenState.currentStage = currentStage; + charGenState.endStage = endStage; + charGenState.isFinished = false; auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN); packet->setPlayer(this); diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index 6c4c04048..91c33f098 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -80,7 +80,7 @@ public: void setName(const std::string &name); std::string getName(); - void setCharGenStage(int start, int end); + void setCharGenStages(int currentStage, int endStage); void message(const std::string &message, bool toAll = false); bool isMale() const; void setIsMale(bool male); diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp index f5edc7aa8..cd265cb54 100644 --- a/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp +++ b/apps/openmw-mp/processors/player/ProcessorPlayerCharGen.hpp @@ -21,7 +21,7 @@ namespace mwmp { DEBUG_PRINTF(strPacketID.c_str()); - if (player->charGenStage.current == player->charGenStage.end && player->charGenStage.current != 0) + if (player->charGenState.currentStage == player->charGenState.endStage) Networking::get().getState().getEventCtrl().Call(player); } }; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 691eab1f3..f42bf9618 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -44,8 +44,9 @@ using namespace std; LocalPlayer::LocalPlayer() { - charGenStage.current = 0; - charGenStage.end = 1; + charGenState.currentStage = 0; + charGenState.endStage = 1; + charGenState.isFinished = false; consoleAllowed = false; difficulty = 0; @@ -104,26 +105,22 @@ void LocalPlayer::update() } } -void LocalPlayer::charGen(int stageFirst, int stageEnd) -{ - charGenStage.current = stageFirst; - charGenStage.end = stageEnd; -} - -bool LocalPlayer::charGenThread() +bool LocalPlayer::processCharGen() { MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); // If we haven't finished CharGen and we're in a menu, it must be // one of the CharGen menus, so go no further until it's closed - if (windowManager->isGuiMode() && charGenStage.end != 0) + if (windowManager->isGuiMode() && !charGenState.isFinished) + { return false; + } // If the current stage of CharGen is not the last one, // move to the next one - else if (charGenStage.current < charGenStage.end) + else if (charGenState.currentStage < charGenState.endStage) { - switch (charGenStage.current) + switch (charGenState.currentStage) { case 0: windowManager->pushGuiMode(MWGui::GM_Name); @@ -143,14 +140,14 @@ bool LocalPlayer::charGenThread() } getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_CHARGEN)->Send(); - charGenStage.current++; + charGenState.currentStage++; return false; } // If we've reached the last stage of CharGen, send the // corresponding packets and mark CharGen as finished - else if (charGenStage.end != 0) + else if (!charGenState.isFinished) { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); @@ -163,7 +160,7 @@ bool LocalPlayer::charGenThread() // Send stats packets if this is the 2nd round of CharGen that // only happens for new characters - if (charGenStage.end != 1) + if (charGenState.endStage != 1) { updateStatsDynamic(true); updateAttributes(true); @@ -177,8 +174,8 @@ bool LocalPlayer::charGenThread() sendCellStates(); - // Set the last stage variable to 0 to indicate that CharGen is finished - charGenStage.end = 0; + // Mark character generation as finished until overridden by a new ID_PLAYER_CHARGEN packet + charGenState.isFinished = true; } return true; @@ -186,7 +183,7 @@ bool LocalPlayer::charGenThread() bool LocalPlayer::hasFinishedCharGen() { - return charGenStage.end == 0; + return charGenState.isFinished; } void LocalPlayer::updateStatsDynamic(bool forceUpdate) diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 7c0a06353..babe9a4e0 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -21,8 +21,7 @@ namespace mwmp void update(); - void charGen(int stageFirst, int stageEnd); - bool charGenThread(); // return true if CGStage::current == CGStage::end + bool processCharGen(); // return true if CGStage::current == CGStage::end bool hasFinishedCharGen(); void updateStatsDynamic(bool forceUpdate = false); diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 344a04adf..85f436ea9 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -212,8 +212,7 @@ void Main::frame(float dt) void Main::updateWorld(float dt) const { - - if (!mLocalPlayer->charGenThread()) + if (!mLocalPlayer->processCharGen()) return; static bool init = true; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 8650c4724..8f8b58606 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -154,9 +154,10 @@ namespace mwmp { public: - struct CGStage + struct CharGenState { - int current, end; + int currentStage, endStage; + bool isFinished; }; struct GUIMessageBox @@ -227,7 +228,7 @@ namespace mwmp ESM::Class charClass; std::string birthsign; std::string chatMessage; - CGStage charGenStage; + CharGenState charGenState; std::string passw; bool isWerewolf; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp b/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp index 63bc61deb..1ea695c77 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerCharGen.cpp @@ -14,6 +14,6 @@ void mwmp::PacketPlayerCharGen::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->charGenStage, send); + RW(player->charGenState, send); }