Trying to create a fixed time slice system

This commit is contained in:
Kayne Ruse
2013-06-02 04:00:26 +10:00
parent 4c670c3a22
commit 6a16e341ec
9 changed files with 31 additions and 63 deletions
+2 -3
View File
@@ -1,7 +1,7 @@
#include "player.hpp" #include "player.hpp"
#define ANIMATION_SPEED 100 #define ANIMATION_SPEED 100
#define WALKING_SPEED 0.14 #define WALKING_SPEED 140
Player::Player(SDL_Surface* s, int w, int h) Player::Player(SDL_Surface* s, int w, int h)
: sprite(s, w, h) : sprite(s, w, h)
@@ -22,10 +22,9 @@ void Player::Update(int delta) {
FaceDirection(Direction::EAST); FaceDirection(Direction::EAST);
} }
constexpr double d = 1/sqrt(2);
if (motion.x != 0 && motion.y != 0) { if (motion.x != 0 && motion.y != 0) {
sprite.SetInterval(ANIMATION_SPEED); sprite.SetInterval(ANIMATION_SPEED);
constexpr double d = 1/sqrt(2);
position += motion * d * delta; position += motion * d * delta;
} }
else if (motion != 0) { else if (motion != 0) {
+1 -1
View File
@@ -86,13 +86,13 @@ void SceneManager::LoadScene(SceneList sceneIndex) {
switch(sceneIndex) { switch(sceneIndex) {
//add scene creation calls here //add scene creation calls here
case SceneList::FIRST:
#ifdef DEBUG #ifdef DEBUG
case SceneList::TESTSYSTEMS: case SceneList::TESTSYSTEMS:
activeScene = new TestSystems(&configUtil, &surfaceMgr, &netUtil); activeScene = new TestSystems(&configUtil, &surfaceMgr, &netUtil);
break; break;
#endif #endif
case SceneList::FIRST:
case SceneList::SPLASH: case SceneList::SPLASH:
activeScene = new Splash(&configUtil, &surfaceMgr); activeScene = new Splash(&configUtil, &surfaceMgr);
break; break;
+20 -4
View File
@@ -4,6 +4,8 @@
using namespace std; using namespace std;
#include "splash.hpp"
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
@@ -16,6 +18,20 @@ TestSystems::TestSystems(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkU
surfaceMgr = sMgr; surfaceMgr = sMgr;
netUtil = nUtil; 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; playerCounter = currentPlayer = 0;
playerMgr.New(playerCounter++, surfaceMgr->Get("elliot")); playerMgr.New(playerCounter++, surfaceMgr->Get("elliot"));
@@ -46,8 +62,8 @@ void TestSystems::FrameEnd() {
} }
void TestSystems::Update() { void TestSystems::Update() {
delta.Calculate(); // Delta::Calculate();
playerMgr.UpdateAll(delta.GetDelta()); // playerMgr.UpdateAll(Delta::GetTime());
} }
string IToS(int i) { string IToS(int i) {
@@ -81,7 +97,7 @@ void TestSystems::MouseButtonUp(SDL_MouseButtonEvent const& button) {
void TestSystems::KeyDown(SDL_KeyboardEvent const& key) { void TestSystems::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) { switch(key.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU); QuitEvent();
break; break;
case SDLK_w: case SDLK_w:
@@ -164,5 +180,5 @@ void TestSystems::SwitchToPlayer(int index) {
} }
void TestSystems::SendMessage(std::string s) { void TestSystems::SendMessage(std::string s) {
// cout << s << endl;
} }
-2
View File
@@ -9,7 +9,6 @@
#include "packet_list.hpp" #include "packet_list.hpp"
#include "player_manager.hpp" #include "player_manager.hpp"
#include "delta.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
@@ -47,7 +46,6 @@ protected:
PlayerManager playerMgr; PlayerManager playerMgr;
Delta delta;
FrameRate frameRate; FrameRate frameRate;
RasterFont font; RasterFont font;
-45
View File
@@ -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 <ctime>
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
+3 -1
View File
@@ -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 Have multiple players moving around the server at the same time
keep the docs up to date!!!!! keep the docs up to date!!!!!
Player's internals a weird.
+1 -1
View File
@@ -13,7 +13,7 @@ struct ClientData {
handle = h; handle = h;
avatar = a; avatar = a;
} }
void Update(int delta) { void Update(double delta) {
position += motion * delta; position += motion * delta;
} }
+4 -4
View File
@@ -54,10 +54,10 @@ void ServerApplication::Proc() {
} }
} }
//update the world //update the world
delta.Calculate(); //TODO Delta::Calculate();
for (auto it : clientMap) { // for (auto it : clientMap) {
it.second.Update(delta.GetDelta()); // it.second.Update(Delta::GetTime());
} // }
//handle output... //handle output...
//TODO... //TODO...
-2
View File
@@ -3,7 +3,6 @@
#include "client_data.hpp" #include "client_data.hpp"
#include "delta.hpp"
#include "packet_list.hpp" #include "packet_list.hpp"
#include "config_utility.hpp" #include "config_utility.hpp"
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
@@ -37,7 +36,6 @@ private:
//members //members
bool running = false; bool running = false;
Delta delta;
std::map<int, ClientData> clientMap; std::map<int, ClientData> clientMap;
int maxClients = SDLNET_MAX_UDPCHANNELS; int maxClients = SDLNET_MAX_UDPCHANNELS;
int uniqueIndex = 0; int uniqueIndex = 0;