From 5dea53ad50707141bdad707bc974780601280409 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 19 Aug 2014 02:52:15 +1000 Subject: [PATCH] Removed delta time system from the framework --- client/character.cpp | 8 ++++---- client/character.hpp | 2 +- client/client_application.cpp | 6 +++--- client/scenes/base_scene.cpp | 4 ++-- client/scenes/base_scene.hpp | 4 ++-- client/scenes/clean_up.cpp | 2 +- client/scenes/clean_up.hpp | 2 +- client/scenes/in_world.cpp | 10 +++++----- client/scenes/in_world.hpp | 2 +- client/scenes/lobby_menu.cpp | 6 +++--- client/scenes/lobby_menu.hpp | 2 +- client/scenes/main_menu.cpp | 2 +- client/scenes/main_menu.hpp | 2 +- client/scenes/options_menu.cpp | 2 +- client/scenes/options_menu.hpp | 2 +- client/scenes/splash_screen.cpp | 2 +- client/scenes/splash_screen.hpp | 2 +- common/gameplay/character_defines.hpp | 2 +- 18 files changed, 31 insertions(+), 31 deletions(-) diff --git a/client/character.cpp b/client/character.cpp index eaa38d8..70ee4a9 100644 --- a/client/character.cpp +++ b/client/character.cpp @@ -21,14 +21,14 @@ */ #include "character.hpp" -void Character::Update(double delta) { +void Character::Update() { if (motion.x && motion.y) { - origin += motion * delta * CHARACTER_WALKING_MOD; + origin += motion * CHARACTER_WALKING_MOD; } else if (motion != 0) { - origin += motion * delta; + origin += motion; } - sprite.Update(delta); + sprite.Update(0.016); } void Character::DrawTo(SDL_Surface* const dest, int camX, int camY) { diff --git a/client/character.hpp b/client/character.hpp index bde4268..23924a4 100644 --- a/client/character.hpp +++ b/client/character.hpp @@ -40,7 +40,7 @@ public: Character() = default; ~Character() = default; - void Update(double delta); + void Update(); //graphics void DrawTo(SDL_Surface* const, int camX, int camY); diff --git a/client/client_application.cpp b/client/client_application.cpp index 16ad96c..75a9d9b 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -120,7 +120,6 @@ void ClientApplication::Proc() { //prepare the time system typedef std::chrono::steady_clock Clock; - std::chrono::duration delta(16); Clock::time_point simTime = Clock::now(); Clock::time_point realTime; @@ -138,8 +137,9 @@ void ClientApplication::Proc() { //simulate game time while (simTime < realTime) { //call each user defined function - activeScene->RunFrame(double(delta.count()) / std::chrono::duration::period::den); - simTime += delta; + activeScene->RunFrame(); + //~60 FPS + simTime += std::chrono::duration(16); } //draw the game to the screen diff --git a/client/scenes/base_scene.cpp b/client/scenes/base_scene.cpp index e4e8043..d4b7824 100644 --- a/client/scenes/base_scene.cpp +++ b/client/scenes/base_scene.cpp @@ -75,10 +75,10 @@ SceneList BaseScene::GetNextScene() const { //Frame loop //------------------------- -void BaseScene::RunFrame(double delta) { +void BaseScene::RunFrame() { FrameStart(); HandleEvents(); - Update(delta); + Update(); FrameEnd(); } diff --git a/client/scenes/base_scene.hpp b/client/scenes/base_scene.hpp index a4bfd88..d954ca0 100644 --- a/client/scenes/base_scene.hpp +++ b/client/scenes/base_scene.hpp @@ -40,13 +40,13 @@ public: SceneList GetNextScene() const; //Frame loop - virtual void RunFrame(double delta); + virtual void RunFrame(); virtual void RenderFrame(); protected: virtual void FrameStart() {} virtual void HandleEvents(); - virtual void Update(double delta) {} + virtual void Update() {} virtual void FrameEnd() {} virtual void Render(SDL_Surface* const screen) {} diff --git a/client/scenes/clean_up.cpp b/client/scenes/clean_up.cpp index fab06fd..1be9e5c 100644 --- a/client/scenes/clean_up.cpp +++ b/client/scenes/clean_up.cpp @@ -80,7 +80,7 @@ CleanUp::~CleanUp() { //Frame loop //------------------------- -void CleanUp::Update(double delta) { +void CleanUp::Update() { if (std::chrono::steady_clock::now() - startTick > std::chrono::duration(10)) { SetNextScene(SceneList::MAINMENU); } diff --git a/client/scenes/clean_up.hpp b/client/scenes/clean_up.hpp index 7ab48bd..a408d3d 100644 --- a/client/scenes/clean_up.hpp +++ b/client/scenes/clean_up.hpp @@ -50,7 +50,7 @@ public: protected: //Frame loop - void Update(double delta); + void Update(); void Render(SDL_Surface* const); //Event handlers diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index b2de46c..f78103f 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -92,17 +92,17 @@ void InWorld::FrameStart() { // } -void InWorld::Update(double delta) { +void InWorld::Update() { //suck in and process all waiting packets - SerialPacket* packetBuffer = static_cast(malloc(MAX_PACKET_SIZE)); + SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); while(network.Receive(packetBuffer)) { HandlePacket(packetBuffer); } - free(static_cast(packetBuffer)); + delete reinterpret_cast(packetBuffer); //update the characters for (auto& it : characterMap) { - it.second.Update(delta); + it.second.Update(); } //check the map @@ -129,7 +129,7 @@ void InWorld::Update(double delta) { } if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) { - localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta)); + localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion())); localCharacter->SetMotion({0,0}); localCharacter->CorrectSprite(); SendPlayerUpdate(); diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index c72ff73..e263bc8 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -59,7 +59,7 @@ public: protected: //Frame loop void FrameStart(); - void Update(double delta); + void Update(); void FrameEnd(); void RenderFrame(); void Render(SDL_Surface* const); diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index d866159..80504c3 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -82,13 +82,13 @@ void LobbyMenu::FrameStart() { // } -void LobbyMenu::Update(double delta) { +void LobbyMenu::Update() { //suck in and process all waiting packets - SerialPacket* packetBuffer = static_cast(malloc(MAX_PACKET_SIZE)); + SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); while(network.Receive(packetBuffer)) { HandlePacket(packetBuffer); } - free(static_cast(packetBuffer)); + delete reinterpret_cast(packetBuffer); } void LobbyMenu::FrameEnd() { diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index 7020ac8..03160c2 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -47,7 +47,7 @@ public: protected: //Frame loop void FrameStart(); - void Update(double delta); + void Update(); void FrameEnd(); void Render(SDL_Surface* const); diff --git a/client/scenes/main_menu.cpp b/client/scenes/main_menu.cpp index ca82ef8..5aa431b 100644 --- a/client/scenes/main_menu.cpp +++ b/client/scenes/main_menu.cpp @@ -72,7 +72,7 @@ void MainMenu::FrameStart() { // } -void MainMenu::Update(double delta) { +void MainMenu::Update() { // } diff --git a/client/scenes/main_menu.hpp b/client/scenes/main_menu.hpp index 2dec3ae..9572499 100644 --- a/client/scenes/main_menu.hpp +++ b/client/scenes/main_menu.hpp @@ -37,7 +37,7 @@ public: protected: //Frame loop void FrameStart(); - void Update(double delta); + void Update(); void FrameEnd(); void Render(SDL_Surface* const); diff --git a/client/scenes/options_menu.cpp b/client/scenes/options_menu.cpp index 539cd44..7aa2493 100644 --- a/client/scenes/options_menu.cpp +++ b/client/scenes/options_menu.cpp @@ -59,7 +59,7 @@ void OptionsMenu::FrameStart() { // } -void OptionsMenu::Update(double delta) { +void OptionsMenu::Update() { // } diff --git a/client/scenes/options_menu.hpp b/client/scenes/options_menu.hpp index 8570644..5bb3eed 100644 --- a/client/scenes/options_menu.hpp +++ b/client/scenes/options_menu.hpp @@ -38,7 +38,7 @@ public: protected: //Frame loop void FrameStart(); - void Update(double delta); + void Update(); void FrameEnd(); void Render(SDL_Surface* const); diff --git a/client/scenes/splash_screen.cpp b/client/scenes/splash_screen.cpp index 2c3b233..5473d79 100644 --- a/client/scenes/splash_screen.cpp +++ b/client/scenes/splash_screen.cpp @@ -40,7 +40,7 @@ SplashScreen::~SplashScreen() { //Frame loop //------------------------- -void SplashScreen::Update(double delta) { +void SplashScreen::Update() { if (std::chrono::steady_clock::now() - startTick > std::chrono::duration(1)) { SetNextScene(SceneList::MAINMENU); } diff --git a/client/scenes/splash_screen.hpp b/client/scenes/splash_screen.hpp index 9d55c0c..c6440c1 100644 --- a/client/scenes/splash_screen.hpp +++ b/client/scenes/splash_screen.hpp @@ -36,7 +36,7 @@ public: protected: //Frame loop - void Update(double delta); + void Update(); void Render(SDL_Surface* const); //members diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp index 43777e0..484fcfa 100644 --- a/common/gameplay/character_defines.hpp +++ b/common/gameplay/character_defines.hpp @@ -25,7 +25,7 @@ #include //the speeds that the characters move -constexpr double CHARACTER_WALKING_SPEED = 140.0; +constexpr double CHARACTER_WALKING_SPEED = 2.24; constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); //the bounds for the character objects, mapped to the default sprites