Implemented client-side HandleCharacterSet*(); untested

This commit is contained in:
Kayne Ruse
2014-12-22 23:01:53 +11:00
parent f52eafdf55
commit 3e2d1a5a56
4 changed files with 88 additions and 3 deletions
+81 -1
View File
@@ -289,6 +289,17 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket)); HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket));
break; break;
//character movement
case SerialPacketType::CHARACTER_SET_ROOM:
HandleCharacterSetRoom(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_ORIGIN:
HandleCharacterSetOrigin(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_MOTION:
HandleCharacterSetMotion(static_cast<CharacterPacket*>(argPacket));
break;
//rejection messages //rejection messages
case SerialPacketType::REGION_REJECTION: case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::CHARACTER_REJECTION:
@@ -412,6 +423,10 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
} }
void InWorld::UpdateMap() { void InWorld::UpdateMap() {
if (roomIndex == -1) {
return;
}
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
@@ -428,7 +443,7 @@ void InWorld::UpdateMap() {
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) { if (!regionPager.FindRegion(i, j)) {
SendRegionRequest(0, i, j); SendRegionRequest(roomIndex, i, j);
} }
} }
} }
@@ -470,6 +485,9 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
//focus the camera on this character //focus the camera on this character
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
//focus on this character's room
roomIndex = argPacket->roomIndex;
} }
//debug //debug
@@ -492,6 +510,9 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//clear the camera //clear the camera
camera.marginX = 0; camera.marginX = 0;
camera.marginY = 0; camera.marginY = 0;
//clear the room
roomIndex = -1;
} }
//remove this character //remove this character
@@ -507,6 +528,11 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
return; return;
} }
//ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly construct the character if it doesn't exist //implicitly construct the character if it doesn't exist
BaseCharacter* character = &characterMap[argPacket->characterIndex]; BaseCharacter* character = &characterMap[argPacket->characterIndex];
@@ -521,3 +547,57 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
//debug //debug
std::cout << "Query, total: " << characterMap.size() << std::endl; std::cout << "Query, total: " << characterMap.size() << std::endl;
} }
void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) {
//someone else's character
if (argPacket->characterIndex != characterIndex) {
characterMap.erase(argPacket->characterIndex);
return;
}
//this character is moving between rooms
roomIndex = argPacket->roomIndex;
//set the character's info
localCharacter->SetOrigin(argPacket->origin);
localCharacter->SetMotion(argPacket->motion);
//clear the old room's data
regionPager.UnloadAll();
monsterMap.clear();
//use the jenky pattern for std::map to skip this player's character
for (std::map<int, BaseCharacter>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
if (it->first != characterIndex) {
it = characterMap.erase(it);
}
else {
++it;
}
}
//request the info on characters in this room
CharacterPacket newPacket;
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//set the origin and motion
characterIt->second.SetOrigin(argPacket->origin);
characterIt->second.SetMotion(argPacket->motion);
}
}
void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) {
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//set the origin and motion
characterIt->second.SetOrigin(argPacket->origin);
characterIt->second.SetMotion(argPacket->motion);
}
}
+4
View File
@@ -94,11 +94,15 @@ protected:
void HandleCharacterCreate(CharacterPacket* const); void HandleCharacterCreate(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const); void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterQueryExists(CharacterPacket* const); void HandleCharacterQueryExists(CharacterPacket* const);
void HandleCharacterSetRoom(CharacterPacket* const);
void HandleCharacterSetOrigin(CharacterPacket* const);
void HandleCharacterSetMotion(CharacterPacket* const);
//indexes //indexes
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int characterIndex = -1; int characterIndex = -1;
int roomIndex = -1;
//graphics //graphics
Image buttonImage; Image buttonImage;
+1 -1
View File
@@ -192,7 +192,7 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
//set the character's room, zero it's origin, zero it's motion //set the character's room, zero it's origin, zero it's motion
//TODO: Set the origin here //TODO: Set the origin here
characterData->SetRoom(argPacket->roomIndex); characterData->SetRoomIndex(argPacket->roomIndex);
characterData->SetOrigin({0, 0}); characterData->SetOrigin({0, 0});
characterData->SetMotion({0, 0}); characterData->SetMotion({0, 0});
+1
View File
@@ -73,6 +73,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) { void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) {
//respond with all character data //respond with all character data
//TODO: handle room and location specifications
CharacterPacket newPacket; CharacterPacket newPacket;
for (auto& it : *characterMgr.GetContainer()) { for (auto& it : *characterMgr.GetContainer()) {
CopyCharacterToPacket(&newPacket, it.first); CopyCharacterToPacket(&newPacket, it.first);