Merge branch 'high-water-mark' into collisions
This commit is contained in:
@@ -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", argc, argv);
|
config.Load("rsc/config.cfg", false, argc, argv);
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Initialize the APIs
|
//Initialize the APIs
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
|
|||||||
ConfigUtility::CreateSingleton();
|
ConfigUtility::CreateSingleton();
|
||||||
UDPNetworkUtility::CreateSingleton();
|
UDPNetworkUtility::CreateSingleton();
|
||||||
|
|
||||||
//call the server's routines
|
//call the client's routines
|
||||||
ClientApplication::CreateSingleton();
|
ClientApplication::CreateSingleton();
|
||||||
ClientApplication& app = ClientApplication::GetSingleton();
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
|
|
||||||
|
|||||||
+17
-15
@@ -137,10 +137,8 @@ void InWorld::Update() {
|
|||||||
//check the connection (heartbeat)
|
//check the connection (heartbeat)
|
||||||
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||||
if (attemptedBeats > 2) {
|
if (attemptedBeats > 2) {
|
||||||
//two-step logout
|
//escape to the disconnect screen
|
||||||
SendLogoutRequest();
|
|
||||||
SendDisconnectRequest();
|
SendDisconnectRequest();
|
||||||
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
|
||||||
}
|
}
|
||||||
@@ -248,7 +246,6 @@ void InWorld::Render(SDL_Surface* const screen) {
|
|||||||
|
|
||||||
void InWorld::QuitEvent() {
|
void InWorld::QuitEvent() {
|
||||||
//two-step logout
|
//two-step logout
|
||||||
SendLogoutRequest();
|
|
||||||
SendDisconnectRequest();
|
SendDisconnectRequest();
|
||||||
SetNextScene(SceneList::QUIT);
|
SetNextScene(SceneList::QUIT);
|
||||||
}
|
}
|
||||||
@@ -276,9 +273,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
//hotkeys
|
//hotkeys
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
//the escape key should actually control menus and stuff
|
//TODO: the escape key should actually control menus and stuff
|
||||||
SendLogoutRequest();
|
SendLogoutRequest();
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//character movement
|
//character movement
|
||||||
@@ -299,6 +296,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
motion.x += CHARACTER_WALKING_SPEED;
|
motion.x += CHARACTER_WALKING_SPEED;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
//DOCS: prevents wrong keys screwing with character movement
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//handle diagonals
|
//handle diagonals
|
||||||
if (motion.x != 0 && motion.y != 0) {
|
if (motion.x != 0 && motion.y != 0) {
|
||||||
@@ -329,6 +329,9 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
|
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
//DOCS: prevents wrong keys screwing with character movement
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//BUGFIX: reset cardinal direction speed on key release
|
//BUGFIX: reset cardinal direction speed on key release
|
||||||
if (motion.x > 0) {
|
if (motion.x > 0) {
|
||||||
@@ -473,30 +476,29 @@ void InWorld::SendShutdownRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
||||||
|
if (localCharacter) {
|
||||||
|
characterMap.erase(characterIndex);
|
||||||
|
localCharacter = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
accountIndex = -1;
|
accountIndex = -1;
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
|
|
||||||
//reset the camera
|
//reset the camera
|
||||||
camera.x = camera.y = 0;
|
|
||||||
camera.marginX = camera.marginY = 0;
|
camera.marginX = camera.marginY = 0;
|
||||||
|
|
||||||
|
//because, why not? I guess...
|
||||||
SendDisconnectRequest();
|
SendDisconnectRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
|
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
|
||||||
|
HandleLogoutResponse(argPacket);//shortcut
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
||||||
//clear the local data
|
HandleDisconnectResponse(argPacket);//shortcut
|
||||||
accountIndex = -1;
|
|
||||||
characterIndex = -1;
|
|
||||||
|
|
||||||
//reset the camera
|
|
||||||
camera.x = camera .y = 0;
|
|
||||||
camera.marginX = camera.marginY = 0;
|
|
||||||
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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::milliseconds>(t.GetTime()).count();
|
os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
|
||||||
os << "ms";
|
os << "us";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public:
|
|||||||
Timer(std::string s);
|
Timer(std::string s);
|
||||||
~Timer() = default;
|
~Timer() = default;
|
||||||
|
|
||||||
inline void Start();
|
void Start();
|
||||||
inline void Stop();
|
void Stop();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
Clock::duration GetTime() { return timeSpan; }
|
Clock::duration GetTime() { return timeSpan; }
|
||||||
|
|||||||
@@ -27,13 +27,13 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
|
void ConfigUtility::Load(std::string fname, bool skipMissingFile, 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);
|
configMap = Read(fname, skipMissingFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
|
|||||||
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)) {
|
||||||
redirectedFile = Read(argv[i] + 8);
|
//older specified files take precedence
|
||||||
|
table_t tmp = Read(argv[i] + 8, skipMissingFile);
|
||||||
|
redirectedFile.insert(tmp.begin(), tmp.end());
|
||||||
redirectUsed = true;
|
redirectUsed = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
|
|||||||
|
|
||||||
//finally, construct the final config table
|
//finally, construct the final config table
|
||||||
if (!redirectUsed) {
|
if (!redirectUsed) {
|
||||||
redirectedFile = Read(fname);
|
redirectedFile = Read(fname, skipMissingFile);
|
||||||
}
|
}
|
||||||
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) {
|
ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) {
|
||||||
//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() ));
|
||||||
@@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
|
|||||||
|
|
||||||
//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"]);
|
table_t subTable = Read(retTable["config.next"], skipMissingFile);
|
||||||
retTable.insert(subTable.begin(), subTable.end());
|
retTable.insert(subTable.begin(), subTable.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
class ConfigUtility: public Singleton<ConfigUtility> {
|
class ConfigUtility: public Singleton<ConfigUtility> {
|
||||||
public:
|
public:
|
||||||
void Load(std::string fname, int argc = 0, char* argv[] = nullptr);
|
void Load(std::string fname, bool skipMissingFile = false, 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,10 +47,7 @@ private:
|
|||||||
|
|
||||||
friend Singleton<ConfigUtility>;
|
friend Singleton<ConfigUtility>;
|
||||||
|
|
||||||
ConfigUtility() = default;
|
table_t Read(std::string fname, bool skipMissingFile);
|
||||||
~ConfigUtility() = default;
|
|
||||||
|
|
||||||
table_t Read(std::string fname);
|
|
||||||
|
|
||||||
table_t configMap;
|
table_t configMap;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
std::cout << "Beginning " << argv[0] << std::endl;
|
std::cout << "Beginning " << argv[0] << std::endl;
|
||||||
|
|
||||||
//load the config settings
|
//load the config settings
|
||||||
config.Load("rsc/config.cfg", argc, argv);
|
config.Load("rsc/config.cfg", false, argc, argv);
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Initialize the APIs
|
//Initialize the APIs
|
||||||
|
|||||||
Reference in New Issue
Block a user