Creatures are visible
This commit is contained in:
@@ -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
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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, static_cast<SerialPacket*>(&newPacket));
|
||||||
network.SendTo(argPacket->srcAddress, reinterpret_cast<void*>(&newPacket), MAX_PACKET_SIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user