From d76cbe13da638859c3e4ee12e9613212f74448f8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 20 May 2013 17:43:16 +1000 Subject: [PATCH] Added basic server list, and added yield calls --- client/base_scene.cpp | 22 +++++++++++++++++++++- client/lobby.cpp | 20 ++++++++++++++------ client/lobby.hpp | 9 ++++++++- client/scene_manager.cpp | 6 ++++++ docs/TODO.txt | 6 ++---- server/server.cpp | 1 + 6 files changed, 52 insertions(+), 12 deletions(-) diff --git a/client/base_scene.cpp b/client/base_scene.cpp index baa8ab9..7e1db60 100644 --- a/client/base_scene.cpp +++ b/client/base_scene.cpp @@ -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 @@ -58,7 +79,6 @@ void BaseScene::RunFrame() { FrameStart(); HandleEvents(); Update(); - SDL_FillRect(screen, 0, 0); Render(screen); SDL_Flip(screen); FrameEnd(); diff --git a/client/lobby.cpp b/client/lobby.cpp index 3fab514..5ad8e3e 100644 --- a/client/lobby.cpp +++ b/client/lobby.cpp @@ -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(&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); +} \ No newline at end of file diff --git a/client/lobby.hpp b/client/lobby.hpp index 3be922e..dcc4ee3 100644 --- a/client/lobby.hpp +++ b/client/lobby.hpp @@ -14,6 +14,11 @@ #include #include +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 serverVector; }; #endif diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index b6ec601..3cccd78 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -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(); diff --git a/docs/TODO.txt b/docs/TODO.txt index 5be5e35..ed714dd 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -1,4 +1,2 @@ -Button: - SetImageSurface() - SetFontSurface() -end \ No newline at end of file +Build an interface for the lobby +Have multiple players moving around the server at the same time diff --git a/server/server.cpp b/server/server.cpp index f0c4269..f780cce 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -22,6 +22,7 @@ void Server::Proc() { //debug // running = false; + SDL_Delay(10); } }