From 6a16e341ecd0cc9299610e489d2e4b2a9c850842 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 2 Jun 2013 04:00:26 +1000 Subject: [PATCH] Trying to create a fixed time slice system --- client/player.cpp | 5 ++-- client/scene_manager.cpp | 2 +- client/test_systems.cpp | 24 +++++++++++++++---- client/test_systems.hpp | 2 -- common/delta.hpp | 45 ----------------------------------- docs/TODO.txt | 4 +++- server/client_data.hpp | 2 +- server/server_application.cpp | 8 +++---- server/server_application.hpp | 2 -- 9 files changed, 31 insertions(+), 63 deletions(-) delete mode 100644 common/delta.hpp diff --git a/client/player.cpp b/client/player.cpp index d568e8b..162cc59 100644 --- a/client/player.cpp +++ b/client/player.cpp @@ -1,7 +1,7 @@ #include "player.hpp" #define ANIMATION_SPEED 100 -#define WALKING_SPEED 0.14 +#define WALKING_SPEED 140 Player::Player(SDL_Surface* s, int w, int h) : sprite(s, w, h) @@ -22,10 +22,9 @@ void Player::Update(int delta) { FaceDirection(Direction::EAST); } - constexpr double d = 1/sqrt(2); - if (motion.x != 0 && motion.y != 0) { sprite.SetInterval(ANIMATION_SPEED); + constexpr double d = 1/sqrt(2); position += motion * d * delta; } else if (motion != 0) { diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index b471e97..c324624 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -86,13 +86,13 @@ void SceneManager::LoadScene(SceneList sceneIndex) { switch(sceneIndex) { //add scene creation calls here + case SceneList::FIRST: #ifdef DEBUG case SceneList::TESTSYSTEMS: activeScene = new TestSystems(&configUtil, &surfaceMgr, &netUtil); break; #endif - case SceneList::FIRST: case SceneList::SPLASH: activeScene = new Splash(&configUtil, &surfaceMgr); break; diff --git a/client/test_systems.cpp b/client/test_systems.cpp index fcaed9f..bcbaab9 100644 --- a/client/test_systems.cpp +++ b/client/test_systems.cpp @@ -4,6 +4,8 @@ using namespace std; +#include "splash.hpp" + //------------------------- //Public access members //------------------------- @@ -16,6 +18,20 @@ TestSystems::TestSystems(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkU surfaceMgr = sMgr; netUtil = nUtil; + //subscene; load the resources + Splash* splash = new Splash(configUtil, surfaceMgr); + + while(splash->GetNextScene() == SceneList::CONTINUE) { + //wipe the screen + SDL_FillRect(splash->GetScreen(), 0, 0); + //call each user defined function + ((BaseScene*)(splash))->RunFrame(); + //give the computer a break + SDL_Delay(10); + } + delete splash; + SetNextScene(SceneList::CONTINUE); + playerCounter = currentPlayer = 0; playerMgr.New(playerCounter++, surfaceMgr->Get("elliot")); @@ -46,8 +62,8 @@ void TestSystems::FrameEnd() { } void TestSystems::Update() { - delta.Calculate(); - playerMgr.UpdateAll(delta.GetDelta()); +// Delta::Calculate(); +// playerMgr.UpdateAll(Delta::GetTime()); } string IToS(int i) { @@ -81,7 +97,7 @@ void TestSystems::MouseButtonUp(SDL_MouseButtonEvent const& button) { void TestSystems::KeyDown(SDL_KeyboardEvent const& key) { switch(key.keysym.sym) { case SDLK_ESCAPE: - SetNextScene(SceneList::MAINMENU); + QuitEvent(); break; case SDLK_w: @@ -164,5 +180,5 @@ void TestSystems::SwitchToPlayer(int index) { } void TestSystems::SendMessage(std::string s) { - // + cout << s << endl; } \ No newline at end of file diff --git a/client/test_systems.hpp b/client/test_systems.hpp index e9e9db4..ec1461e 100644 --- a/client/test_systems.hpp +++ b/client/test_systems.hpp @@ -9,7 +9,6 @@ #include "packet_list.hpp" #include "player_manager.hpp" -#include "delta.hpp" #include "frame_rate.hpp" #include "raster_font.hpp" @@ -47,7 +46,6 @@ protected: PlayerManager playerMgr; - Delta delta; FrameRate frameRate; RasterFont font; diff --git a/common/delta.hpp b/common/delta.hpp deleted file mode 100644 index 25423a0..0000000 --- a/common/delta.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* 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. -*/ -#ifndef DELTA_HPP_ -#define DELTA_HPP_ - -#include - -class Delta { -public: - Delta() { - time = tick = 0; - } - int Calculate() { - int c = clock(); - time = c - tick; - tick = c; - return time; - } - int GetDelta() const { - return time; - }; -private: - int time, tick; -}; - -#endif diff --git a/docs/TODO.txt b/docs/TODO.txt index 997fc62..091b719 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -2,4 +2,6 @@ Each client needs to know about each other client now. Have multiple players moving around the server at the same time -keep the docs up to date!!!!! \ No newline at end of file +keep the docs up to date!!!!! + +Player's internals a weird. \ No newline at end of file diff --git a/server/client_data.hpp b/server/client_data.hpp index d6e81b6..7ef1a7c 100644 --- a/server/client_data.hpp +++ b/server/client_data.hpp @@ -13,7 +13,7 @@ struct ClientData { handle = h; avatar = a; } - void Update(int delta) { + void Update(double delta) { position += motion * delta; } diff --git a/server/server_application.cpp b/server/server_application.cpp index aef3f31..b42e135 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -54,10 +54,10 @@ void ServerApplication::Proc() { } } //update the world - delta.Calculate(); - for (auto it : clientMap) { - it.second.Update(delta.GetDelta()); - } +//TODO Delta::Calculate(); +// for (auto it : clientMap) { +// it.second.Update(Delta::GetTime()); +// } //handle output... //TODO... diff --git a/server/server_application.hpp b/server/server_application.hpp index e13080f..12912c5 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -3,7 +3,6 @@ #include "client_data.hpp" -#include "delta.hpp" #include "packet_list.hpp" #include "config_utility.hpp" #include "udp_network_utility.hpp" @@ -37,7 +36,6 @@ private: //members bool running = false; - Delta delta; std::map clientMap; int maxClients = SDLNET_MAX_UDPCHANNELS; int uniqueIndex = 0;