1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 18:19:55 +00:00

[General] Turn GameTime into a Worldstate packet

This commit is contained in:
David Cernat 2018-05-21 07:14:08 +03:00
parent e87e1dbb30
commit 5af1150ab2
13 changed files with 68 additions and 62 deletions

View file

@ -1,4 +1,5 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Base/BaseWorldstate.hpp>
#include <apps/openmw-mp/Networking.hpp>
#include <apps/openmw-mp/Player.hpp>
@ -6,20 +7,24 @@
#include "Worldstate.hpp"
#include <iostream>
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;
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false);
writeWorldstate.hour = hour;
writeWorldstate.month = -1;
writeWorldstate.day = -1;
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;
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 = -1;
writeWorldstate.day = day;
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->setWorldstate(&writeWorldstate);
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_GAME_TIME)->Send(false);
}

View file

@ -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)

View file

@ -1,7 +1,8 @@
#include "ObjectProcessor.hpp"
#include "../Main.hpp"
#include "../Networking.hpp"
#include "ObjectProcessor.hpp"
using namespace mwmp;
template<class T>

View file

@ -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());
}

View file

@ -1,18 +1,14 @@
//
// Created by koncord on 16.04.17.
//
#ifndef OPENMW_PROCESSORGAMETIME_HPP
#define OPENMW_PROCESSORGAMETIME_HPP
#include <apps/openmw/mwbase/world.hpp>
#include <apps/openmw/mwbase/environment.hpp>
#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);
}
}
};

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,8 @@
#ifndef OPENMW_BASESTRUCTS_HPP
#define OPENMW_BASESTRUCTS_HPP
#include <string>
#include <components/esm/statstate.hpp>
#include <RakNetTypes.h>

View file

@ -19,6 +19,10 @@ namespace mwmp
RakNet::RakNetGUID guid;
int month;
int day;
double hour;
bool isValid;
};
}

View file

@ -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<PacketCellCreate>(&packets, peer);
AddPacket<PacketRecordDynamic>(&packets, peer);
AddPacket<PacketGameSettings>(&packets, peer);
AddPacket<PacketGameTime>(&packets, peer);
AddPacket<PacketGameWeather>(&packets, peer);
AddPacket<PacketPlayerActiveSkills>(&packets, peer);

View file

@ -1,3 +1,5 @@
#include "../Packets/Worldstate/PacketGameTime.hpp"
#include "WorldstatePacketController.hpp"
template <typename T>
@ -10,7 +12,7 @@ inline void AddPacket(mwmp::WorldstatePacketController::packets_t *packets, RakN
mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInterface *peer)
{
AddPacket<PacketGameTime>(&packets, peer);
}

View file

@ -1,13 +1,9 @@
//
// Created by koncord on 30.08.16.
//
#include "PacketGameTime.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
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);
}

View file

@ -1,15 +1,11 @@
//
// Created by koncord on 30.08.16.
//
#ifndef OPENMW_PACKETGAMETIME_HPP
#define OPENMW_PACKETGAMETIME_HPP
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
#include <components/openmw-mp/Packets/Worldstate/WorldstatePacket.hpp>
namespace mwmp
{
class PacketGameTime : public PlayerPacket
class PacketGameTime : public WorldstatePacket
{
public:
PacketGameTime(RakNet::RakPeerInterface *peer);