Threaded the tables through the scenes

This commit is contained in:
Kayne Ruse
2014-05-27 23:59:42 +10:00
parent b86d393571
commit 967f0653a1
6 changed files with 48 additions and 17 deletions
+2 -2
View File
@@ -122,10 +122,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
break; break;
case SceneList::INWORLD: case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
break; break;
case SceneList::INCOMBAT: case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex); activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break; break;
default: default:
throw(std::logic_error("Failed to recognize the scene index")); throw(std::logic_error("Failed to recognize the scene index"));
+1 -1
View File
@@ -56,8 +56,8 @@ private:
int accountIndex = -1; int accountIndex = -1;
int characterIndex = -1; int characterIndex = -1;
std::map<int, CharacterData> characterMap;
std::map<int, CombatData> combatMap; std::map<int, CombatData> combatMap;
std::map<int, CharacterData> characterMap;
std::map<int, EnemyData> enemyMap; std::map<int, EnemyData> enemyMap;
}; };
+8 -2
View File
@@ -30,13 +30,19 @@ InCombat::InCombat(
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
): ):
config(*argConfig), config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex) characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
{ {
// //
} }
+11 -1
View File
@@ -36,6 +36,10 @@
#include "config_utility.hpp" #include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
@@ -47,7 +51,10 @@ public:
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
); );
~InCombat(); ~InCombat();
@@ -84,6 +91,9 @@ protected:
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int& characterIndex; int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics //graphics
//TODO: graphics //TODO: graphics
+20 -9
View File
@@ -36,13 +36,17 @@ InWorld::InWorld(
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
): ):
config(*argConfig), config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex) characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
{ {
//setup the utility objects //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
@@ -108,14 +112,21 @@ void InWorld::Update(double delta) {
//update the characters //update the characters
for (auto& it : playerCharacters) { for (auto& it : playerCharacters) {
it.second.Update(delta); if (it.second.motion.x && it.second.motion.y) {
//TODO: refactor this into a method
it.second.position += it.second.motion * CHARACTER_WALKING_SPEED * CHARACTER_WALKING_MOD;
}
else if (it.second.motion != 0) {
it.second.position += it.second.motion * CHARACTER_WALKING_SPEED;
}
//TODO: SPRITE: fix sprite
} }
//TODO: sort the players and entities by Y position //TODO: sort the players and entities by Y position
//update the camera //update the camera
if(localCharacter) { if(localCharacter) {
camera.x = localCharacter->GetPosition().x - camera.marginX; camera.x = localCharacter->position.x - camera.marginX;
camera.y = localCharacter->GetPosition().y - camera.marginY; camera.y = localCharacter->position.y - camera.marginY;
} }
//check the map //check the map
@@ -327,8 +338,8 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
camera.width = GetScreen()->w; camera.width = GetScreen()->w;
camera.height = GetScreen()->h; camera.height = GetScreen()->h;
//center on the player's character //center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite->GetImage()->GetClipH() / 2);
} }
} }
@@ -357,8 +368,8 @@ void InWorld::SendPlayerUpdate() {
packet.characterInfo.clientIndex = clientIndex; packet.characterInfo.clientIndex = clientIndex;
packet.characterInfo.accountIndex = accountIndex; packet.characterInfo.accountIndex = accountIndex;
packet.characterInfo.characterIndex = characterIndex; packet.characterInfo.characterIndex = characterIndex;
packet.characterInfo.position = localCharacter->GetPosition(); packet.characterInfo.position = localCharacter->position;
packet.characterInfo.motion = localCharacter->GetMotion(); packet.characterInfo.motion = localCharacter->motion;
serialize(&packet, buffer); serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
+6 -2
View File
@@ -42,8 +42,8 @@
#include "config_utility.hpp" #include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "character_data.hpp"
#include "combat_data.hpp" #include "combat_data.hpp"
#include "character_data.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
@@ -59,7 +59,9 @@ public:
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
); );
~InWorld(); ~InWorld();
@@ -102,6 +104,8 @@ protected:
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int& characterIndex; int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
//graphics //graphics
Image buttonImage; Image buttonImage;