From 5af1150ab256ab3ad700e877723f2b44ae959440 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 21 May 2018 07:14:08 +0300 Subject: [PATCH] [General] Turn GameTime into a Worldstate packet --- .../openmw-mp/Script/Functions/Worldstate.cpp | 41 +++++++++++-------- apps/openmw/CMakeLists.txt | 19 +++++---- .../mwmp/processors/ObjectProcessor.cpp | 3 +- .../mwmp/processors/ProcessorInitializer.cpp | 5 ++- .../ProcessorGameTime.hpp | 22 ++++------ components/CMakeLists.txt | 3 +- components/openmw-mp/Base/BasePlayer.hpp | 3 -- components/openmw-mp/Base/BaseStructs.hpp | 2 + components/openmw-mp/Base/BaseWorldstate.hpp | 4 ++ .../Controllers/PlayerPacketController.cpp | 2 - .../WorldstatePacketController.cpp | 4 +- .../{Player => Worldstate}/PacketGameTime.cpp | 14 +++---- .../{Player => Worldstate}/PacketGameTime.hpp | 8 +--- 13 files changed, 68 insertions(+), 62 deletions(-) rename apps/openmw/mwmp/processors/{player => worldstate}/ProcessorGameTime.hpp (50%) rename components/openmw-mp/Packets/{Player => Worldstate}/PacketGameTime.cpp (62%) rename components/openmw-mp/Packets/{Player => Worldstate}/PacketGameTime.hpp (63%) diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index b95b67d14..0460e3915 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,20 +7,24 @@ #include "Worldstate.hpp" -#include using namespace std; +using namespace mwmp; + +BaseWorldstate writeWorldstate; void WorldstateFunctions::SetHour(unsigned short pid, double hour) noexcept { Player *player; GET_PLAYER(pid, player, ); - player->hour = hour; - player->month = -1; - player->day = -1; + writeWorldstate.guid = player->guid; + + writeWorldstate.hour = hour; + writeWorldstate.month = -1; + writeWorldstate.day = -1; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->setWorldstate(&writeWorldstate); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->Send(false); } void WorldstateFunctions::SetMonth(unsigned short pid, int month) noexcept @@ -27,12 +32,14 @@ void WorldstateFunctions::SetMonth(unsigned short pid, int month) noexcept Player *player; GET_PLAYER(pid, player, ); - player->hour = -1; - player->month = month; - player->day = -1; + writeWorldstate.guid = player->guid; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); + writeWorldstate.hour = -1; + writeWorldstate.month = month; + writeWorldstate.day = -1; + + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->setWorldstate(&writeWorldstate); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->Send(false); } @@ -41,10 +48,12 @@ void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept Player *player; GET_PLAYER(pid, player, ); - player->hour = -1; - player->month = -1; - player->day = day; + writeWorldstate.guid = player->guid; + + writeWorldstate.hour = -1; + writeWorldstate.month = -1; + writeWorldstate.day = day; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->setWorldstate(&writeWorldstate); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->Send(false); } diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 10384e004..ddea2b435 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -115,14 +115,14 @@ add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags P add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorHandshake ProcessorUserDisconnected ProcessorUserMyID ProcessorCellCreate ProcessorRecordDynamic ProcessorGameSettings - ProcessorGameTime ProcessorGameWeather ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack - ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty - ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath - ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInteraction - ProcessorPlayerInventory ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerKillCount ProcessorPlayerLevel - ProcessorPlayerMap ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys - ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech - ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic + ProcessorGameWeather ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack ProcessorPlayerAttribute + ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty ProcessorPlayerCellChange + ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition + ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInteraction ProcessorPlayerInventory ProcessorPlayerJail + ProcessorPlayerJournal ProcessorPlayerKillCount ProcessorPlayerLevel ProcessorPlayerMap ProcessorPlayerMiscellaneous + ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation ProcessorPlayerResurrect + ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic + ProcessorPlayerTopic ) add_openmw_dir (mwmp/processors/object BaseObjectProcessor ProcessorConsoleCommand ProcessorContainer ProcessorDoorDestination @@ -133,6 +133,9 @@ add_openmw_dir (mwmp/processors/object BaseObjectProcessor ProcessorConsoleComma ProcessorScriptMemberFloat ProcessorScriptGlobalShort ProcessorScriptGlobalFloat ) +add_openmw_dir (mwmp/processors/worldstate ProcessorGameTime + ) + # Main executable if (NOT ANDROID) diff --git a/apps/openmw/mwmp/processors/ObjectProcessor.cpp b/apps/openmw/mwmp/processors/ObjectProcessor.cpp index 7eae403db..33cce8352 100644 --- a/apps/openmw/mwmp/processors/ObjectProcessor.cpp +++ b/apps/openmw/mwmp/processors/ObjectProcessor.cpp @@ -1,7 +1,8 @@ -#include "ObjectProcessor.hpp" #include "../Main.hpp" #include "../Networking.hpp" +#include "ObjectProcessor.hpp" + using namespace mwmp; template diff --git a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp index 38cbc0a9c..95d32842e 100644 --- a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp +++ b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp @@ -8,7 +8,6 @@ #include "player/ProcessorCellCreate.hpp" #include "player/ProcessorRecordDynamic.hpp" #include "player/ProcessorGameSettings.hpp" -#include "player/ProcessorGameTime.hpp" #include "player/ProcessorGameWeather.hpp" #include "player/ProcessorPlayerAnimFlags.hpp" #include "player/ProcessorPlayerAnimPlay.hpp" @@ -92,6 +91,7 @@ #include "actor/ProcessorActorTest.hpp" #include "WorldstateProcessor.hpp" +#include "worldstate/ProcessorGameTime.hpp" using namespace mwmp; @@ -104,7 +104,6 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorCellCreate()); PlayerProcessor::AddProcessor(new ProcessorRecordDynamic()); PlayerProcessor::AddProcessor(new ProcessorGameSettings()); - PlayerProcessor::AddProcessor(new ProcessorGameTime()); PlayerProcessor::AddProcessor(new ProcessorGameWeather()); PlayerProcessor::AddProcessor(new ProcessorPlayerAnimFlags()); PlayerProcessor::AddProcessor(new ProcessorPlayerAnimPlay()); @@ -184,4 +183,6 @@ void ProcessorInitializer() ActorProcessor::AddProcessor(new ProcessorActorSpeech()); ActorProcessor::AddProcessor(new ProcessorActorStatsDynamic()); ActorProcessor::AddProcessor(new ProcessorActorTest()); + + WorldstateProcessor::AddProcessor(new ProcessorGameTime()); } diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorGameTime.hpp similarity index 50% rename from apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp rename to apps/openmw/mwmp/processors/worldstate/ProcessorGameTime.hpp index 1ee0b7694..ce0180536 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameTime.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorGameTime.hpp @@ -1,18 +1,14 @@ -// -// Created by koncord on 16.04.17. -// - #ifndef OPENMW_PROCESSORGAMETIME_HPP #define OPENMW_PROCESSORGAMETIME_HPP #include #include -#include "../PlayerProcessor.hpp" +#include "../WorldstateProcessor.hpp" namespace mwmp { - class ProcessorGameTime : public PlayerProcessor + class ProcessorGameTime : public WorldstateProcessor { public: ProcessorGameTime() @@ -20,17 +16,17 @@ namespace mwmp BPP_INIT(ID_GAME_TIME) } - virtual void Do(PlayerPacket &packet, BasePlayer *player) + virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) { if (isLocal()) { MWBase::World *world = MWBase::Environment::get().getWorld(); - if (player->hour != -1) - world->setHour(player->hour); - else if (player->day != -1) - world->setDay(player->day); - else if (player->month != -1) - world->setMonth(player->month); + if (worldstate.hour != -1) + world->setHour(worldstate.hour); + else if (worldstate.day != -1) + world->setDay(worldstate.day); + else if (worldstate.month != -1) + world->setMonth(worldstate.month); } } }; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 3516104ed..6f6bfcc1f 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -174,7 +174,7 @@ add_component_dir (openmw-mp/Packets/Actor add_component_dir (openmw-mp/Packets/Player PlayerPacket - PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameSettings PacketGameTime PacketGameWeather + PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameSettings PacketGameWeather PacketCellCreate PacketRecordDynamic @@ -198,6 +198,7 @@ add_component_dir (openmw-mp/Packets/Object add_component_dir (openmw-mp/Packets/Worldstate WorldstatePacket + PacketGameTime ) add_component_dir (fallback diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index f625e1c0d..9cc13c71f 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -246,9 +246,6 @@ namespace mwmp RakNet::RakNetGUID guid; GUIMessageBox guiMessageBox; - int month; - int day; - double hour; // Track only the indexes of the attributes that have been changed, // with the attribute values themselves being stored in creatureStats.mAttributes diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 03fa30082..4f71d3b89 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_BASESTRUCTS_HPP #define OPENMW_BASESTRUCTS_HPP +#include + #include #include diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index a823066f0..ba108a9e1 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -19,6 +19,10 @@ namespace mwmp RakNet::RakNetGUID guid; + int month; + int day; + double hour; + bool isValid; }; } diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index a9579e779..55c256adb 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -7,7 +7,6 @@ #include "../Packets/Player/PacketCellCreate.hpp" #include "../Packets/Player/PacketRecordDynamic.hpp" #include "../Packets/Player/PacketGameSettings.hpp" -#include "../Packets/Player/PacketGameTime.hpp" #include "../Packets/Player/PacketGameWeather.hpp" #include "../Packets/Player/PacketPlayerActiveSkills.hpp" #include "../Packets/Player/PacketPlayerAnimFlags.hpp" @@ -66,7 +65,6 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); - AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/Controllers/WorldstatePacketController.cpp b/components/openmw-mp/Controllers/WorldstatePacketController.cpp index 44d83c5c1..667d29b08 100644 --- a/components/openmw-mp/Controllers/WorldstatePacketController.cpp +++ b/components/openmw-mp/Controllers/WorldstatePacketController.cpp @@ -1,3 +1,5 @@ +#include "../Packets/Worldstate/PacketGameTime.hpp" + #include "WorldstatePacketController.hpp" template @@ -10,7 +12,7 @@ inline void AddPacket(mwmp::WorldstatePacketController::packets_t *packets, RakN mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer) { - + AddPacket(&packets, peer); } diff --git a/components/openmw-mp/Packets/Player/PacketGameTime.cpp b/components/openmw-mp/Packets/Worldstate/PacketGameTime.cpp similarity index 62% rename from components/openmw-mp/Packets/Player/PacketGameTime.cpp rename to components/openmw-mp/Packets/Worldstate/PacketGameTime.cpp index 71027707e..8c1ff7ffc 100644 --- a/components/openmw-mp/Packets/Player/PacketGameTime.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketGameTime.cpp @@ -1,13 +1,9 @@ -// -// Created by koncord on 30.08.16. -// - #include "PacketGameTime.hpp" #include using namespace mwmp; -PacketGameTime::PacketGameTime(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) +PacketGameTime::PacketGameTime(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer) { packetID = ID_GAME_TIME; orderChannel = CHANNEL_SYSTEM; @@ -15,9 +11,9 @@ PacketGameTime::PacketGameTime(RakNet::RakPeerInterface *peer) : PlayerPacket(pe void PacketGameTime::Packet(RakNet::BitStream *bs, bool send) { - PlayerPacket::Packet(bs, send); + WorldstatePacket::Packet(bs, send); - RW(player->month, send); - RW(player->day, send); - RW(player->hour, send); + RW(worldstate->month, send); + RW(worldstate->day, send); + RW(worldstate->hour, send); } diff --git a/components/openmw-mp/Packets/Player/PacketGameTime.hpp b/components/openmw-mp/Packets/Worldstate/PacketGameTime.hpp similarity index 63% rename from components/openmw-mp/Packets/Player/PacketGameTime.hpp rename to components/openmw-mp/Packets/Worldstate/PacketGameTime.hpp index 9f48f8674..e081e1d0c 100644 --- a/components/openmw-mp/Packets/Player/PacketGameTime.hpp +++ b/components/openmw-mp/Packets/Worldstate/PacketGameTime.hpp @@ -1,15 +1,11 @@ -// -// Created by koncord on 30.08.16. -// - #ifndef OPENMW_PACKETGAMETIME_HPP #define OPENMW_PACKETGAMETIME_HPP -#include +#include namespace mwmp { - class PacketGameTime : public PlayerPacket + class PacketGameTime : public WorldstatePacket { public: PacketGameTime(RakNet::RakPeerInterface *peer);