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 <stdexcept>
|
||||
@@ -58,7 +79,6 @@ void BaseScene::RunFrame() {
|
||||
FrameStart();
|
||||
HandleEvents();
|
||||
Update();
|
||||
SDL_FillRect(screen, 0, 0);
|
||||
Render(screen);
|
||||
SDL_Flip(screen);
|
||||
FrameEnd();
|
||||
|
||||
+14
-6
@@ -57,13 +57,9 @@ void Lobby::Receive() {
|
||||
Packet packet;
|
||||
while(netUtil->Receive()) {
|
||||
memcpy(&packet, netUtil->GetInData(), sizeof(Packet));
|
||||
|
||||
cout << "receiving" << endl;
|
||||
|
||||
switch(packet.type) {
|
||||
case PacketList::PONG:
|
||||
cout << "dumping..." << endl;
|
||||
cout << packet.pong.serverName << endl;
|
||||
PushServer(&packet);
|
||||
break;
|
||||
//...
|
||||
}
|
||||
@@ -72,6 +68,9 @@ void Lobby::Receive() {
|
||||
|
||||
void Lobby::Render(SDL_Surface* const 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() {
|
||||
//ing the network
|
||||
//ping the network
|
||||
Packet packet;
|
||||
packet.type = PacketList::PING;
|
||||
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 <string>
|
||||
|
||||
struct Server {
|
||||
std::string name;
|
||||
IPaddress add;
|
||||
};
|
||||
|
||||
class Lobby : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
@@ -37,7 +42,7 @@ protected:
|
||||
|
||||
//utilities
|
||||
void PingNetwork();
|
||||
// void JoinRequest();
|
||||
void PushServer(Packet*);
|
||||
|
||||
//members
|
||||
ConfigUtility* configUtil = nullptr;
|
||||
@@ -46,6 +51,8 @@ protected:
|
||||
|
||||
RasterFont font;
|
||||
Button pingButton;
|
||||
|
||||
std::vector<Server> serverVector;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -62,8 +62,14 @@ void SceneManager::Proc() {
|
||||
continue;
|
||||
}
|
||||
|
||||
//wipe the screen
|
||||
SDL_FillRect(activeScene->GetScreen(), 0, 0);
|
||||
|
||||
//call each user defined function
|
||||
activeScene->RunFrame();
|
||||
|
||||
//give the computer a break
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
UnloadScene();
|
||||
|
||||
+2
-4
@@ -1,4 +1,2 @@
|
||||
Button:
|
||||
SetImageSurface()
|
||||
SetFontSurface()
|
||||
end
|
||||
Build an interface for the lobby
|
||||
Have multiple players moving around the server at the same time
|
||||
|
||||
@@ -22,6 +22,7 @@ void Server::Proc() {
|
||||
|
||||
//debug
|
||||
// running = false;
|
||||
SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user