Creatures are visible

This commit is contained in:
2016-03-29 03:19:17 +11:00
parent 42b37be6f5
commit 8778bfdc4b
4 changed files with 30 additions and 23 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ std::string BaseCreature::GetHandle() const {
std::string BaseCreature::SetAvatar(SDL_Renderer* const renderer, std::string s) { std::string BaseCreature::SetAvatar(SDL_Renderer* const renderer, std::string s) {
avatar = s; avatar = s;
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1); sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 4);
return avatar; return avatar;
} }
+20 -15
View File
@@ -684,13 +684,16 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
roomIndex = argPacket->roomIndex; roomIndex = argPacket->roomIndex;
//query the world state (room) //query the world state (room)
CharacterPacket newPacket; CharacterPacket characterPacket;
memset(&newPacket, 0, MAX_PACKET_SIZE); memset(&characterPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex; characterPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket); network.SendTo(Channels::SERVER, &characterPacket);
newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
network.SendTo(Channels::SERVER, &newPacket); CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
creaturePacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &creaturePacket);
} }
//debug //debug
@@ -805,14 +808,14 @@ void World::hCreatureCreate(CreaturePacket* const argPacket) {
throw(std::runtime_error(msg.str())); throw(std::runtime_error(msg.str()));
} }
// //ignore creatures from other rooms //ignore creatures from other rooms
// if (roomIndex != argPacket->roomIndex) { if (roomIndex != argPacket->roomIndex) {
// //temporary error checking //temporary error checking
// std::ostringstream msg; std::ostringstream msg;
// msg << "Creature from the wrong room received: "; msg << "Creature from the wrong room received: ";
// msg << "creatureIndex: " << argPacket->creatureIndex << ", roomIndex: " << argPacket->roomIndex; msg << "creatureIndex: " << argPacket->creatureIndex << ", roomIndex: " << argPacket->roomIndex;
// throw(std::runtime_error(msg.str())); throw(std::runtime_error(msg.str()));
// } }
//implicitly create the element //implicitly create the element
BaseCreature* creature = &creatureMap[argPacket->creatureIndex]; BaseCreature* creature = &creatureMap[argPacket->creatureIndex];
@@ -843,6 +846,8 @@ void World::hCreatureUnload(CreaturePacket* const argPacket) {
} }
void World::hQueryCreatureExists(CreaturePacket* const argPacket) { void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
std::cout << "Creature Query" << std::endl;
//ignore creatures in a different room (sub-optimal) //ignore creatures in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) { if (argPacket->roomIndex != roomIndex) {
return; return;
+1
View File
@@ -142,6 +142,7 @@ void RoomManager::PopCharacter(CharacterData const* character) {
}); });
} }
//TODO: rename these functions from Get to Find
RoomData* RoomManager::Get(int uid) { RoomData* RoomManager::Get(int uid) {
std::map<int, RoomData>::iterator it = elementMap.find(uid); std::map<int, RoomData>::iterator it = elementMap.find(uid);
+6 -5
View File
@@ -806,15 +806,16 @@ void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
//TODO: On creature create, etc. //TODO: On creature create, etc.
void ServerApplication::hQueryCreatureExists(CreaturePacket* const argPacket) { void ServerApplication::hQueryCreatureExists(CreaturePacket* const argPacket) {
//respond with all creature data
CreaturePacket newPacket;
CreatureManager* creatureMgr = roomMgr.Get(argPacket->roomIndex)->GetCreatureMgr(); CreatureManager* creatureMgr = roomMgr.Get(argPacket->roomIndex)->GetCreatureMgr();
CreaturePacket newPacket; //TODO: move this into the room class
for ( auto& it : *(creatureMgr->GetContainer()) ) { for (auto& it : *(creatureMgr->GetContainer()) ) {
if (distance(argPacket->origin, it.second.GetOrigin()) < 1000) {
copyCreatureToPacket(&newPacket, &(it.second), it.first); copyCreatureToPacket(&newPacket, &(it.second), it.first);
newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS; newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
network.SendTo(argPacket->srcAddress, reinterpret_cast<void*>(&newPacket), MAX_PACKET_SIZE); network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
}
} }
} }