Did some renaming and comment tweaks
This commit is contained in:
+38
-38
@@ -31,11 +31,11 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argPlayerIndex):
|
||||
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
playerIndex(*argPlayerIndex)
|
||||
characterIndex(*argCharacterIndex)
|
||||
{
|
||||
//setup the utility objects
|
||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
@@ -67,7 +67,7 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
||||
char buffer[PACKET_STRING_SIZE];
|
||||
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.playerIndex = playerIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
serialize(&packet, buffer);
|
||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||
|
||||
@@ -252,14 +252,14 @@ void InWorld::HandlePacket(SerialPacket packet) {
|
||||
case SerialPacket::Type::REGION_CONTENT:
|
||||
HandleRegionContent(packet);
|
||||
break;
|
||||
case SerialPacket::Type::PLAYER_UPDATE:
|
||||
HandlePlayerUpdate(packet);
|
||||
case SerialPacket::Type::CHARACTER_UPDATE:
|
||||
HandleCharacterUpdate(packet);
|
||||
break;
|
||||
case SerialPacket::Type::PLAYER_NEW:
|
||||
HandlePlayerNew(packet);
|
||||
case SerialPacket::Type::CHARACTER_NEW:
|
||||
HandleCharacterNew(packet);
|
||||
break;
|
||||
case SerialPacket::Type::PLAYER_DELETE:
|
||||
HandlePlayerDelete(packet);
|
||||
case SerialPacket::Type::CHARACTER_DELETE:
|
||||
HandleCharacterDelete(packet);
|
||||
break;
|
||||
//handle errors
|
||||
default:
|
||||
@@ -271,7 +271,7 @@ void InWorld::HandlePacket(SerialPacket packet) {
|
||||
void InWorld::HandleDisconnect(SerialPacket packet) {
|
||||
network.Unbind(Channels::SERVER);
|
||||
clientIndex = -1;
|
||||
playerIndex = -1;
|
||||
characterIndex = -1;
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
|
||||
@@ -285,34 +285,34 @@ void InWorld::HandleRegionContent(SerialPacket packet) {
|
||||
packet.regionInfo.region = nullptr;
|
||||
}
|
||||
|
||||
void InWorld::HandlePlayerUpdate(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.playerInfo.playerIndex) == playerCharacters.end()) {
|
||||
HandlePlayerNew(packet);
|
||||
void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
||||
HandleCharacterNew(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
//update only if the message didn't originate from here
|
||||
if (packet.playerInfo.clientIndex != clientIndex) {
|
||||
playerCharacters[packet.playerInfo.playerIndex].SetPosition(packet.playerInfo.position);
|
||||
playerCharacters[packet.playerInfo.playerIndex].SetMotion(packet.playerInfo.motion);
|
||||
if (packet.characterInfo.clientIndex != clientIndex) {
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
|
||||
}
|
||||
playerCharacters[packet.playerInfo.playerIndex].ResetDirection();
|
||||
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
|
||||
}
|
||||
|
||||
void InWorld::HandlePlayerNew(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.playerInfo.playerIndex) != playerCharacters.end()) {
|
||||
throw(std::runtime_error("Cannot create duplicate players"));
|
||||
void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.characterInfo.characterIndex) != playerCharacters.end()) {
|
||||
throw(std::runtime_error("Cannot create duplicate characters"));
|
||||
}
|
||||
|
||||
//TODO: set the handle
|
||||
playerCharacters[packet.playerInfo.playerIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.playerInfo.avatar, 4, 4);
|
||||
playerCharacters[packet.playerInfo.playerIndex].SetPosition(packet.playerInfo.position);
|
||||
playerCharacters[packet.playerInfo.playerIndex].SetMotion(packet.playerInfo.motion);
|
||||
playerCharacters[packet.playerInfo.playerIndex].ResetDirection();
|
||||
//TODO: set the player's handle
|
||||
playerCharacters[packet.characterInfo.characterIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4);
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
|
||||
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.playerInfo.playerIndex == playerIndex && !localCharacter) {
|
||||
localCharacter = &playerCharacters[playerIndex];
|
||||
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
||||
localCharacter = &playerCharacters[characterIndex];
|
||||
|
||||
//setup the camera
|
||||
camera.width = GetScreen()->w;
|
||||
@@ -323,16 +323,16 @@ void InWorld::HandlePlayerNew(SerialPacket packet) {
|
||||
}
|
||||
}
|
||||
|
||||
void InWorld::HandlePlayerDelete(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.playerInfo.playerIndex) == playerCharacters.end()) {
|
||||
throw(std::runtime_error("Cannot delete non-existant players"));
|
||||
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
||||
throw(std::runtime_error("Cannot delete non-existant characters"));
|
||||
}
|
||||
|
||||
playerCharacters.erase(packet.playerInfo.playerIndex);
|
||||
playerCharacters.erase(packet.characterInfo.characterIndex);
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.playerInfo.playerIndex == playerIndex) {
|
||||
playerIndex = -1;
|
||||
if (packet.characterInfo.characterIndex == characterIndex) {
|
||||
characterIndex = -1;
|
||||
localCharacter = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -346,11 +346,11 @@ void InWorld::SendPlayerUpdate() {
|
||||
char buffer[PACKET_BUFFER_SIZE];
|
||||
|
||||
//pack the packet
|
||||
packet.meta.type = SerialPacket::Type::PLAYER_UPDATE;
|
||||
packet.playerInfo.clientIndex = clientIndex;
|
||||
packet.playerInfo.playerIndex = playerIndex;
|
||||
packet.playerInfo.position = localCharacter->GetPosition();
|
||||
packet.playerInfo.motion = localCharacter->GetMotion();
|
||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||
packet.characterInfo.clientIndex = clientIndex;
|
||||
packet.characterInfo.characterIndex = characterIndex;
|
||||
packet.characterInfo.position = localCharacter->GetPosition();
|
||||
packet.characterInfo.motion = localCharacter->GetMotion();
|
||||
|
||||
serialize(&packet, buffer);
|
||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||
|
||||
@@ -74,9 +74,9 @@ protected:
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket);
|
||||
void HandleDisconnect(SerialPacket);
|
||||
void HandlePlayerNew(SerialPacket);
|
||||
void HandlePlayerDelete(SerialPacket);
|
||||
void HandlePlayerUpdate(SerialPacket);
|
||||
void HandleCharacterNew(SerialPacket);
|
||||
void HandleCharacterDelete(SerialPacket);
|
||||
void HandleCharacterUpdate(SerialPacket);
|
||||
void HandleRegionContent(SerialPacket);
|
||||
|
||||
//Server control
|
||||
@@ -92,7 +92,7 @@ protected:
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& playerIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//graphics
|
||||
Image buttonImage;
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argPlayerIndex):
|
||||
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
playerIndex(*argPlayerIndex)
|
||||
characterIndex(*argCharacterIndex)
|
||||
{
|
||||
//setup the utility objects
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
@@ -119,7 +119,7 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
|
||||
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
|
||||
}
|
||||
|
||||
//TODO: ping?
|
||||
//ping?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
|
||||
//pack the packet
|
||||
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
|
||||
strncpy(packet.clientInfo.player, config["client.player"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||
|
||||
@@ -221,7 +221,7 @@ void LobbyMenu::HandlePacket(SerialPacket packet) {
|
||||
break;
|
||||
case SerialPacket::Type::JOIN_RESPONSE:
|
||||
clientIndex = packet.clientInfo.clientIndex;
|
||||
playerIndex = packet.clientInfo.playerIndex;
|
||||
characterIndex = packet.clientInfo.characterIndex;
|
||||
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
break;
|
||||
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& playerIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
|
||||
Reference in New Issue
Block a user