Threaded the barriers through the networking system
This commit is contained in:
@@ -21,12 +21,13 @@
|
||||
*/
|
||||
#include "barrier_data.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
BarrierData::BarrierData(int i):
|
||||
Entity::Entity("barrier")
|
||||
{
|
||||
//
|
||||
memcpy(status, 0, sizeof(int) * 8);
|
||||
}
|
||||
|
||||
BarrierData::~BarrierData() {
|
||||
@@ -81,3 +82,7 @@ int BarrierData::SetInstanceIndex(int i) {
|
||||
int BarrierData::GetInstanceIndex() const {
|
||||
return instanceIndex;
|
||||
}
|
||||
|
||||
int* BarrierData::GetStatusArray() {
|
||||
return status;
|
||||
}
|
||||
@@ -44,9 +44,13 @@ public:
|
||||
int SetInstanceIndex(int i);
|
||||
int GetInstanceIndex() const;
|
||||
|
||||
int* GetStatusArray();
|
||||
|
||||
private:
|
||||
int scriptRef = LUA_NOREF;
|
||||
std::map<std::string, std::string> tags;
|
||||
|
||||
int instanceIndex = -1;
|
||||
|
||||
int status[8];
|
||||
};
|
||||
@@ -115,6 +115,19 @@ void RoomData::RunFrame() {
|
||||
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
|
||||
}
|
||||
|
||||
//a list of barriers that need to be updated client-side
|
||||
std::list< std::pair<const int, BarrierData*>> barrierList;
|
||||
barrierMgr.Update(&barrierList);
|
||||
|
||||
//send the updates
|
||||
for (auto& it : barrierList) {
|
||||
BarrierPacket packet;
|
||||
copyBarrierToPacket(&packet, it.second, it.first);
|
||||
packet.type = SerialPacketType::BARRIER_UPDATE;
|
||||
packet.roomIndex = roomIndex;
|
||||
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
|
||||
}
|
||||
|
||||
//TODO: creature/character collisions
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,16 @@ void copyCreatureToPacket(CreaturePacket* const packet, CreatureData* const crea
|
||||
packet->bounds = creatureData->GetBounds();
|
||||
}
|
||||
|
||||
void copyBarrierToPacket(BarrierPacket* const packet, BarrierData* const barrierData, int barrierIndex) {
|
||||
packet->barrierIndex = barrierIndex;
|
||||
packet->roomIndex = barrierData->GetRoomIndex();
|
||||
packet->origin = barrierData->GetOrigin();
|
||||
packet->motion = barrierData->GetMotion();
|
||||
packet->bounds = barrierData->GetBounds();
|
||||
|
||||
memcpy(barrierData->GetStatusArray(), &packet->status, sizeof(int) * 8);
|
||||
}
|
||||
|
||||
void pumpAndChangeRooms(int characterIndex, int newRoomIndex) {
|
||||
//get the character object
|
||||
CharacterData* character = CharacterManager::GetSingleton().Find(characterIndex);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "barrier_data.hpp"
|
||||
#include "character_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
#include "serial_packet.hpp"
|
||||
@@ -38,6 +39,8 @@ void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const c
|
||||
|
||||
void copyCreatureToPacket(CreaturePacket* const packet, CreatureData* const creatureData, int creatureIndex);
|
||||
|
||||
void copyBarrierToPacket(BarrierPacket* const packet, BarrierData* const barrierData, int barrierIndex);
|
||||
|
||||
void pumpAndChangeRooms(int characterIndex, int newRoomIndex);
|
||||
void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user