Implemented client-side HandleCharacterCreate

This commit is contained in:
Kayne Ruse
2014-12-18 09:14:11 +11:00
parent ae046977f0
commit 015631a73d
6 changed files with 62 additions and 21 deletions
+5 -1
View File
@@ -21,6 +21,8 @@
*/
#include "base_character.hpp"
#include "config_utility.hpp"
//-------------------------
//graphics
//-------------------------
@@ -71,7 +73,9 @@ std::string BaseCharacter::GetHandle() const {
}
std::string BaseCharacter::SetAvatar(std::string s) {
return avatar = s;
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
return avatar;
}
std::string BaseCharacter::GetAvatar() const {
-8
View File
@@ -42,10 +42,6 @@ int Entity::SetEntityIndex(int i) {
return entityIndex = i;
}
int Entity::SetRoomIndex(int i) {
return roomIndex = i;
}
Vector2 Entity::SetOrigin(Vector2 v) {
return origin = v;
}
@@ -62,10 +58,6 @@ int Entity::GetEntityIndex() {
return entityIndex;
}
int Entity::GetRoomIndex() {
return roomIndex;
}
Vector2 Entity::GetOrigin() {
return origin;
}
-3
View File
@@ -36,13 +36,11 @@ public:
//accessors & mutators
int SetEntityIndex(int i);
int SetRoomIndex(int i);
Vector2 SetOrigin(Vector2 v);
Vector2 SetMotion(Vector2 v);
BoundingBox SetBounds(BoundingBox b);
int GetEntityIndex();
int GetRoomIndex();
Vector2 GetOrigin();
Vector2 GetMotion();
BoundingBox GetBounds();
@@ -53,7 +51,6 @@ protected:
SpriteSheet sprite;
int entityIndex = -1;
int roomIndex = -1;
Vector2 origin;
Vector2 motion;
BoundingBox bounds;
+47 -9
View File
@@ -96,7 +96,9 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
}
InWorld::~InWorld() {
//
//unload the local data
characterMap.clear();
monsterMap.clear();
}
//-------------------------
@@ -168,6 +170,16 @@ void InWorld::Render(SDL_Surface* const screen) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
}
//draw the entities
for (auto& it : characterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
@@ -328,8 +340,7 @@ void InWorld::SendShutdownRequest() {
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
accountIndex = -1;
//TODO: unload the character
characterIndex = -1;
SendDisconnectRequest();
}
@@ -340,7 +351,10 @@ void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
}
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
//TODO: More needed in the disconnection
//clear the local data
accountIndex = -1;
characterIndex = -1;
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
@@ -394,9 +408,36 @@ void InWorld::UpdateMap() {
}
}
//-------------------------
//entity management
//-------------------------
//NOTE: preexisting characters will result in query responses
//NOTE: new characters will result in create messages
//NOTE: this client's character will exist in both
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
//TODO: HandleCharacterCreate()
std::cout << "HandleCharacterCreate" << std::endl;
//prevent double message
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
std::ostringstream msg;
msg << "Double character creation event; ";
msg << "Index: " << argPacket->characterIndex << "; ";
msg << "Handle: " << argPacket->handle;
throw(std::runtime_error(msg.str()));
}
//implicity create and retrieve the entity
BaseCharacter& character = characterMap[argPacket->characterIndex];
//fill the character's info
character.SetOrigin({0, 0});
character.SetMotion({0, 0});
character.SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
character.SetHandle(argPacket->handle);
character.SetAvatar(argPacket->avatar);
//debug
std::cout << "Create, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
@@ -407,7 +448,4 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
//TODO: HandleCharacterQueryExists()
std::cout << "HandleCharacterQueryExists" << std::endl;
//NOTE: preexisting characters will result in query responses
//NOTE: new characters will result in create messages
//NOTE: this client's character will exist in both
}
+6
View File
@@ -44,6 +44,8 @@
//client
#include "base_scene.hpp"
#include "base_character.hpp"
#include "base_monster.hpp"
//STL
#include <map>
@@ -99,6 +101,7 @@ protected:
//indexes
int& clientIndex;
int& accountIndex;
int characterIndex = -1;
//graphics
Image buttonImage;
@@ -120,6 +123,9 @@ protected:
int marginX = 0, marginY = 0;
} camera;
//entities
std::map<int, BaseCharacter> characterMap;
std::map<int, BaseMonster> monsterMap;
//heartbeat
//TODO: Heartbeat needs it's own utility
+4
View File
@@ -35,4 +35,8 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
//the character's sprite format
constexpr int CHARACTER_CELLS_X = 4;
constexpr int CHARACTER_CELLS_Y = 4;
#endif