forked from teamnwah/openmw-tes3coop
[Server] Create Worldstate class and implement associated table
parent
07b781cd32
commit
49bf605e8e
@ -0,0 +1,133 @@
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
#include "Worldstate.hpp"
|
||||
#include "Networking.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Worldstate::Init(LuaState &lua)
|
||||
{
|
||||
sol::table worldstateTable = lua.getState()->create_named_table("Worldstate");
|
||||
|
||||
worldstateTable.set_function("setHour", [](double hour) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setHour(hour);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setDay", [](int day) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setDay(day);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setMonth", [](int month) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setMonth(month);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setYear", [](int year) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setYear(year);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setDaysPassed", [](int daysPassed) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setDaysPassed(daysPassed);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setTimeScale", [](float timeScale) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setTimeScale(timeScale);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setPlayerCollisionState", [](bool state) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setPlayerCollisionState(state);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setActorCollisionState", [](bool state) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setActorCollisionState(state);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setPlacedObjectCollisionState", [](bool state) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setPlacedObjectCollisionState(state);
|
||||
});
|
||||
|
||||
worldstateTable.set_function("setActorCollisionForPlacedObjects", [](bool state) {
|
||||
mwmp::Networking::get().get().getServerWorldstate()->setActorCollisionForPlacedObjects(state);
|
||||
});
|
||||
}
|
||||
|
||||
void Worldstate::update()
|
||||
{
|
||||
auto worldstateController = mwmp::Networking::get().getWorldstatePacketController();
|
||||
|
||||
if (shouldUpdateTime)
|
||||
{
|
||||
auto packet = worldstateController->GetPacket(ID_WORLD_TIME);
|
||||
packet->setWorldstate(this);
|
||||
packet->Send(true);
|
||||
|
||||
shouldUpdateTime = false;
|
||||
}
|
||||
|
||||
if (shouldUpdateCollisionOverrides)
|
||||
{
|
||||
auto packet = worldstateController->GetPacket(ID_WORLD_COLLISION_OVERRIDE);
|
||||
packet->setWorldstate(this);
|
||||
packet->Send(true);
|
||||
|
||||
shouldUpdateCollisionOverrides = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Worldstate::setHour(double inputHour)
|
||||
{
|
||||
hour = inputHour;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setDay(int inputDay)
|
||||
{
|
||||
day = inputDay;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setMonth(int inputMonth)
|
||||
{
|
||||
month = inputMonth;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setYear(int inputYear)
|
||||
{
|
||||
year = inputYear;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setDaysPassed(int inputDaysPassed)
|
||||
{
|
||||
daysPassed = inputDaysPassed;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setTimeScale(float inputTimeScale)
|
||||
{
|
||||
timeScale = inputTimeScale;
|
||||
shouldUpdateTime = true;
|
||||
}
|
||||
|
||||
void Worldstate::setPlayerCollisionState(bool state)
|
||||
{
|
||||
hasPlayerCollision = state;
|
||||
shouldUpdateCollisionOverrides = true;
|
||||
}
|
||||
|
||||
void Worldstate::setActorCollisionState(bool state)
|
||||
{
|
||||
hasActorCollision = state;
|
||||
shouldUpdateCollisionOverrides = true;
|
||||
}
|
||||
void Worldstate::setPlacedObjectCollisionState(bool state)
|
||||
{
|
||||
hasPlacedObjectCollision = state;
|
||||
shouldUpdateCollisionOverrides = true;
|
||||
}
|
||||
|
||||
void Worldstate::setActorCollisionForPlacedObjects(bool state)
|
||||
{
|
||||
useActorCollisionForPlacedObjects = state;
|
||||
shouldUpdateCollisionOverrides = true;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <RakNetTypes.h>
|
||||
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
#include <components/openmw-mp/Base/BaseWorldstate.hpp>
|
||||
#include <components/openmw-mp/Packets/Worldstate/WorldstatePacket.hpp>
|
||||
|
||||
class LuaState;
|
||||
|
||||
|
||||
class Worldstate : public mwmp::BaseWorldstate
|
||||
{
|
||||
public:
|
||||
|
||||
static void Init(LuaState &lua);
|
||||
|
||||
void update();
|
||||
|
||||
void setHour(double hour);
|
||||
void setDay(int day);
|
||||
void setMonth(int month);
|
||||
void setYear(int year);
|
||||
void setDaysPassed(int daysPassed);
|
||||
void setTimeScale(float timeScale);
|
||||
|
||||
void setPlayerCollisionState(bool state);
|
||||
void setActorCollisionState(bool state);
|
||||
void setPlacedObjectCollisionState(bool state);
|
||||
void setActorCollisionForPlacedObjects(bool state);
|
||||
|
||||
private:
|
||||
|
||||
bool shouldUpdateTime, shouldUpdateCollisionOverrides;
|
||||
|
||||
};
|
Loading…
Reference in New Issue