Added network tweaks to client; project builds cleanly

This commit is contained in:
Kayne Ruse
2015-01-15 23:32:04 +11:00
parent 42662c3f61
commit be90694234
2 changed files with 15 additions and 67 deletions
+12 -63
View File
@@ -159,7 +159,7 @@ void InWorld::Update() {
//process the collisions //process the collisions
if (localCharacter->ProcessCollisionGrid(boxList)) { if (localCharacter->ProcessCollisionGrid(boxList)) {
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendLocalCharacterMovement();
} }
//update the camera //update the camera
@@ -267,7 +267,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
//set the info //set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendLocalCharacterMovement();
} }
void InWorld::KeyUp(SDL_KeyboardEvent const& key) { void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
@@ -313,7 +313,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
//set the info //set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendLocalCharacterMovement();
} }
//------------------------- //-------------------------
@@ -358,14 +358,11 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
break; break;
//character movement //character movement
case SerialPacketType::CHARACTER_SET_ROOM: case SerialPacketType::CHARACTER_MOVEMENT:
HandleCharacterSetRoom(static_cast<CharacterPacket*>(argPacket)); HandleCharacterMovement(static_cast<CharacterPacket*>(argPacket));
break; break;
case SerialPacketType::CHARACTER_SET_ORIGIN: case SerialPacketType::CHARACTER_ATTACK:
HandleCharacterSetOrigin(static_cast<CharacterPacket*>(argPacket)); HandleCharacterAttack(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_MOTION:
HandleCharacterSetMotion(static_cast<CharacterPacket*>(argPacket));
break; break;
//rejection messages //rejection messages
@@ -638,43 +635,7 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
std::cout << "Query, total: " << characterMap.size() << std::endl; std::cout << "Query, total: " << characterMap.size() << std::endl;
} }
void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { void InWorld::HandleCharacterMovement(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);
localCharacter->CorrectSprite();
//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;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
//TODO: Authentication //TODO: Authentication
if (argPacket->characterIndex == characterIndex) { if (argPacket->characterIndex == characterIndex) {
return; return;
@@ -690,20 +651,8 @@ void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
} }
} }
void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) { void InWorld::HandleCharacterAttack(CharacterPacket* const argPacket) {
//TODO: Authentication //TODO: attack animation
if (argPacket->characterIndex == characterIndex) {
return;
}
//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);
characterIt->second.CorrectSprite();
}
} }
//------------------------- //-------------------------
@@ -711,9 +660,9 @@ void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) {
//------------------------- //-------------------------
//TODO: add a "movement" packet type //TODO: add a "movement" packet type
void InWorld::SendLocalCharacterMotion() { void InWorld::SendLocalCharacterMovement() {
CharacterPacket newPacket; CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION; newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
newPacket.accountIndex = accountIndex; newPacket.accountIndex = accountIndex;
newPacket.characterIndex = characterIndex; newPacket.characterIndex = characterIndex;
+3 -4
View File
@@ -96,12 +96,11 @@ 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 HandleCharacterMovement(CharacterPacket* const);
void HandleCharacterSetOrigin(CharacterPacket* const); void HandleCharacterAttack(CharacterPacket* const);
void HandleCharacterSetMotion(CharacterPacket* const);
//player movement //player movement
void SendLocalCharacterMotion(); void SendLocalCharacterMovement();
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight); std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
//indexes //indexes