packet is being sent and received, bare-bones ping-pong is working
This commit is contained in:
+2
-1
@@ -8,12 +8,13 @@ using namespace std;
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
InGame::InGame(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
||||
InGame::InGame(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkUtility* nUtil) {
|
||||
#ifdef DEBUG
|
||||
cout << "entering InGame" << endl;
|
||||
#endif
|
||||
configUtil = cUtil;
|
||||
surfaceMgr = sMgr;
|
||||
netUtil = nUtil;
|
||||
}
|
||||
|
||||
InGame::~InGame() {
|
||||
|
||||
+6
-3
@@ -5,11 +5,13 @@
|
||||
|
||||
#include "config_utility.hpp"
|
||||
#include "surface_manager.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "packet_list.hpp"
|
||||
|
||||
class InGame : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
InGame(ConfigUtility*, SurfaceManager*);
|
||||
InGame(ConfigUtility*, SurfaceManager*, UDPNetworkUtility*);
|
||||
virtual ~InGame();
|
||||
|
||||
protected:
|
||||
@@ -27,8 +29,9 @@ protected:
|
||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//members
|
||||
ConfigUtility* configUtil;
|
||||
SurfaceManager* surfaceMgr;
|
||||
ConfigUtility* configUtil = nullptr;
|
||||
SurfaceManager* surfaceMgr = nullptr;
|
||||
UDPNetworkUtility* netUtil = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+33
-5
@@ -9,18 +9,24 @@ using namespace std;
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
Lobby::Lobby(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
||||
Lobby::Lobby(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkUtility* nUtil) {
|
||||
#ifdef DEBUG
|
||||
cout << "entering Lobby" << endl;
|
||||
#endif
|
||||
//globals
|
||||
configUtil = cUtil;
|
||||
surfaceMgr = sMgr;
|
||||
netUtil = nUtil;
|
||||
|
||||
//members
|
||||
font.SetSurface(surfaceMgr->Get("font"));
|
||||
pingButton.GetImage()->SetSurface(surfaceMgr->Get("button"));
|
||||
pingButton.SetX(50);
|
||||
pingButton.SetY(50);
|
||||
|
||||
//ping the network, ping the preset "phone home" servers
|
||||
//generate the server list
|
||||
//eventually
|
||||
|
||||
SetNextScene(SceneList::TESTSYSTEMS);
|
||||
}
|
||||
|
||||
Lobby::~Lobby() {
|
||||
@@ -42,11 +48,27 @@ void Lobby::FrameEnd() {
|
||||
}
|
||||
|
||||
void Lobby::Update() {
|
||||
//
|
||||
Receive();
|
||||
}
|
||||
|
||||
void Lobby::Receive() {
|
||||
//dump to the console
|
||||
Packet packet;
|
||||
while(netUtil->Receive()) {
|
||||
memcpy(&packet, netUtil->GetInData(), sizeof(Packet));
|
||||
|
||||
switch(packet.type) {
|
||||
case PacketList::PONG:
|
||||
cout << "dumping..." << endl;
|
||||
cout << packet.pong.buffer << endl;
|
||||
break;
|
||||
//...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
pingButton.DrawTo(screen);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -70,6 +92,12 @@ void Lobby::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
//debugging
|
||||
Packet packet;
|
||||
packet.type = PacketList::PING;
|
||||
netUtil->Send("127.0.0.1", 2000, reinterpret_cast<void*>(&packet), sizeof(Packet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -5,11 +5,16 @@
|
||||
|
||||
#include "config_utility.hpp"
|
||||
#include "surface_manager.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "packet_list.hpp"
|
||||
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
class Lobby : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
Lobby(ConfigUtility*, SurfaceManager*);
|
||||
Lobby(ConfigUtility*, SurfaceManager*, UDPNetworkUtility*);
|
||||
virtual ~Lobby();
|
||||
|
||||
protected:
|
||||
@@ -17,6 +22,7 @@ protected:
|
||||
virtual void FrameStart();
|
||||
virtual void FrameEnd();
|
||||
virtual void Update();
|
||||
virtual void Receive();
|
||||
virtual void Render(SDL_Surface* const);
|
||||
|
||||
//Event handlers
|
||||
@@ -27,8 +33,12 @@ protected:
|
||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//members
|
||||
ConfigUtility* configUtil;
|
||||
SurfaceManager* surfaceMgr;
|
||||
ConfigUtility* configUtil = nullptr;
|
||||
SurfaceManager* surfaceMgr = nullptr;
|
||||
UDPNetworkUtility* netUtil = nullptr;
|
||||
|
||||
RasterFont font;
|
||||
Button pingButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,10 +33,15 @@ SceneManager::~SceneManager() {
|
||||
}
|
||||
|
||||
void SceneManager::Init() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO))
|
||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||
throw(std::runtime_error("Failed to initialize SDL"));
|
||||
}
|
||||
if (SDLNet_Init()) {
|
||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||
}
|
||||
|
||||
configUtil.Load("rsc/config.cfg");
|
||||
netUtil.Open(0, sizeof(Packet));
|
||||
|
||||
//set the screen from the config file
|
||||
int flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
|
||||
@@ -66,6 +71,7 @@ void SceneManager::Proc() {
|
||||
|
||||
void SceneManager::Quit() {
|
||||
UnloadScene();
|
||||
SDLNet_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
@@ -80,7 +86,7 @@ void SceneManager::LoadScene(SceneList sceneIndex) {
|
||||
//add scene creation calls here
|
||||
#ifdef DEBUG
|
||||
case SceneList::TESTSYSTEMS:
|
||||
activeScene = new TestSystems(&configUtil, &surfaceMgr);
|
||||
activeScene = new TestSystems(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -92,10 +98,10 @@ void SceneManager::LoadScene(SceneList sceneIndex) {
|
||||
activeScene = new MainMenu(&configUtil, &surfaceMgr);
|
||||
break;
|
||||
case SceneList::INGAME:
|
||||
activeScene = new InGame(&configUtil, &surfaceMgr);
|
||||
activeScene = new InGame(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
case SceneList::LOBBY:
|
||||
activeScene = new Lobby(&configUtil, &surfaceMgr);
|
||||
activeScene = new Lobby(&configUtil, &surfaceMgr, &netUtil);
|
||||
break;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "config_utility.hpp"
|
||||
#include "surface_manager.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "packet_list.hpp"
|
||||
|
||||
#include "SDL/SDL.h"
|
||||
|
||||
@@ -28,6 +30,7 @@ private:
|
||||
|
||||
ConfigUtility configUtil;
|
||||
SurfaceManager surfaceMgr;
|
||||
UDPNetworkUtility netUtil;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,12 +8,13 @@ using namespace std;
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
TestSystems::TestSystems(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
||||
TestSystems::TestSystems(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkUtility* nUtil) {
|
||||
#ifdef DEBUG
|
||||
cout << "entering TestSystems" << endl;
|
||||
#endif
|
||||
configUtil = cUtil;
|
||||
surfaceMgr = sMgr;
|
||||
netUtil = nUtil;
|
||||
|
||||
playerCounter = currentPlayer = 0;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "config_utility.hpp"
|
||||
#include "surface_manager.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "packet_list.hpp"
|
||||
|
||||
#include "player_manager.hpp"
|
||||
#include "delta.hpp"
|
||||
@@ -16,7 +18,7 @@
|
||||
class TestSystems : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
TestSystems(ConfigUtility*, SurfaceManager*);
|
||||
TestSystems(ConfigUtility*, SurfaceManager*, UDPNetworkUtility*);
|
||||
virtual ~TestSystems();
|
||||
|
||||
protected:
|
||||
@@ -39,8 +41,9 @@ protected:
|
||||
void SendMessage(std::string);
|
||||
|
||||
//members
|
||||
ConfigUtility* configUtil;
|
||||
SurfaceManager* surfaceMgr;
|
||||
ConfigUtility* configUtil = nullptr;
|
||||
SurfaceManager* surfaceMgr = nullptr;
|
||||
UDPNetworkUtility* netUtil = nullptr;
|
||||
|
||||
PlayerManager playerMgr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user