Compare commits

..

2 Commits

Author SHA1 Message Date
Kayne Ruse fdaae0e8f2 Problems with lambdas and references 2014-11-26 04:21:30 +11:00
Kayne Ruse bd3838a04e IDK what the fuck is going on, too tired to think
OK, so I think I was working on the parameters for CreateRoom() in lua,
but then shit just got ot of control. IDK, I'm probably going about this
all wrong anyway. I just want to finish this stage, and reach the high
water mark again.
2014-11-24 05:43:38 +11:00
133 changed files with 1105 additions and 1685 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+4 -4
View File
@@ -1,11 +1,11 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial ClientApplications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
@@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) {
//load the prerequisites //load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc/config.cfg", false, argc, argv); config.Load("rsc/config.cfg", argc, argv);
//------------------------- //-------------------------
//Initialize the APIs //Initialize the APIs
@@ -178,7 +178,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu(); activeScene = new OptionsMenu();
break; break;
case SceneList::LOBBYMENU: case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&clientIndex, &accountIndex); activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters?
break; break;
case SceneList::INWORLD: case SceneList::INWORLD:
activeScene = new InWorld(&clientIndex, &accountIndex); activeScene = new InWorld(&clientIndex, &accountIndex);
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
-37
View File
@@ -1,37 +0,0 @@
#config
INCLUDES+=.
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,client.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -1,23 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "terminal_error.hpp"
@@ -1,34 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 TERMINALERROR_HPP_
#define TERMINALERROR_HPP_
#include <stdexcept>
#include <string>
class terminal_error: public std::runtime_error {
public:
explicit terminal_error(const std::string& str): runtime_error(str) {}
explicit terminal_error(const char* cstr): runtime_error(cstr) {}
};
#endif
+1 -37
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -21,12 +21,6 @@
*/ */
#include "base_character.hpp" #include "base_character.hpp"
#include "config_utility.hpp"
//-------------------------
//graphics
//-------------------------
void BaseCharacter::CorrectSprite() { void BaseCharacter::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use //NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) { if (motion.y > 0) {
@@ -51,33 +45,3 @@ void BaseCharacter::CorrectSprite() {
sprite.SetXIndex(0); sprite.SetXIndex(0);
} }
} }
//-------------------------
//metadata
//-------------------------
int BaseCharacter::SetOwner(int i) {
return owner = i;
}
int BaseCharacter::GetOwner() {
return owner;
}
std::string BaseCharacter::SetHandle(std::string s) {
return handle = s;
}
std::string BaseCharacter::GetHandle() const {
return handle;
}
std::string BaseCharacter::SetAvatar(std::string s) {
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
return avatar;
}
std::string BaseCharacter::GetAvatar() const {
return avatar;
}
+9 -9
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,7 @@
//std namespace //std namespace
#include <string> #include <string>
class BaseCharacter: public Entity { class BaseCharacter : public Entity {
public: public:
BaseCharacter() = default; BaseCharacter() = default;
virtual ~BaseCharacter() = default; virtual ~BaseCharacter() = default;
@@ -38,14 +38,14 @@ public:
void CorrectSprite(); void CorrectSprite();
//metadata //metadata
int SetOwner(int i); int SetOwner(int i) { return owner = i; }
int GetOwner(); int GetOwner() { return owner; }
std::string SetHandle(std::string s); std::string SetHandle(std::string s) { return handle = s; }
std::string GetHandle() const; std::string GetHandle() const { return handle; }
std::string SetAvatar(std::string s); std::string SetAvatar(std::string s) { return avatar = s; }
std::string GetAvatar() const; std::string GetAvatar() const { return avatar; }
protected: private:
//metadata //metadata
int owner; int owner;
std::string handle; std::string handle;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,12 +24,12 @@
#include "entity.hpp" #include "entity.hpp"
class BaseMonster: public Entity { class BaseMonster : public Entity {
public: public:
BaseMonster() = default; BaseMonster() = default;
virtual ~BaseMonster() = default; virtual ~BaseMonster() = default;
protected: private:
// //
}; };
+11 -12
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -30,13 +30,13 @@ void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY); sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
} }
SpriteSheet* Entity::GetSprite() { int Entity::SetEntityIndex(int i) {
return &sprite; return entityIndex = i;
} }
//------------------------- int Entity::SetRoomIndex(int i) {
//accessors & mutators return roomIndex = i;
//------------------------- }
Vector2 Entity::SetOrigin(Vector2 v) { Vector2 Entity::SetOrigin(Vector2 v) {
return origin = v; return origin = v;
@@ -45,9 +45,12 @@ 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;
}
BoundingBox Entity::SetBounds(BoundingBox b) { int Entity::GetRoomIndex() {
return bounds = b; return roomIndex;
} }
Vector2 Entity::GetOrigin() { Vector2 Entity::GetOrigin() {
@@ -57,7 +60,3 @@ Vector2 Entity::GetOrigin() {
Vector2 Entity::GetMotion() { Vector2 Entity::GetMotion() {
return motion; return motion;
} }
BoundingBox Entity::GetBounds() {
return bounds;
}
+11 -5
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -32,22 +32,28 @@ public:
virtual void Update(); virtual void Update();
virtual void DrawTo(SDL_Surface* const, int camX, int camY); virtual void DrawTo(SDL_Surface* const, int camX, int camY);
SpriteSheet* GetSprite(); SpriteSheet* GetSprite() { return &sprite; }
//accessors & mutators //accessors & mutators
int SetEntityIndex(int i);
int SetRoomIndex(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) { return bounds = b; }
int GetEntityIndex();
int GetRoomIndex();
Vector2 GetOrigin(); Vector2 GetOrigin();
Vector2 GetMotion(); Vector2 GetMotion();
BoundingBox GetBounds(); BoundingBox GetBounds() { return bounds; }
protected: protected:
Entity() = default; Entity() = default;
virtual ~Entity() = default; ~Entity() = default;
SpriteSheet sprite; SpriteSheet sprite;
int entityIndex = -1;
int roomIndex = -1;
Vector2 origin; Vector2 origin;
Vector2 motion; Vector2 motion;
BoundingBox bounds; BoundingBox bounds;
-35
View File
@@ -1,35 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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"
#include <iostream>
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
for(auto& box : boxList) {
if (box.CheckOverlap(origin + bounds)) {
origin -= motion;
motion = {0, 0};
return true;
}
}
return false;
}
-42
View File
@@ -1,42 +0,0 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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"
#include "bounding_box.hpp"
#include "vector2.hpp"
#include <list>
class LocalCharacter: public BaseCharacter {
public:
LocalCharacter() = default;
virtual ~LocalCharacter() = default;
bool ProcessCollisionGrid(std::list<BoundingBox>);
private:
//NOTE: NO MEMBERS
};
#endif
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
ConfigUtility::CreateSingleton(); ConfigUtility::CreateSingleton();
UDPNetworkUtility::CreateSingleton(); UDPNetworkUtility::CreateSingleton();
//call the client's routines //call the server's routines
ClientApplication::CreateSingleton(); ClientApplication::CreateSingleton();
ClientApplication& app = ClientApplication::GetSingleton(); ClientApplication& app = ClientApplication::GetSingleton();
+1 -2
View File
@@ -1,5 +1,5 @@
#include directories #include directories
INCLUDES+=. client_utilities entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
#libraries #libraries
#the order of the $(LIBS) is important, at least for MinGW #the order of the $(LIBS) is important, at least for MinGW
@@ -25,7 +25,6 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities
$(MAKE) -C entities $(MAKE) -C entities
$(MAKE) -C scenes $(MAKE) -C scenes
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+287 -484
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,25 +23,12 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include "config_utility.hpp"
#include "terminal_error.hpp"
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <sstream>
//-------------------------
//these should've come standard
//-------------------------
bool operator==(IPaddress lhs, IPaddress rhs) {
return lhs.host == rhs.host && lhs.port == rhs.port;
}
bool operator!=(IPaddress lhs, IPaddress rhs) {
return !(lhs == rhs);
}
//------------------------- //-------------------------
//Public access members //Public access members
@@ -51,6 +38,8 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex) accountIndex(*argAccountIndex)
{ {
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3); buttonImage.SetClipH(buttonImage.GetClipH()/3);
@@ -73,36 +62,27 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
shutDownButton.SetText("Shut Down"); shutDownButton.SetText("Shut Down");
//load the tilesheet //load the tilesheet
//TODO: add the tilesheet to the map system //TODO: add the tilesheet to the map system?
//TODO: Tile size and tile sheet should be loaded elsewhere //TODO: Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//Send the character data //send this player's character info
//TODO: login scene, prompt, etc. // CharacterPacket newPacket;
CharacterPacket newPacket; // newPacket.type = SerialPacketType::CHARACTER_NEW;
newPacket.type = SerialPacketType::CHARACTER_LOAD; // strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); // strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); // newPacket.accountIndex = accountIndex;
newPacket.accountIndex = accountIndex; // network.SendTo(Channels::SERVER, &newPacket);
network.SendTo(Channels::SERVER, &newPacket);
//query the world state //request a sync
memset(&newPacket, 0, MAX_PACKET_SIZE); // RequestSynchronize();
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 //debug
// //
} }
InWorld::~InWorld() { InWorld::~InWorld() {
//unload the local data //
characterMap.clear();
monsterMap.clear();
} }
//------------------------- //-------------------------
@@ -114,57 +94,69 @@ void InWorld::FrameStart() {
} }
void InWorld::Update() { void InWorld::Update() {
//create and zero the buffer //suck in and process all waiting packets
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]); SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
memset(packetBuffer, 0, MAX_PACKET_SIZE); while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
try {
//suck in and process all waiting packets
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
} }
catch(terminal_error& e) {
throw(e);
}
catch(std::exception& e) {
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
}
//free the buffer
delete reinterpret_cast<char*>(packetBuffer); delete reinterpret_cast<char*>(packetBuffer);
//heartbeat system //update the characters
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) { for (auto& it : characterMap) {
it.second.Update(); it.second.Update();
} }
for (auto& it : monsterMap) {
it.second.Update();
}
//update the map //check the map
UpdateMap(); UpdateMap();
//skip the rest without a local character //skip the rest
if (!localCharacter) { if (!localCharacter) {
return; return;
} }
//get the collidable boxes //check for collisions with the map
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH()); BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
//process the collisions for (int i = -1; i <= xCount; ++i) {
if (localCharacter->ProcessCollisionGrid(boxList)) { for (int j = -1; j <= yCount; ++j) {
localCharacter->CorrectSprite(); //set the wall's position
SendLocalCharacterMotion(); wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue;
}
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion()));
localCharacter->SetMotion({0,0});
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
}
} }
//update the camera //update the camera (following the player)
camera.x = localCharacter->GetOrigin().x - camera.marginX; camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY; camera.y = localCharacter->GetOrigin().y - camera.marginY;
//check the connection
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
RequestDisconnect();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
} }
void InWorld::FrameEnd() { void InWorld::FrameEnd() {
@@ -172,7 +164,7 @@ void InWorld::FrameEnd() {
} }
void InWorld::RenderFrame() { void InWorld::RenderFrame() {
SDL_FillRect(GetScreen(), 0, 0); // SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen()); Render(GetScreen());
SDL_Flip(GetScreen()); SDL_Flip(GetScreen());
fps.Calculate(); fps.Calculate();
@@ -184,13 +176,10 @@ void InWorld::Render(SDL_Surface* const screen) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
} }
//draw the entities //draw characters
for (auto& it : characterMap) { for (auto& it : characterMap) {
//TODO: depth ordering //BUG: #29 drawing order according to Y origin
it.second.DrawTo(screen, camera.x, camera.y); //TODO: use a list of renderable objects
}
for (auto& it : monsterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y); it.second.DrawTo(screen, camera.x, camera.y);
} }
@@ -205,8 +194,8 @@ void InWorld::Render(SDL_Surface* const screen) {
//------------------------- //-------------------------
void InWorld::QuitEvent() { void InWorld::QuitEvent() {
//two-step logout //exit the game AND the server
SendDisconnectRequest(); RequestDisconnect();
SetNextScene(SceneList::QUIT); SetNextScene(SceneList::QUIT);
} }
@@ -222,281 +211,231 @@ void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) { void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendLogoutRequest(); RequestDisconnect();
} }
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendShutdownRequest(); RequestShutDown();
} }
} }
void InWorld::KeyDown(SDL_KeyboardEvent const& key) { void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//hotkeys //hotkeys
switch(key.keysym.sym) { switch(key.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
//TODO: the escape key should actually control menus and stuff RequestDisconnect();
SendLogoutRequest(); break;
return;
} }
//character movement //player movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion(); Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) { switch(key.keysym.sym) {
case SDLK_w: case SDLK_LEFT:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_a:
motion.x -= CHARACTER_WALKING_SPEED; motion.x -= CHARACTER_WALKING_SPEED;
break; break;
case SDLK_s: case SDLK_RIGHT:
motion.y += CHARACTER_WALKING_SPEED;
break;
case SDLK_d:
motion.x += CHARACTER_WALKING_SPEED; motion.x += CHARACTER_WALKING_SPEED;
break; break;
case SDLK_UP:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_DOWN:
motion.y += CHARACTER_WALKING_SPEED;
break;
default: default:
//DOCS: prevents wrong keys screwing with character movement
return; return;
} }
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendPlayerUpdate();
} }
void InWorld::KeyUp(SDL_KeyboardEvent const& key) { void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
//character movement
if (!localCharacter) { if (!localCharacter) {
return; return;
} }
//player movement
Vector2 motion = localCharacter->GetMotion(); Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) { switch(key.keysym.sym) {
case SDLK_w: //NOTE: The use of min/max here are to prevent awkward movements
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED); case SDLK_LEFT:
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
break; break;
case SDLK_a: case SDLK_RIGHT:
motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED); motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
break; break;
case SDLK_s: case SDLK_UP:
motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED); motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
break; break;
case SDLK_d: case SDLK_DOWN:
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
break; break;
default: default:
//DOCS: prevents wrong keys screwing with character movement
return; return;
} }
//BUGFIX: reset cardinal direction speed on key release
if (motion.x > 0) {
motion.x = CHARACTER_WALKING_SPEED;
}
else if (motion.x < 0) {
motion.x = -CHARACTER_WALKING_SPEED;
}
if (motion.y > 0) {
motion.y = CHARACTER_WALKING_SPEED;
}
else if (motion.y < 0) {
motion.y = -CHARACTER_WALKING_SPEED;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendPlayerUpdate();
} }
//------------------------- //-------------------------
//Basic connections //Network handlers
//------------------------- //-------------------------
void InWorld::HandlePacket(SerialPacket* const argPacket) { void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) { switch(argPacket->type) {
//heartbeat system //heartbeat system
case SerialPacketType::PING: case SerialPacketType::PING: {
HandlePing(static_cast<ServerPacket*>(argPacket)); ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
break; break;
case SerialPacketType::PONG: case SerialPacketType::PONG:
HandlePong(static_cast<ServerPacket*>(argPacket)); // HandlePong(static_cast<ServerPacket*>(argPacket));
break; break;
//game server connections //game server connections
case SerialPacketType::LOGOUT_RESPONSE: case SerialPacketType::LOGOUT_RESPONSE:
HandleLogoutResponse(static_cast<ClientPacket*>(argPacket)); // HandleLogoutResponse(static_cast<ClientPacket*>(argPacket));
break; break;
case SerialPacketType::DISCONNECT_RESPONSE: case SerialPacketType::DISCONNECT_REQUEST:
HandleDisconnectResponse(static_cast<ClientPacket*>(argPacket)); // HandleDisconnectRequest(static_cast<ClientPacket*>(argPacket));
break; break;
case SerialPacketType::DISCONNECT_FORCED: case SerialPacketType::DISCONNECT_FORCED:
HandleDisconnectForced(static_cast<ClientPacket*>(argPacket)); // HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
break; break;
//map management //data management
case SerialPacketType::REGION_CONTENT: case SerialPacketType::REGION_CONTENT:
HandleRegionContent(static_cast<RegionPacket*>(argPacket)); // HandleRegionContent(static_cast<RegionPacket*>(argPacket));
break; break;
// case SerialPacketType::QUERY_CHARACTER_EXISTS:
// case SerialPacketType::QUERY_CHARACTER_STATS:
// case SerialPacketType::QUERY_CHARACTER_LOCATION:
//character management //character management
case SerialPacketType::CHARACTER_CREATE: // case SerialPacketType::CHARACTER_NEW:
HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket)); // HandleCharacterNew(static_cast<CharacterPacket*>(argPacket));
break; // break;
case SerialPacketType::CHARACTER_DELETE: // case SerialPacketType::CHARACTER_DELETE:
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket)); // HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break; // break;
case SerialPacketType::QUERY_CHARACTER_EXISTS: // case SerialPacketType::CHARACTER_UPDATE:
HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket)); // HandleCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
break; // break;
// case SerialPacketType::CHARACTER_REJECTION:
// HandleCharacterRejection(static_cast<TextPacket*>(argPacket));
// break;
//character movement //enemy management
case SerialPacketType::CHARACTER_SET_ROOM: //TODO: enemy management
HandleCharacterSetRoom(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_ORIGIN:
HandleCharacterSetOrigin(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_MOTION:
HandleCharacterSetMotion(static_cast<CharacterPacket*>(argPacket));
break;
//rejection messages //TODO: text
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
break;
case SerialPacketType::SHUTDOWN_REJECTION:
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
break;
//errors //handle errors
default: { default:
std::ostringstream msg; throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break; break;
} }
} }
void InWorld::HandlePing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void InWorld::HandlePong(ServerPacket* const argPacket) { void InWorld::HandlePong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) { if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) {
throw(std::runtime_error("Heartbeat message received from an unknown source")); throw(std::runtime_error("Heartbeat message received from an unknown source"));
} }
attemptedBeats = 0; attemptedBeats = 0;
lastBeat = Clock::now(); lastBeat = Clock::now();
} }
//------------------------- void InWorld::HandleDisconnect(ClientPacket* const argPacket) {
//Connection control //TODO: More needed in the disconnection
//------------------------- SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected";
void InWorld::SendLogoutRequest() {
ClientPacket newPacket;
//send a logout request
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
} }
void InWorld::SendDisconnectRequest() { void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
ClientPacket newPacket; if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
throw(std::runtime_error("Cannot create duplicate characters"));
}
//send a disconnect request //create the character object
newPacket.type = SerialPacketType::DISCONNECT_REQUEST; BaseCharacter& newCharacter = characterMap[argPacket->characterIndex];
newPacket.clientIndex = clientIndex;
network.SendTo(Channels::SERVER, &newPacket); //fill out the character's members
newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar);
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
newCharacter.SetBounds({
CHARACTER_BOUNDS_X,
CHARACTER_BOUNDS_Y,
CHARACTER_BOUNDS_WIDTH,
CHARACTER_BOUNDS_HEIGHT
});
// (*newCharacter.GetBaseStats()) = argPacket->stats;
//bookkeeping code
newCharacter.CorrectSprite();
//catch this client's player object
if (argPacket->accountIndex == accountIndex && !localCharacter) {
characterIndex = argPacket->characterIndex;
localCharacter = &newCharacter;
//setup the camera
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);
}
} }
void InWorld::SendShutdownRequest() { void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
ClientPacket newPacket; //TODO: authenticate when own character is being deleted (linked to a TODO in the server)
//send a shutdown request //catch this client's player object
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST; if (argPacket->characterIndex == characterIndex) {
newPacket.accountIndex = accountIndex; characterIndex = -1;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr; localCharacter = nullptr;
} }
accountIndex = -1; characterMap.erase(argPacket->characterIndex);
characterIndex = -1;
//reset the camera
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
} }
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) { void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
HandleLogoutResponse(argPacket);//shortcut if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
SetNextScene(SceneList::DISCONNECTEDSCREEN); HandleCharacterNew(argPacket);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out"; return;
} }
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { BaseCharacter& character = characterMap[argPacket->characterIndex];
HandleDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
void InWorld::CheckHeartBeat() { //other characters moving
//check the connection (heartbeat) if (argPacket->characterIndex != characterIndex) {
if (Clock::now() - lastBeat > std::chrono::seconds(3)) { character.SetOrigin(argPacket->origin);
if (attemptedBeats > 2) { character.SetMotion(argPacket->motion);
//escape to the disconnect screen character.CorrectSprite();
SendDisconnectRequest();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
} }
} }
//------------------------- void InWorld::HandleCharacterRejection(TextPacket* const argPacket) {
//map management RequestDisconnect();
//------------------------- SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility& config = ConfigUtility::GetSingleton();
void InWorld::SendRegionRequest(int roomIndex, int x, int y) { config["client.disconnectMessage"] = "Error: ";
RegionPacket packet; config["client.disconnectMessage"] += argPacket->text;
//pack the region's data
packet.type = SerialPacketType::REGION_REQUEST;
packet.roomIndex = roomIndex;
packet.x = x;
packet.y = y;
network.SendTo(Channels::SERVER, &packet);
} }
void InWorld::HandleRegionContent(RegionPacket* const argPacket) { void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
@@ -509,11 +448,82 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
argPacket->region = nullptr; argPacket->region = nullptr;
} }
void InWorld::UpdateMap() { //-------------------------
if (roomIndex == -1) { //Server control
return; //-------------------------
}
void InWorld::RequestSynchronize() {
// ClientPacket newPacket;
//request a sync
// newPacket.type = SerialPacketType::SYNCHRONIZE;
// newPacket.clientIndex = clientIndex;
// newPacket.accountIndex = accountIndex;
//TODO: location, range for sync request
// network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendPlayerUpdate() {
CharacterPacket newPacket;
//pack the packet
// newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//NOTE: omitting the handle and avatar here
newPacket.accountIndex = accountIndex;
newPacket.roomIndex = 0; //TODO: room index
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
// newPacket.stats = *localCharacter->GetBaseStats();
//TODO: gameplay components: equipment, items, buffs, debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestDisconnect() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestShutDown() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestRegion(int roomIndex, int x, int y) {
RegionPacket packet;
//pack the region's data
packet.type = SerialPacketType::REGION_REQUEST;
packet.roomIndex = roomIndex;
packet.x = x;
packet.y = y;
network.SendTo(Channels::SERVER, &packet);
}
//-------------------------
//Utilities
//-------------------------
//TODO: convert this into a more generic function?; using parameters for the bounds
void InWorld::UpdateMap() {
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
@@ -522,234 +532,27 @@ void InWorld::UpdateMap() {
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT; int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions //prune distant regions
regionPager.GetContainer()->remove_if([&](Region const& region) -> bool { for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd; //check if the region is outside of this area
}); if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
//clunky, but the alternative was time consuming
int tmpX = it->GetX();
int tmpY = it->GetY();
++it;
regionPager.UnloadRegion(tmpX, tmpY);
continue;
}
++it;
}
//request empty regions within this zone //request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) { if (!regionPager.FindRegion(i, j)) {
SendRegionRequest(roomIndex, i, j); RequestRegion(0, i, j);
} }
} }
} }
} }
//-------------------------
//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 (skipped)
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
//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(argPacket->origin);
character->SetMotion(argPacket->motion);
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);
character->CorrectSprite();
//check for this player's character
if (character->GetOwner() == accountIndex) {
localCharacter = static_cast<LocalCharacter*>(character);
//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);
//focus on this character's info
characterIndex = argPacket->characterIndex;
roomIndex = argPacket->roomIndex;
}
//debug
std::cout << "Create, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//ignore if this character doesn't exist
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt == characterMap.end()) {
//debug
std::cout << "Ignoring character deletion" << std::endl;
return;
}
//check for this player's character
if ((*characterIt).second.GetOwner() == accountIndex) {
localCharacter = nullptr;
//clear the camera
camera.marginX = 0;
camera.marginY = 0;
//clear the room
roomIndex = -1;
}
//remove this character
characterMap.erase(characterIt);
//debug
std::cout << "Delete, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character
if (argPacket->accountIndex == accountIndex) {
return;
}
//ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly construct the character if it doesn't exist
BaseCharacter* character = &characterMap[argPacket->characterIndex];
//set/update the character's info
character->SetOrigin(argPacket->origin);
character->SetMotion(argPacket->motion);
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);
character->CorrectSprite();
//debug
std::cout << "Query, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) {
//someone else's character
if (argPacket->characterIndex != characterIndex) {
characterMap.erase(argPacket->characterIndex);
return;
}
//this character is moving between rooms
roomIndex = argPacket->roomIndex;
//set the character's info
localCharacter->SetOrigin(argPacket->origin);
localCharacter->SetMotion(argPacket->motion);
localCharacter->CorrectSprite();
//clear the old room's data
regionPager.UnloadAll();
monsterMap.clear();
//use the jenky pattern for std::map to skip this player's character
for (std::map<int, BaseCharacter>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
if (it->first != characterIndex) {
it = characterMap.erase(it);
}
else {
++it;
}
}
//request the info on characters in this room
CharacterPacket newPacket;
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
//TODO: Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//set the origin and motion
characterIt->second.SetOrigin(argPacket->origin);
characterIt->second.SetMotion(argPacket->motion);
characterIt->second.CorrectSprite();
}
}
void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) {
//TODO: Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//set the origin and motion
characterIt->second.SetOrigin(argPacket->origin);
characterIt->second.SetMotion(argPacket->motion);
characterIt->second.CorrectSprite();
}
}
//-------------------------
//player movement
//-------------------------
//TODO: add a "movement" packet type
void InWorld::SendLocalCharacterMotion() {
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
newPacket.accountIndex = accountIndex;
newPacket.characterIndex = characterIndex;
newPacket.roomIndex = roomIndex;
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
network.SendTo(Channels::SERVER, &newPacket);
}
std::list<BoundingBox> InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
//prepare for collisions
BoundingBox wallBounds = {0, 0, tileWidth, tileHeight};
std::list<BoundingBox> boxList;
//NOTE: for loops were too dense to work with, so I've just used while loops
//outer loop
wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x);
while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) {
//inner loop
wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y);
while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) {
//check to see if this tile is solid
if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
//push onto the box set
boxList.push_front(wallBounds);
}
//increment
wallBounds.y += wallBounds.h;
}
//increment
wallBounds.x += wallBounds.w;
}
return std::move(boxList);
}
+25 -40
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,10 +25,9 @@
//maps //maps
#include "region_pager_base.hpp" #include "region_pager_base.hpp"
//utilities //networking
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "serial_packet.hpp" #include "serial_packet.hpp"
#include "config_utility.hpp"
//graphics //graphics
#include "image.hpp" #include "image.hpp"
@@ -39,10 +38,11 @@
//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_monster.hpp"
#include "local_character.hpp"
//STL //STL
#include <map> #include <map>
@@ -71,44 +71,33 @@ protected:
void KeyDown(SDL_KeyboardEvent const&); void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//Basic connections //Network handlers
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const); void HandlePong(ServerPacket* const);
void HandleDisconnect(ClientPacket* const);
//Connection control void HandleCharacterNew(CharacterPacket* const);
void SendLogoutRequest(); void HandleCharacterDelete(CharacterPacket* const);
void SendDisconnectRequest(); void HandleCharacterUpdate(CharacterPacket* const);
void SendShutdownRequest(); void HandleCharacterRejection(TextPacket* const);
void HandleLogoutResponse(ClientPacket* const);
void HandleDisconnectResponse(ClientPacket* const);
void HandleDisconnectForced(ClientPacket* const);
void CheckHeartBeat();
//map management
void SendRegionRequest(int roomIndex, int x, int y);
void HandleRegionContent(RegionPacket* const); void HandleRegionContent(RegionPacket* const);
//Server control
void RequestSynchronize();
void SendPlayerUpdate();
void RequestDisconnect();
void RequestShutDown();
void RequestRegion(int roomIndex, int x, int y);
//utilities
void UpdateMap(); void UpdateMap();
//character management //singleton shortcut
void HandleCharacterCreate(CharacterPacket* const); UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterQueryExists(CharacterPacket* const);
void HandleCharacterSetRoom(CharacterPacket* const);
void HandleCharacterSetOrigin(CharacterPacket* const);
void HandleCharacterSetMotion(CharacterPacket* const);
//player movement
void SendLocalCharacterMotion();
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
//indexes //indexes
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int characterIndex = -1; int characterIndex = -1;
int roomIndex = -1;
//graphics //graphics
Image buttonImage; Image buttonImage;
@@ -130,20 +119,16 @@ protected:
int marginX = 0, marginY = 0; int marginX = 0, marginY = 0;
} camera; } camera;
//entities //game components
BaseCharacter* localCharacter = nullptr;
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: This needs it's own utility, for both InWorld and InCombat
typedef std::chrono::steady_clock Clock; typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now(); Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0; int attemptedBeats = 0;
//ugly references; I hate this
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
}; };
#endif #endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,7 @@ void Timer::Stop() {
std::ostream& operator<<(std::ostream& os, Timer& t) { std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": "; os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count(); os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
os << "us"; os << "ms";
return os; return os;
} }
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,8 @@ public:
Timer(std::string s); Timer(std::string s);
~Timer() = default; ~Timer() = default;
void Start(); inline void Start();
void Stop(); inline void Stop();
//accessors and mutators //accessors and mutators
Clock::duration GetTime() { return timeSpan; } Clock::duration GetTime() { return timeSpan; }
+1 -5
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -35,8 +35,4 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
constexpr int CHARACTER_BOUNDS_WIDTH = 32; constexpr int CHARACTER_BOUNDS_WIDTH = 32;
constexpr int CHARACTER_BOUNDS_HEIGHT = 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 #endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -70,7 +70,7 @@ int openMapSystemAPI(lua_State* L) {
//push the substable //push the substable
for (const luaL_Reg* lib = libs; lib->func; lib++) { for (const luaL_Reg* lib = libs; lib->func; lib++) {
lib->func(L); lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name); lua_setfield(L, -2, lib->name);
} }
return 1; return 1;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+13 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,18 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
RegionPagerBase::RegionPagerBase() {
//
}
RegionPagerBase::RegionPagerBase(RegionPagerBase&& rhs) {
regionList = std::move(rhs.regionList);
}
RegionPagerBase::~RegionPagerBase() {
UnloadAll();
}
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) { Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
Region* ptr = GetRegion(x, y); Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
+4 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -28,8 +28,9 @@
class RegionPagerBase { class RegionPagerBase {
public: public:
RegionPagerBase() = default; RegionPagerBase();
virtual ~RegionPagerBase() { UnloadAll(); }; RegionPagerBase(RegionPagerBase&&);
virtual ~RegionPagerBase();
//tile manipulation //tile manipulation
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v); virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
+14 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,6 +23,18 @@
#include <stdexcept> #include <stdexcept>
RegionPagerLua::RegionPagerLua() {
//
}
RegionPagerLua::RegionPagerLua(RegionPagerLua&& rhs) {
lua = rhs.lua;
loadRef = rhs.loadRef;
saveRef = rhs.saveRef;
createRef = rhs.createRef;
unloadRef = rhs.unloadRef;
}
RegionPagerLua::~RegionPagerLua() { RegionPagerLua::~RegionPagerLua() {
//unload all regions //unload all regions
UnloadAll(); UnloadAll();
@@ -164,6 +176,7 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
lua_pop(lua, 1); lua_pop(lua, 1);
} }
//no return
void RegionPagerLua::UnloadAll() { void RegionPagerLua::UnloadAll() {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
+3 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -34,7 +34,8 @@
class RegionPagerLua : public RegionPagerBase { class RegionPagerLua : public RegionPagerBase {
public: public:
RegionPagerLua() = default; RegionPagerLua();
RegionPagerLua(RegionPagerLua&&);
~RegionPagerLua(); ~RegionPagerLua();
//region manipulation //region manipulation
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -33,7 +33,7 @@
typedef SerialPacketBase SerialPacket; typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients //DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20141227; constexpr int NETWORK_VERSION = -1;
union MaxPacket { union MaxPacket {
CharacterPacket a; CharacterPacket a;
+33 -34
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -38,12 +38,12 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//heartbeat //heartbeat
PING = 1, PING,
PONG = 2, PONG,
//Used for finding available servers //Used for finding available servers
BROADCAST_REQUEST = 3, BROADCAST_REQUEST,
BROADCAST_RESPONSE = 4, BROADCAST_RESPONSE,
//------------------------- //-------------------------
//ClientPacket //ClientPacket
@@ -51,24 +51,24 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//Connecting to a server as a client //Connecting to a server as a client
JOIN_REQUEST = 5, JOIN_REQUEST,
JOIN_RESPONSE = 6, JOIN_RESPONSE,
//disconnect from the server //disconnect from the server
DISCONNECT_REQUEST = 7, DISCONNECT_REQUEST,
DISCONNECT_RESPONSE = 8, DISCONNECT_RESPONSE,
DISCONNECT_FORCED = 9, DISCONNECT_FORCED,
//load the account //load the account
LOGIN_REQUEST = 10, LOGIN_REQUEST,
LOGIN_RESPONSE = 11, LOGIN_RESPONSE,
//unload the account //unload the account
LOGOUT_REQUEST = 12, LOGOUT_REQUEST,
LOGOUT_RESPONSE = 13, LOGOUT_RESPONSE,
//shut down the server //shut down the server
SHUTDOWN_REQUEST = 14, SHUTDOWN_REQUEST,
//------------------------- //-------------------------
//RegionPacket //RegionPacket
@@ -76,8 +76,8 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//map data //map data
REGION_REQUEST = 15, //NOTE: technically a query REGION_REQUEST, //NOTE: technically a query
REGION_CONTENT = 16, REGION_CONTENT,
//------------------------- //-------------------------
//CharacterPacket //CharacterPacket
@@ -89,20 +89,20 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//character management //character management
CHARACTER_CREATE = 17, CHARACTER_CREATE,
CHARACTER_DELETE = 18, CHARACTER_DELETE,
CHARACTER_LOAD = 19, CHARACTER_LOAD,
CHARACTER_UNLOAD = 20, CHARACTER_UNLOAD,
//find out info from the server //find out info from the server
QUERY_CHARACTER_EXISTS = 21, QUERY_CHARACTER_EXISTS,
QUERY_CHARACTER_STATS = 22, QUERY_CHARACTER_STATS,
QUERY_CHARACTER_LOCATION = 23, QUERY_CHARACTER_LOCATION,
//set the info in the server //set the info in the server
CHARACTER_SET_ROOM = 24, CHARACTER_SET_ROOM,
CHARACTER_SET_ORIGIN = 25, CHARACTER_SET_ORIGIN,
CHARACTER_SET_MOTION = 26, CHARACTER_SET_MOTION,
//TODO: enemy management //TODO: enemy management
@@ -112,20 +112,19 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//general speech //general speech
TEXT_BROADCAST = 27, TEXT_BROADCAST,
//rejection/error messages //rejection/error messages
JOIN_REJECTION = 28, JOIN_REJECTION,
LOGIN_REJECTION = 29, LOGIN_REJECTION,
REGION_REJECTION = 30, CHARACTER_REJECTION,
CHARACTER_REJECTION = 31, SHUTDOWN_REJECTION,
SHUTDOWN_REJECTION = 32,
//------------------------- //-------------------------
//not used //not used
//------------------------- //-------------------------
LAST = 33 LAST
}; };
#endif #endif
+2 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -83,7 +83,6 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION: case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet)); serializeText(buffer, static_cast<TextPacket*>(packet));
@@ -96,7 +95,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
SerialPacketType type; SerialPacketType type;
memcpy(&type, buffer, sizeof(SerialPacketType)); memcpy(&type, buffer, sizeof(SerialPacketType));
switch(type) { switch(packet->type) {
case SerialPacketType::PING: case SerialPacketType::PING:
case SerialPacketType::PONG: case SerialPacketType::PONG:
case SerialPacketType::BROADCAST_REQUEST: case SerialPacketType::BROADCAST_REQUEST:
@@ -134,7 +133,6 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION: case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION:
deserializeText(buffer, static_cast<TextPacket*>(packet)); deserializeText(buffer, static_cast<TextPacket*>(packet));
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+7 -12
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,13 +27,13 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) { void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
//clear the stored configuration //clear the stored configuration
configMap.clear(); configMap.clear();
//use the default file //use the default file
if (argc < 2) { if (argc < 2) {
configMap = Read(fname, skipMissingFile); configMap = Read(fname);
return; return;
} }
@@ -47,9 +47,7 @@ void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
//read from a specified config file //read from a specified config file
if (!strncmp(argv[i], "-config=", 8)) { if (!strncmp(argv[i], "-config=", 8)) {
//older specified files take precedence redirectedFile = Read(argv[i] + 8);
table_t tmp = Read(argv[i] + 8, skipMissingFile);
redirectedFile.insert(tmp.begin(), tmp.end());
redirectUsed = true; redirectUsed = true;
continue; continue;
} }
@@ -75,21 +73,18 @@ void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char
//finally, construct the final config table //finally, construct the final config table
if (!redirectUsed) { if (!redirectUsed) {
redirectedFile = Read(fname, skipMissingFile); redirectedFile = Read(fname);
} }
configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
configMap.insert(redirectedFile.begin(), redirectedFile.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end());
} }
ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) { ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
//read in and return this file's data //read in and return this file's data
table_t retTable; table_t retTable;
std::ifstream is(fname); std::ifstream is(fname);
if (!is.is_open()) { if (!is.is_open()) {
if (skipMissingFile) {
return {}; //empty table
}
std::ostringstream os; std::ostringstream os;
os << "Failed to open a config file: " << fname; os << "Failed to open a config file: " << fname;
throw(std::runtime_error( os.str() )); throw(std::runtime_error( os.str() ));
@@ -148,7 +143,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFi
//load in any subordinate config files //load in any subordinate config files
if (retTable.find("config.next") != retTable.end()) { if (retTable.find("config.next") != retTable.end()) {
table_t subTable = Read(retTable["config.next"], skipMissingFile); table_t subTable = Read(retTable["config.next"]);
retTable.insert(subTable.begin(), subTable.end()); retTable.insert(subTable.begin(), subTable.end());
} }
+7 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,9 +27,9 @@
#include <map> #include <map>
#include <string> #include <string>
class ConfigUtility: public Singleton<ConfigUtility> { class ConfigUtility : public Singleton<ConfigUtility> {
public: public:
void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr); void Load(std::string fname, int argc = 0, char* argv[] = nullptr);
//convert to a type //convert to a type
std::string& String(std::string); std::string& String(std::string);
@@ -47,7 +47,10 @@ private:
friend Singleton<ConfigUtility>; friend Singleton<ConfigUtility>;
table_t Read(std::string fname, bool skipMissingFile); ConfigUtility() = default;
~ConfigUtility() = default;
table_t Read(std::string fname);
table_t configMap; table_t configMap;
}; };
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -5
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013, 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -92,10 +92,6 @@ public:
return ret; return ret;
} }
//unary operators
Vector2 operator-() { return {-x, -y}; }
//comparison operators
bool operator==(Vector2 v) { return (x == v.x && y == v.y); } bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
-6
View File
@@ -1,9 +1,3 @@
local mapSaver = {} local mapSaver = {}
function mapSaver.Load(region)
--empty
end
function mapSaver.Save(region)
--empty
end
--TODO: create a flexible saving & loading system --TODO: create a flexible saving & loading system
return mapSaver return mapSaver
+1 -3
View File
@@ -25,8 +25,6 @@ dumpTable(roomSystem)
dumpTable(roomSystem.RoomManager) dumpTable(roomSystem.RoomManager)
dumpTable(roomSystem.Room) dumpTable(roomSystem.Room)
--NOTE: room 0 is the first that the client asks for, therefore it must exist local overworld = roomSystem.RoomManager.CreateRoom("overworld")
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld")
roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
print("Finished the lua script") print("Finished the lua script")
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -200,7 +200,7 @@ void AccountManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void AccountManager::UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn) { void AccountManager::UnloadIf(std::function<bool(std::pair<const int, AccountData>&)> fn) {
//replicate std::remove_if, using custom code //replicate std::remove_if, using custom code
std::map<int, AccountData>::iterator it = elementMap.begin(); std::map<int, AccountData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -48,7 +48,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, AccountData>&)> fn) override;
//accessors and mutators //accessors and mutators
AccountData* Get(int uid) override; AccountData* Get(int uid) override;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -110,8 +110,6 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) {
//check the owner //check the owner
if (owner != sqlite3_column_int(statement, 1)) { if (owner != sqlite3_column_int(statement, 1)) {
sqlite3_finalize(statement); sqlite3_finalize(statement);
//unload the already loaded character
Unload(uid);
return -2; return -2;
} }
@@ -229,7 +227,7 @@ void CharacterManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void CharacterManager::UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn) { void CharacterManager::UnloadIf(std::function<bool(std::pair<const int, CharacterData>&)> fn) {
std::map<int, CharacterData>::iterator it = elementMap.begin(); std::map<int, CharacterData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -48,7 +48,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, CharacterData>&)> fn) override;
//accessors and mutators //accessors and mutators
CharacterData* Get(int uid) override; CharacterData* Get(int uid) override;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2014
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,7 @@ int ClientManager::CheckConnections() {
for (auto& it : elementMap) { for (auto& it : elementMap) {
if (it.second.GetAttempts() > 2) { if (it.second.GetAttempts() > 2) {
int ret = it.first; int ret = it.first;
// elementMap.erase(it.first); elementMap.erase(it.first);
return ret; return ret;
} }
} }
@@ -73,7 +73,7 @@ void ClientManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void ClientManager::UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn) { void ClientManager::UnloadIf(std::function<bool(std::pair<const int, ClientData>&)> fn) {
std::map<int, ClientData>::iterator it = elementMap.begin(); std::map<int, ClientData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {

Some files were not shown because too many files have changed in this diff Show More