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) {
avatar = s;
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 4);
return avatar;
}
+20 -15
View File
@@ -684,13 +684,16 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
roomIndex = argPacket->roomIndex;
//query the world state (room)
CharacterPacket newPacket;
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
CharacterPacket characterPacket;
memset(&characterPacket, 0, MAX_PACKET_SIZE);
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
characterPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &characterPacket);
CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
creaturePacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &creaturePacket);
}
//debug
@@ -805,14 +808,14 @@ void World::hCreatureCreate(CreaturePacket* const argPacket) {
throw(std::runtime_error(msg.str()));
}
// //ignore creatures from other rooms
// if (roomIndex != argPacket->roomIndex) {
// //temporary error checking
// std::ostringstream msg;
// msg << "Creature from the wrong room received: ";
// msg << "creatureIndex: " << argPacket->creatureIndex << ", roomIndex: " << argPacket->roomIndex;
// throw(std::runtime_error(msg.str()));
// }
//ignore creatures from other rooms
if (roomIndex != argPacket->roomIndex) {
//temporary error checking
std::ostringstream msg;
msg << "Creature from the wrong room received: ";
msg << "creatureIndex: " << argPacket->creatureIndex << ", roomIndex: " << argPacket->roomIndex;
throw(std::runtime_error(msg.str()));
}
//implicitly create the element
BaseCreature* creature = &creatureMap[argPacket->creatureIndex];
@@ -843,6 +846,8 @@ void World::hCreatureUnload(CreaturePacket* const argPacket) {
}
void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
std::cout << "Creature Query" << std::endl;
//ignore creatures in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
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) {
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.
void ServerApplication::hQueryCreatureExists(CreaturePacket* const argPacket) {
//respond with all creature data
CreaturePacket newPacket;
CreatureManager* creatureMgr = roomMgr.Get(argPacket->roomIndex)->GetCreatureMgr();
CreaturePacket newPacket;
for ( auto& it : *(creatureMgr->GetContainer()) ) {
if (distance(argPacket->origin, it.second.GetOrigin()) < 1000) {
//TODO: move this into the room class
for (auto& it : *(creatureMgr->GetContainer()) ) {
copyCreatureToPacket(&newPacket, &(it.second), it.first);
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));
}
}