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);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex);
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex);
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
+1 -1
View File
@@ -56,8 +56,8 @@ private:
int accountIndex = -1;
int characterIndex = -1;
std::map<int, CharacterData> characterMap;
std::map<int, CombatData> combatMap;
std::map<int, CharacterData> characterMap;
std::map<int, EnemyData> enemyMap;
};
+8 -2
View File
@@ -30,13 +30,19 @@ InCombat::InCombat(
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
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),
network(*argNetwork),
clientIndex(*argClientIndex),
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 "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client
#include "base_scene.hpp"
@@ -47,7 +51,10 @@ public:
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
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();
@@ -84,6 +91,9 @@ protected:
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics
//TODO: graphics
+20 -9
View File
@@ -36,13 +36,17 @@ InWorld::InWorld(
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex)
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
@@ -108,14 +112,21 @@ void InWorld::Update(double delta) {
//update the characters
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
//update the camera
if(localCharacter) {
camera.x = localCharacter->GetPosition().x - camera.marginX;
camera.y = localCharacter->GetPosition().y - camera.marginY;
camera.x = localCharacter->position.x - camera.marginX;
camera.y = localCharacter->position.y - camera.marginY;
}
//check the map
@@ -327,8 +338,8 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite->GetImage()->GetClipH() / 2);
}
}
@@ -357,8 +368,8 @@ void InWorld::SendPlayerUpdate() {
packet.characterInfo.clientIndex = clientIndex;
packet.characterInfo.accountIndex = accountIndex;
packet.characterInfo.characterIndex = characterIndex;
packet.characterInfo.position = localCharacter->GetPosition();
packet.characterInfo.motion = localCharacter->GetMotion();
packet.characterInfo.position = localCharacter->position;
packet.characterInfo.motion = localCharacter->motion;
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
+6 -2
View File
@@ -42,8 +42,8 @@
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "character_data.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
//client
#include "base_scene.hpp"
@@ -59,7 +59,9 @@ public:
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
);
~InWorld();
@@ -102,6 +104,8 @@ protected:
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
//graphics
Image buttonImage;