UDPNetworkUtility is a singleton, disabled InCombat scene
I found incombat to be way too finicky to keep up to date, so I disabled it for now.
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
#include "options_menu.hpp"
|
#include "options_menu.hpp"
|
||||||
#include "lobby_menu.hpp"
|
#include "lobby_menu.hpp"
|
||||||
#include "in_world.hpp"
|
#include "in_world.hpp"
|
||||||
#include "in_combat.hpp"
|
//#include "in_combat.hpp"
|
||||||
#include "clean_up.hpp"
|
#include "clean_up.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -66,7 +66,7 @@ void ClientApplication::Init(int argc, char** argv) {
|
|||||||
if (SDLNet_Init()) {
|
if (SDLNet_Init()) {
|
||||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||||
}
|
}
|
||||||
network.Open(0);
|
UDPNetworkUtility::GetSingleton().Open(0);
|
||||||
std::cout << "Initialized SDL_net" << std::endl;
|
std::cout << "Initialized SDL_net" << std::endl;
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -151,7 +151,7 @@ void ClientApplication::Proc() {
|
|||||||
|
|
||||||
void ClientApplication::Quit() {
|
void ClientApplication::Quit() {
|
||||||
std::cout << "Shutting down" << std::endl;
|
std::cout << "Shutting down" << std::endl;
|
||||||
network.Close();
|
UDPNetworkUtility::GetSingleton().Close();
|
||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
std::cout << "Clean exit" << std::endl;
|
std::cout << "Clean exit" << std::endl;
|
||||||
@@ -176,16 +176,16 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
activeScene = new OptionsMenu();
|
activeScene = new OptionsMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
case SceneList::LOBBYMENU:
|
||||||
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex);
|
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
activeScene = new InWorld(&clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
|
||||||
case SceneList::INCOMBAT:
|
|
||||||
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
|
||||||
break;
|
break;
|
||||||
|
// case SceneList::INCOMBAT:
|
||||||
|
// activeScene = new InCombat(&clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
|
// break;
|
||||||
case SceneList::CLEANUP:
|
case SceneList::CLEANUP:
|
||||||
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
activeScene = new CleanUp(&clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw(std::logic_error("Failed to recognize the scene index"));
|
throw(std::logic_error("Failed to recognize the scene index"));
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ private:
|
|||||||
BaseScene* activeScene = nullptr;
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
UDPNetworkUtility network;
|
|
||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
int accountIndex = -1;
|
int accountIndex = -1;
|
||||||
int characterIndex = -1;
|
int characterIndex = -1;
|
||||||
|
|||||||
+7
-2
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
//singletons
|
//singletons
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -32,18 +33,22 @@ using namespace std;
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
//create the singletons
|
//create the singletons
|
||||||
ClientApplication::Create();
|
|
||||||
ConfigUtility::Create();
|
ConfigUtility::Create();
|
||||||
|
UDPNetworkUtility::Create();
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
|
ClientApplication::Create();
|
||||||
ClientApplication& app = ClientApplication::GetSingleton();
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
|
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
ClientApplication::Delete();
|
||||||
|
|
||||||
//delete the singletons
|
//delete the singletons
|
||||||
ConfigUtility::Delete();
|
ConfigUtility::Delete();
|
||||||
ClientApplication::Delete();
|
UDPNetworkUtility::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
@@ -31,13 +31,11 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
CleanUp::CleanUp(
|
CleanUp::CleanUp(
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
CharacterMap* argCharacterMap
|
CharacterMap* argCharacterMap
|
||||||
):
|
):
|
||||||
network(*argNetwork),
|
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class CleanUp : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
CleanUp(
|
CleanUp(
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
@@ -68,7 +67,7 @@ protected:
|
|||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
|
|||||||
@@ -35,13 +35,11 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InWorld::InWorld(
|
InWorld::InWorld(
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
CharacterMap* argCharacterMap
|
CharacterMap* argCharacterMap
|
||||||
):
|
):
|
||||||
network(*argNetwork),
|
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class InWorld : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InWorld(
|
InWorld(
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
@@ -92,7 +91,7 @@ protected:
|
|||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
|
|||||||
@@ -30,12 +30,7 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
LobbyMenu::LobbyMenu(
|
LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
|
||||||
int* const argAccountIndex
|
|
||||||
):
|
|
||||||
network(*argNetwork),
|
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex)
|
accountIndex(*argAccountIndex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,11 +40,7 @@
|
|||||||
class LobbyMenu : public BaseScene {
|
class LobbyMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
LobbyMenu(
|
LobbyMenu(int* const argClientIndex, int* const argAccountIndex);
|
||||||
UDPNetworkUtility* const argNetwork,
|
|
||||||
int* const argClientIndex,
|
|
||||||
int* const argAccountIndex
|
|
||||||
);
|
|
||||||
~LobbyMenu();
|
~LobbyMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -68,7 +64,7 @@ protected:
|
|||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
//NOTE: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
//BUGFIX: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||||
//NOTE: don't confuse SerialPacket with UDPpacket
|
//NOTE: don't confuse SerialPacket with UDPpacket
|
||||||
|
|
||||||
void UDPNetworkUtility::Open(int port) {
|
void UDPNetworkUtility::Open(int port) {
|
||||||
|
|||||||
@@ -22,15 +22,15 @@
|
|||||||
#ifndef UDPNETWORKUTILITY_HPP_
|
#ifndef UDPNETWORKUTILITY_HPP_
|
||||||
#define UDPNETWORKUTILITY_HPP_
|
#define UDPNETWORKUTILITY_HPP_
|
||||||
|
|
||||||
|
//common
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
|
//APIs
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
#include "serial_packet.hpp"
|
class UDPNetworkUtility : public Singleton<UDPNetworkUtility> {
|
||||||
|
|
||||||
class UDPNetworkUtility {
|
|
||||||
public:
|
public:
|
||||||
UDPNetworkUtility() = default;
|
|
||||||
~UDPNetworkUtility() = default;
|
|
||||||
|
|
||||||
void Open(int port);
|
void Open(int port);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
@@ -65,6 +65,11 @@ public:
|
|||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<UDPNetworkUtility>;
|
||||||
|
|
||||||
|
UDPNetworkUtility() = default;
|
||||||
|
~UDPNetworkUtility() = default;
|
||||||
|
|
||||||
UDPsocket socket = nullptr;
|
UDPsocket socket = nullptr;
|
||||||
UDPpacket* packet = nullptr;
|
UDPpacket* packet = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
+7
-2
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
//singletons
|
//singletons
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -33,17 +34,21 @@ int main(int argc, char** argv) {
|
|||||||
try {
|
try {
|
||||||
//create the singletons
|
//create the singletons
|
||||||
ConfigUtility::Create();
|
ConfigUtility::Create();
|
||||||
ServerApplication::Create();
|
UDPNetworkUtility::Create();
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
|
ServerApplication::Create();
|
||||||
ServerApplication& app = ServerApplication::GetSingleton();
|
ServerApplication& app = ServerApplication::GetSingleton();
|
||||||
|
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
ServerApplication::Delete();
|
||||||
|
|
||||||
//delete the singletons
|
//delete the singletons
|
||||||
ConfigUtility::Delete();
|
ConfigUtility::Delete();
|
||||||
ServerApplication::Delete();
|
UDPNetworkUtility::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ private:
|
|||||||
//APIs and utilities
|
//APIs and utilities
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//simple tables
|
//simple tables
|
||||||
|
|||||||
Reference in New Issue
Block a user