Smoothed naming and other conventions
This commit is contained in:
+10
-10
@@ -63,9 +63,9 @@ void Lobby::Update() {
|
||||
|
||||
void Lobby::Receive() {
|
||||
//dump to the console
|
||||
Packet packet;
|
||||
PacketData packet;
|
||||
while(netUtil->Receive()) {
|
||||
memcpy(&packet, netUtil->GetInData(), sizeof(Packet));
|
||||
memcpy(&packet, netUtil->GetInData(), sizeof(PacketData));
|
||||
switch(packet.type) {
|
||||
case PacketList::PONG:
|
||||
PushServer(&packet);
|
||||
@@ -149,24 +149,24 @@ void Lobby::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
|
||||
void Lobby::PingNetwork() {
|
||||
//ping the network
|
||||
Packet packet;
|
||||
PacketData packet;
|
||||
packet.type = PacketList::PING;
|
||||
netUtil->Send("255.255.255.255", configUtil->Integer("server.port"), reinterpret_cast<void*>(&packet), sizeof(Packet));
|
||||
netUtil->Send("255.255.255.255", configUtil->Integer("server.port"), reinterpret_cast<void*>(&packet), sizeof(PacketData));
|
||||
//reset the server list
|
||||
// serverVector.clear();
|
||||
}
|
||||
|
||||
void Lobby::PushServer(Packet* packet) {
|
||||
Server s;
|
||||
void Lobby::PushServer(PacketData* packet) {
|
||||
ServerData s;
|
||||
s.name = packet->pong.metadata;
|
||||
s.add = netUtil->GetInPacket()->address;
|
||||
s.address = netUtil->GetInPacket()->address;
|
||||
serverVector.push_back(s);
|
||||
}
|
||||
|
||||
void Lobby::JoinRequest(Server* server) {
|
||||
Packet packet;
|
||||
void Lobby::JoinRequest(ServerData* server) {
|
||||
PacketData packet;
|
||||
packet.type = PacketList::JOINREQUEST;
|
||||
snprintf(packet.joinRequest.handle, PACKET_STRING_SIZE, "%s", configUtil->CString("handle"));
|
||||
snprintf(packet.joinRequest.avatar, PACKET_STRING_SIZE, "%s", configUtil->CString("avatar"));
|
||||
netUtil->Send(&server->add, reinterpret_cast<void*>(&packet), sizeof(Packet));
|
||||
netUtil->Send(&server->address, reinterpret_cast<void*>(&packet), sizeof(PacketData));
|
||||
}
|
||||
|
||||
+10
-11
@@ -15,11 +15,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct Server {
|
||||
std::string name;
|
||||
IPaddress add;
|
||||
};
|
||||
|
||||
class Lobby : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
@@ -42,10 +37,14 @@ protected:
|
||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//utilities
|
||||
struct ServerData {
|
||||
std::string name;
|
||||
IPaddress address;
|
||||
};
|
||||
|
||||
void PingNetwork();
|
||||
void PushServer(Packet*);
|
||||
void JoinRequest(Server*);
|
||||
typedef std::map<std::string, Button*> ButtonMap;
|
||||
void PushServer(PacketData*);
|
||||
void JoinRequest(ServerData*);
|
||||
|
||||
//members
|
||||
ConfigUtility* configUtil = nullptr;
|
||||
@@ -53,11 +52,11 @@ protected:
|
||||
UDPNetworkUtility* netUtil = nullptr;
|
||||
|
||||
RasterFont font;
|
||||
ButtonMap buttonMap;
|
||||
std::map<std::string, Button*> buttonMap;
|
||||
|
||||
//the list of servers on the screen
|
||||
std::vector<Server> serverVector;
|
||||
Server* selectedServer = nullptr;
|
||||
std::vector<ServerData> serverVector;
|
||||
ServerData* selectedServer = nullptr;
|
||||
SDL_Rect listBox;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ MainMenu::~MainMenu() {
|
||||
for (auto it : buttonMap) {
|
||||
delete it.second;
|
||||
}
|
||||
buttonMap.clear();
|
||||
#ifdef DEBUG
|
||||
cout << "leaving MainMenu" << endl;
|
||||
#endif
|
||||
|
||||
@@ -31,15 +31,12 @@ protected:
|
||||
virtual void KeyDown(SDL_KeyboardEvent const&);
|
||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//utilities
|
||||
typedef std::map<std::string, Button*> ButtonMap;
|
||||
|
||||
//singletons
|
||||
//globals
|
||||
ConfigUtility* configUtil;
|
||||
SurfaceManager* surfaceMgr;
|
||||
|
||||
//members
|
||||
ButtonMap buttonMap;
|
||||
std::map<std::string, Button*> buttonMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//-------------------------
|
||||
|
||||
SceneManager::SceneManager() {
|
||||
activeScene = nullptr;
|
||||
//
|
||||
}
|
||||
|
||||
SceneManager::~SceneManager() {
|
||||
@@ -41,7 +41,7 @@ void SceneManager::Init() {
|
||||
}
|
||||
|
||||
configUtil.Load("rsc/config.cfg");
|
||||
netUtil.Open(0, sizeof(Packet));
|
||||
netUtil.Open(0, sizeof(PacketData));
|
||||
|
||||
//set the screen from the config file
|
||||
int flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
|
||||
@@ -103,12 +103,12 @@ void SceneManager::LoadScene(SceneList sceneIndex) {
|
||||
case SceneList::MAINMENU:
|
||||
activeScene = new MainMenu(&configUtil, &surfaceMgr);
|
||||
break;
|
||||
case SceneList::INGAME:
|
||||
activeScene = new InGame(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
case SceneList::LOBBY:
|
||||
activeScene = new Lobby(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
case SceneList::INGAME:
|
||||
activeScene = new InGame(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
|
||||
#ifdef DEBUG
|
||||
case SceneList::COMBAT:
|
||||
|
||||
@@ -26,8 +26,9 @@ private:
|
||||
void LoadScene(SceneList sceneIndex);
|
||||
void UnloadScene();
|
||||
|
||||
BaseScene* activeScene;
|
||||
BaseScene* activeScene = nullptr;
|
||||
|
||||
//globals
|
||||
ConfigUtility configUtil;
|
||||
SurfaceManager surfaceMgr;
|
||||
UDPNetworkUtility netUtil;
|
||||
|
||||
@@ -12,8 +12,6 @@ Splash::Splash(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
||||
#ifdef DEBUG
|
||||
cout << "entering Splash" << endl;
|
||||
#endif
|
||||
loaded = false;
|
||||
start = clock();
|
||||
configUtil = cUtil;
|
||||
surfaceMgr = sMgr;
|
||||
|
||||
|
||||
+6
-4
@@ -19,12 +19,14 @@ protected:
|
||||
|
||||
void LoadResources();
|
||||
|
||||
bool loaded;
|
||||
time_t start;
|
||||
|
||||
//globals
|
||||
ConfigUtility* configUtil;
|
||||
SurfaceManager* surfaceMgr;
|
||||
Image* logo;
|
||||
|
||||
//members
|
||||
bool loaded = false;
|
||||
time_t start = clock();
|
||||
Image* logo = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user