Server is ready to send
This commit is contained in:
@@ -30,12 +30,12 @@ CreatureManager::~CreatureManager() {
|
||||
}
|
||||
|
||||
//arg: a list of creatures to be updated in the clients
|
||||
int CreatureManager::Update(std::list<CreatureData*>* creatureList) {
|
||||
int CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList) {
|
||||
int ret;
|
||||
for (auto& it : elementMap) {
|
||||
ret = it.second.Update(lua);
|
||||
if (ret) {
|
||||
creatureList->push_back(&it.second);
|
||||
creatureList->push_back(std::pair<const int, CreatureData*>(it.first, &it.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
~CreatureManager();
|
||||
|
||||
//common public methods
|
||||
int Update(std::list<CreatureData*>* creatureList);
|
||||
int Update(std::list<std::pair<const int, CreatureData*>>* creatureList);
|
||||
|
||||
int Create(std::string avatar, int scriptRef);
|
||||
void Unload(int uid);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. .. ../characters ../creatures ../entities ../monsters ../triggers ../../common/gameplay ../../common/map ../../common/utilities
|
||||
INCLUDES+=. .. ../characters ../creatures ../entities ../monsters ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
*/
|
||||
#include "room_data.hpp"
|
||||
|
||||
#include "serial_packet.hpp"
|
||||
#include "server_utilities.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
@@ -99,10 +102,15 @@ void RoomData::RunFrame() {
|
||||
}
|
||||
|
||||
//a list of creatures that need to be updated client-side
|
||||
std::list<CreatureData*> creatureList;
|
||||
std::list< std::pair<const int, CreatureData*>> creatureList;
|
||||
creatureMgr.Update(&creatureList);
|
||||
|
||||
//TODO: (0) send the updates
|
||||
//send the updates
|
||||
for (auto& it : creatureList) {
|
||||
CreaturePacket packet;
|
||||
copyCreatureToPacket(&packet, it.second, it.first);
|
||||
//TODO: send
|
||||
}
|
||||
|
||||
//TODO: creature/character collisions
|
||||
}
|
||||
|
||||
@@ -169,6 +169,14 @@ void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const c
|
||||
packet->bounds = characterData->GetBounds();
|
||||
}
|
||||
|
||||
void copyCreatureToPacket(CreaturePacket* const packet, CreatureData* const creatureData, int creatureIndex) {
|
||||
packet->creatureIndex = creatureIndex;
|
||||
strncpy(packet->avatar, creatureData->GetAvatar().c_str(), PACKET_STRING_SIZE);
|
||||
packet->origin = creatureData->GetOrigin();
|
||||
packet->motion = creatureData->GetMotion();
|
||||
packet->bounds = creatureData->GetBounds();
|
||||
}
|
||||
|
||||
void pumpAndChangeRooms(int characterIndex, int newRoomIndex) {
|
||||
//get the character object
|
||||
CharacterData* character = CharacterManager::GetSingleton().Get(characterIndex);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "character_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
#include "serial_packet.hpp"
|
||||
#include "vector2.hpp"
|
||||
|
||||
@@ -34,5 +35,8 @@ void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 p
|
||||
|
||||
void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
||||
void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex);
|
||||
|
||||
void copyCreatureToPacket(CreaturePacket* const packet, CreatureData* const creatureData, int creatureIndex);
|
||||
|
||||
void pumpAndChangeRooms(int characterIndex, int newRoomIndex);
|
||||
void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex);
|
||||
|
||||
Reference in New Issue
Block a user