Added LocalCharacter, removed entityIndex
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
|||||||
std::string SetAvatar(std::string s);
|
std::string SetAvatar(std::string s);
|
||||||
std::string GetAvatar() const;
|
std::string GetAvatar() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
//metadata
|
//metadata
|
||||||
int owner;
|
int owner;
|
||||||
std::string handle;
|
std::string handle;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public:
|
|||||||
BaseMonster() = default;
|
BaseMonster() = default;
|
||||||
virtual ~BaseMonster() = default;
|
virtual ~BaseMonster() = default;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,6 @@ SpriteSheet* Entity::GetSprite() {
|
|||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
int Entity::SetEntityIndex(int i) {
|
|
||||||
return entityIndex = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 Entity::SetOrigin(Vector2 v) {
|
Vector2 Entity::SetOrigin(Vector2 v) {
|
||||||
return origin = v;
|
return origin = v;
|
||||||
}
|
}
|
||||||
@@ -54,10 +50,6 @@ BoundingBox Entity::SetBounds(BoundingBox b) {
|
|||||||
return bounds = b;
|
return bounds = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Entity::GetEntityIndex() {
|
|
||||||
return entityIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 Entity::GetOrigin() {
|
Vector2 Entity::GetOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,10 @@ public:
|
|||||||
SpriteSheet* GetSprite();
|
SpriteSheet* GetSprite();
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
int SetEntityIndex(int i);
|
|
||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
BoundingBox SetBounds(BoundingBox b);
|
BoundingBox SetBounds(BoundingBox b);
|
||||||
|
|
||||||
int GetEntityIndex();
|
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin();
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion();
|
||||||
BoundingBox GetBounds();
|
BoundingBox GetBounds();
|
||||||
@@ -50,7 +48,6 @@ protected:
|
|||||||
virtual ~Entity() = default;
|
virtual ~Entity() = default;
|
||||||
|
|
||||||
SpriteSheet sprite;
|
SpriteSheet sprite;
|
||||||
int entityIndex = -1;
|
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
BoundingBox bounds;
|
BoundingBox bounds;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "local_character.hpp"
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef LOCALCHARACTER_HPP_
|
||||||
|
#define LOCALCHARACTER_HPP_
|
||||||
|
|
||||||
|
#include "base_character.hpp"
|
||||||
|
|
||||||
|
class LocalCharacter: public BaseCharacter {
|
||||||
|
public:
|
||||||
|
//
|
||||||
|
private:
|
||||||
|
//NOTE: NO MEMBERS
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -91,6 +91,10 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
|
||||||
|
//set the camera's values
|
||||||
|
camera.width = GetScreen()->w;
|
||||||
|
camera.height = GetScreen()->h;
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -133,6 +137,14 @@ void InWorld::Update() {
|
|||||||
//update the map
|
//update the map
|
||||||
UpdateMap();
|
UpdateMap();
|
||||||
|
|
||||||
|
//update all entities
|
||||||
|
for (auto& it : characterMap) {
|
||||||
|
it.second.Update();
|
||||||
|
}
|
||||||
|
for (auto& it : monsterMap) {
|
||||||
|
it.second.Update();
|
||||||
|
}
|
||||||
|
|
||||||
//check the connection (heartbeat)
|
//check the connection (heartbeat)
|
||||||
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||||
if (attemptedBeats > 2) {
|
if (attemptedBeats > 2) {
|
||||||
@@ -342,6 +354,10 @@ void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
|||||||
accountIndex = -1;
|
accountIndex = -1;
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
|
|
||||||
|
//reset the camera
|
||||||
|
camera.x = camera .y = 0;
|
||||||
|
camera.marginX = camera.marginY = 0;
|
||||||
|
|
||||||
SendDisconnectRequest();
|
SendDisconnectRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +371,10 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
|||||||
accountIndex = -1;
|
accountIndex = -1;
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
|
|
||||||
|
//reset the camera
|
||||||
|
camera.x = camera .y = 0;
|
||||||
|
camera.marginX = camera.marginY = 0;
|
||||||
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
||||||
}
|
}
|
||||||
@@ -414,7 +434,7 @@ void InWorld::UpdateMap() {
|
|||||||
|
|
||||||
//NOTE: preexisting characters will result in query responses
|
//NOTE: preexisting characters will result in query responses
|
||||||
//NOTE: new characters will result in create messages
|
//NOTE: new characters will result in create messages
|
||||||
//NOTE: this client's character will exist in both
|
//NOTE: this client's character will exist in both (skipped)
|
||||||
|
|
||||||
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
||||||
//prevent double message
|
//prevent double message
|
||||||
@@ -435,10 +455,16 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
|||||||
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
||||||
character->SetHandle(argPacket->handle);
|
character->SetHandle(argPacket->handle);
|
||||||
character->SetAvatar(argPacket->avatar);
|
character->SetAvatar(argPacket->avatar);
|
||||||
|
character->SetOwner(argPacket->accountIndex);
|
||||||
|
|
||||||
//TODO: check for this player's character
|
//check for this player's character
|
||||||
|
if (character->GetOwner() == accountIndex) {
|
||||||
|
localCharacter = static_cast<LocalCharacter*>(character);
|
||||||
|
|
||||||
//TODO: setup the camera
|
//focus the camera on this character
|
||||||
|
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
||||||
|
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
std::cout << "Create, total: " << characterMap.size() << std::endl;
|
std::cout << "Create, total: " << characterMap.size() << std::endl;
|
||||||
@@ -453,7 +479,14 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: check for this player's character
|
//check for this player's character
|
||||||
|
if ((*characterIt).second.GetOwner() == accountIndex) {
|
||||||
|
localCharacter = nullptr;
|
||||||
|
|
||||||
|
//clear the camera
|
||||||
|
camera.marginX = 0;
|
||||||
|
camera.marginY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//remove this character
|
//remove this character
|
||||||
characterMap.erase(characterIt);
|
characterMap.erase(characterIt);
|
||||||
@@ -463,6 +496,11 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
||||||
|
//prevent a double message about this player's character
|
||||||
|
if (argPacket->accountIndex == accountIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//implicitly construct the character if it doesn't exist
|
//implicitly construct the character if it doesn't exist
|
||||||
BaseCharacter* character = &characterMap[argPacket->characterIndex];
|
BaseCharacter* character = &characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
@@ -472,6 +510,7 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
|||||||
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
||||||
character->SetHandle(argPacket->handle);
|
character->SetHandle(argPacket->handle);
|
||||||
character->SetAvatar(argPacket->avatar);
|
character->SetAvatar(argPacket->avatar);
|
||||||
|
character->SetOwner(argPacket->accountIndex);
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
std::cout << "Query, total: " << characterMap.size() << std::endl;
|
std::cout << "Query, total: " << characterMap.size() << std::endl;
|
||||||
|
|||||||
@@ -39,13 +39,10 @@
|
|||||||
//common
|
//common
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "base_character.hpp"
|
|
||||||
#include "base_monster.hpp"
|
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "base_character.hpp"
|
|
||||||
#include "base_monster.hpp"
|
#include "base_monster.hpp"
|
||||||
|
#include "local_character.hpp"
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -126,6 +123,7 @@ protected:
|
|||||||
//entities
|
//entities
|
||||||
std::map<int, BaseCharacter> characterMap;
|
std::map<int, BaseCharacter> characterMap;
|
||||||
std::map<int, BaseMonster> monsterMap;
|
std::map<int, BaseMonster> monsterMap;
|
||||||
|
LocalCharacter* localCharacter = nullptr;
|
||||||
|
|
||||||
//heartbeat
|
//heartbeat
|
||||||
//TODO: Heartbeat needs it's own utility
|
//TODO: Heartbeat needs it's own utility
|
||||||
|
|||||||
@@ -21,10 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
|
||||||
int Entity::SetEntityIndex(int i) {
|
|
||||||
return entityIndex = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Entity::SetRoomIndex(int i) {
|
int Entity::SetRoomIndex(int i) {
|
||||||
return roomIndex = i;
|
return roomIndex = i;
|
||||||
}
|
}
|
||||||
@@ -36,9 +32,6 @@ Vector2 Entity::SetOrigin(Vector2 v) {
|
|||||||
Vector2 Entity::SetMotion(Vector2 v) {
|
Vector2 Entity::SetMotion(Vector2 v) {
|
||||||
return motion = v;
|
return motion = v;
|
||||||
}
|
}
|
||||||
int Entity::GetEntityIndex() {
|
|
||||||
return entityIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Entity::GetRoomIndex() {
|
int Entity::GetRoomIndex() {
|
||||||
return roomIndex;
|
return roomIndex;
|
||||||
|
|||||||
@@ -28,12 +28,10 @@
|
|||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
int SetEntityIndex(int i);
|
|
||||||
int SetRoomIndex(int i);
|
int SetRoomIndex(int i);
|
||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
|
|
||||||
int GetEntityIndex();
|
|
||||||
int GetRoomIndex();
|
int GetRoomIndex();
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin();
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion();
|
||||||
@@ -42,7 +40,6 @@ protected:
|
|||||||
Entity() = default;
|
Entity() = default;
|
||||||
~Entity() = default;
|
~Entity() = default;
|
||||||
|
|
||||||
int entityIndex = -1;
|
|
||||||
int roomIndex = -1;
|
int roomIndex = -1;
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
|
|||||||
Reference in New Issue
Block a user