Added basic server list, and added yield calls
This commit is contained in:
+21
-1
@@ -1,3 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* 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 "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -58,7 +79,6 @@ void BaseScene::RunFrame() {
|
|||||||
FrameStart();
|
FrameStart();
|
||||||
HandleEvents();
|
HandleEvents();
|
||||||
Update();
|
Update();
|
||||||
SDL_FillRect(screen, 0, 0);
|
|
||||||
Render(screen);
|
Render(screen);
|
||||||
SDL_Flip(screen);
|
SDL_Flip(screen);
|
||||||
FrameEnd();
|
FrameEnd();
|
||||||
|
|||||||
+14
-6
@@ -57,13 +57,9 @@ void Lobby::Receive() {
|
|||||||
Packet packet;
|
Packet packet;
|
||||||
while(netUtil->Receive()) {
|
while(netUtil->Receive()) {
|
||||||
memcpy(&packet, netUtil->GetInData(), sizeof(Packet));
|
memcpy(&packet, netUtil->GetInData(), sizeof(Packet));
|
||||||
|
|
||||||
cout << "receiving" << endl;
|
|
||||||
|
|
||||||
switch(packet.type) {
|
switch(packet.type) {
|
||||||
case PacketList::PONG:
|
case PacketList::PONG:
|
||||||
cout << "dumping..." << endl;
|
PushServer(&packet);
|
||||||
cout << packet.pong.serverName << endl;
|
|
||||||
break;
|
break;
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
@@ -72,6 +68,9 @@ void Lobby::Receive() {
|
|||||||
|
|
||||||
void Lobby::Render(SDL_Surface* const screen) {
|
void Lobby::Render(SDL_Surface* const screen) {
|
||||||
pingButton.DrawTo(screen);
|
pingButton.DrawTo(screen);
|
||||||
|
for (int i = 0; i < serverVector.size(); i++) {
|
||||||
|
font.DrawStringTo(serverVector[i].name, screen, 50, 16*i + 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -109,8 +108,17 @@ void Lobby::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void Lobby::PingNetwork() {
|
void Lobby::PingNetwork() {
|
||||||
//ing the network
|
//ping the network
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.type = PacketList::PING;
|
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(Packet));
|
||||||
|
//reset the server list
|
||||||
|
serverVector.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::PushServer(Packet* packet) {
|
||||||
|
Server s;
|
||||||
|
s.name = packet->pong.serverName;
|
||||||
|
s.add = netUtil->GetInPacket()->address;
|
||||||
|
serverVector.push_back(s);
|
||||||
}
|
}
|
||||||
+8
-1
@@ -14,6 +14,11 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
struct Server {
|
||||||
|
std::string name;
|
||||||
|
IPaddress add;
|
||||||
|
};
|
||||||
|
|
||||||
class Lobby : public BaseScene {
|
class Lobby : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -37,7 +42,7 @@ protected:
|
|||||||
|
|
||||||
//utilities
|
//utilities
|
||||||
void PingNetwork();
|
void PingNetwork();
|
||||||
// void JoinRequest();
|
void PushServer(Packet*);
|
||||||
|
|
||||||
//members
|
//members
|
||||||
ConfigUtility* configUtil = nullptr;
|
ConfigUtility* configUtil = nullptr;
|
||||||
@@ -46,6 +51,8 @@ protected:
|
|||||||
|
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
Button pingButton;
|
Button pingButton;
|
||||||
|
|
||||||
|
std::vector<Server> serverVector;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -62,8 +62,14 @@ void SceneManager::Proc() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//wipe the screen
|
||||||
|
SDL_FillRect(activeScene->GetScreen(), 0, 0);
|
||||||
|
|
||||||
//call each user defined function
|
//call each user defined function
|
||||||
activeScene->RunFrame();
|
activeScene->RunFrame();
|
||||||
|
|
||||||
|
//give the computer a break
|
||||||
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadScene();
|
UnloadScene();
|
||||||
|
|||||||
+2
-4
@@ -1,4 +1,2 @@
|
|||||||
Button:
|
Build an interface for the lobby
|
||||||
SetImageSurface()
|
Have multiple players moving around the server at the same time
|
||||||
SetFontSurface()
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ void Server::Proc() {
|
|||||||
|
|
||||||
//debug
|
//debug
|
||||||
// running = false;
|
// running = false;
|
||||||
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user