Added LocalCharacter, removed entityIndex
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
||||
std::string SetAvatar(std::string s);
|
||||
std::string GetAvatar() const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
//metadata
|
||||
int owner;
|
||||
std::string handle;
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
BaseMonster() = default;
|
||||
virtual ~BaseMonster() = default;
|
||||
|
||||
private:
|
||||
protected:
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
@@ -38,10 +38,6 @@ SpriteSheet* Entity::GetSprite() {
|
||||
//accessors & mutators
|
||||
//-------------------------
|
||||
|
||||
int Entity::SetEntityIndex(int i) {
|
||||
return entityIndex = i;
|
||||
}
|
||||
|
||||
Vector2 Entity::SetOrigin(Vector2 v) {
|
||||
return origin = v;
|
||||
}
|
||||
@@ -54,10 +50,6 @@ BoundingBox Entity::SetBounds(BoundingBox b) {
|
||||
return bounds = b;
|
||||
}
|
||||
|
||||
int Entity::GetEntityIndex() {
|
||||
return entityIndex;
|
||||
}
|
||||
|
||||
Vector2 Entity::GetOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,10 @@ public:
|
||||
SpriteSheet* GetSprite();
|
||||
|
||||
//accessors & mutators
|
||||
int SetEntityIndex(int i);
|
||||
Vector2 SetOrigin(Vector2 v);
|
||||
Vector2 SetMotion(Vector2 v);
|
||||
BoundingBox SetBounds(BoundingBox b);
|
||||
|
||||
int GetEntityIndex();
|
||||
Vector2 GetOrigin();
|
||||
Vector2 GetMotion();
|
||||
BoundingBox GetBounds();
|
||||
@@ -50,7 +48,6 @@ protected:
|
||||
virtual ~Entity() = default;
|
||||
|
||||
SpriteSheet sprite;
|
||||
int entityIndex = -1;
|
||||
Vector2 origin;
|
||||
Vector2 motion;
|
||||
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;
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
|
||||
//set the camera's values
|
||||
camera.width = GetScreen()->w;
|
||||
camera.height = GetScreen()->h;
|
||||
|
||||
//debug
|
||||
//
|
||||
}
|
||||
@@ -133,6 +137,14 @@ void InWorld::Update() {
|
||||
//update the map
|
||||
UpdateMap();
|
||||
|
||||
//update all entities
|
||||
for (auto& it : characterMap) {
|
||||
it.second.Update();
|
||||
}
|
||||
for (auto& it : monsterMap) {
|
||||
it.second.Update();
|
||||
}
|
||||
|
||||
//check the connection (heartbeat)
|
||||
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||
if (attemptedBeats > 2) {
|
||||
@@ -342,6 +354,10 @@ void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
||||
accountIndex = -1;
|
||||
characterIndex = -1;
|
||||
|
||||
//reset the camera
|
||||
camera.x = camera .y = 0;
|
||||
camera.marginX = camera.marginY = 0;
|
||||
|
||||
SendDisconnectRequest();
|
||||
}
|
||||
|
||||
@@ -355,6 +371,10 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
||||
accountIndex = -1;
|
||||
characterIndex = -1;
|
||||
|
||||
//reset the camera
|
||||
camera.x = camera .y = 0;
|
||||
camera.marginX = camera.marginY = 0;
|
||||
|
||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||
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: 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) {
|
||||
//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->SetHandle(argPacket->handle);
|
||||
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
|
||||
std::cout << "Create, total: " << characterMap.size() << std::endl;
|
||||
@@ -453,7 +479,14 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||
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
|
||||
characterMap.erase(characterIt);
|
||||
@@ -463,6 +496,11 @@ void InWorld::HandleCharacterDelete(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
|
||||
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->SetHandle(argPacket->handle);
|
||||
character->SetAvatar(argPacket->avatar);
|
||||
character->SetOwner(argPacket->accountIndex);
|
||||
|
||||
//debug
|
||||
std::cout << "Query, total: " << characterMap.size() << std::endl;
|
||||
|
||||
@@ -39,13 +39,10 @@
|
||||
//common
|
||||
#include "frame_rate.hpp"
|
||||
|
||||
#include "base_character.hpp"
|
||||
#include "base_monster.hpp"
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
#include "base_character.hpp"
|
||||
#include "base_monster.hpp"
|
||||
#include "local_character.hpp"
|
||||
|
||||
//STL
|
||||
#include <map>
|
||||
@@ -126,6 +123,7 @@ protected:
|
||||
//entities
|
||||
std::map<int, BaseCharacter> characterMap;
|
||||
std::map<int, BaseMonster> monsterMap;
|
||||
LocalCharacter* localCharacter = nullptr;
|
||||
|
||||
//heartbeat
|
||||
//TODO: Heartbeat needs it's own utility
|
||||
|
||||
@@ -21,10 +21,6 @@
|
||||
*/
|
||||
#include "entity.hpp"
|
||||
|
||||
int Entity::SetEntityIndex(int i) {
|
||||
return entityIndex = i;
|
||||
}
|
||||
|
||||
int Entity::SetRoomIndex(int i) {
|
||||
return roomIndex = i;
|
||||
}
|
||||
@@ -36,9 +32,6 @@ Vector2 Entity::SetOrigin(Vector2 v) {
|
||||
Vector2 Entity::SetMotion(Vector2 v) {
|
||||
return motion = v;
|
||||
}
|
||||
int Entity::GetEntityIndex() {
|
||||
return entityIndex;
|
||||
}
|
||||
|
||||
int Entity::GetRoomIndex() {
|
||||
return roomIndex;
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
class Entity {
|
||||
public:
|
||||
//accessors & mutators
|
||||
int SetEntityIndex(int i);
|
||||
int SetRoomIndex(int i);
|
||||
Vector2 SetOrigin(Vector2 v);
|
||||
Vector2 SetMotion(Vector2 v);
|
||||
|
||||
int GetEntityIndex();
|
||||
int GetRoomIndex();
|
||||
Vector2 GetOrigin();
|
||||
Vector2 GetMotion();
|
||||
@@ -42,7 +40,6 @@ protected:
|
||||
Entity() = default;
|
||||
~Entity() = default;
|
||||
|
||||
int entityIndex = -1;
|
||||
int roomIndex = -1;
|
||||
Vector2 origin;
|
||||
Vector2 motion;
|
||||
|
||||
Reference in New Issue
Block a user