projects
/
physics.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update ignore
[physics.git]
/
src
/
main.cpp
diff --git
a/src/main.cpp
b/src/main.cpp
index
d8ca3e1
..
1e9d4ad
100644
(file)
--- a/
src/main.cpp
+++ b/
src/main.cpp
@@
-61,17
+61,32
@@
bool is_Running;
* draw_Count := counts this seconds draws
* last_Second := stores the time of the last second, used for ups and fps
*/
* draw_Count := counts this seconds draws
* last_Second := stores the time of the last second, used for ups and fps
*/
-int target_UPS =
25
0;
+int target_UPS =
10
0;
long int last_Block_Update;
float update_Sum = 0;
long int last_Block_Update;
float update_Sum = 0;
-int ups
, fps
;
+int ups
=100, fps=100
;
int update_Count, draw_Count;
long int last_Second;
int update_Count, draw_Count;
long int last_Second;
+float target_time_steps_per_second = 1000;
+float times;
+float time_steps_Count;
+
+
+// experiment with rolling averages
+float rUpdate = 100;
+float rDraw = 100;
+float rInput = 100;
+float rRun = 100;
+
+float num = 10;
+
+float total = 0;
+
/// ***** MAIN Method *****
/// ***** MAIN Method *****
-int main()
+int main(
int argc, char** args
)
{
init();
run();
{
init();
run();
@@
-87,13
+102,30
@@
void init()
graphics::init();
graphics::init();
+#ifdef DEBUGGING
+ cout << "Graphics initialized" << endl;
+ cout << "Graphics initialized2" << endl;
+#endif
+
game::init();
game::init();
+#ifdef DEBUGGING
+ cout << "Game initialized" << endl;
+#endif
+
input::init();
input::init();
+#ifdef DEBUGGING
+ cout << "Input initialized" << endl;
+#endif
+
cfg::init();
#ifdef DEBUGGING
cfg::init();
#ifdef DEBUGGING
+ cout << "Configs initialized" << endl;
+#endif
+
+#ifdef DEBUGGING
cout << "Initialization Complete" << endl;
#endif
}
cout << "Initialization Complete" << endl;
#endif
}
@@
-123,18
+155,31
@@
void run()
while(is_Running)
{
while(is_Running)
{
- blockUpdate();
- updateFPSCounters();
- draw();
+ long int time;
+
+ time = tickCountMicro();
+ blockUpdate();
+ updateFPSCounters();
+ draw();
+ time = tickCountMicro() - time;
+
+ rRun = (rRun * (num-1) + time) / num;
+
+ //cout << "total:\t" << total << endl;
+ //cout << "rR:\t" << rRun << endl;
+ //total = 0;
}
}
void blockUpdate()
{
long int start = tickCountMicro();
}
}
void blockUpdate()
{
long int start = tickCountMicro();
+ long int diff = start - last_Block_Update;
+
+ //cout << "Block" << endl;
// Calculate the updates that should be run for the next draw
// Calculate the updates that should be run for the next draw
- update_Sum += (
start - last_Block_Update) / (1000000 / (float)target_UPS)
;
+ update_Sum += (
float)(diff * target_UPS) / 1000000
;
// insures the float to int cast is done once.
int iupdate_sum = (int)update_Sum;
// insures the float to int cast is done once.
int iupdate_sum = (int)update_Sum;
@@
-142,17
+187,22
@@
void blockUpdate()
// TODO the main run loop needs to be tested and pruned
if (iupdate_sum > 0)
{
// TODO the main run loop needs to be tested and pruned
if (iupdate_sum > 0)
{
- // Calculate a time step that spreads the updates out as much as possible
- // used because really quick updates are nearly wasted
- float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
+ // Calculate a time step that spreads the updates out as much as
+ // possible used because really quick updates are nearly wasted
+
+ //float time_step = ((float)diff) / iupdate_sum / 1000;
+ //float time_step = 1000 / (100000 / rUpdate) / iupdate_sum;
+ //float time_step = 1000 / ups / iupdate_sum;
+ float time_step = 10;
// run the updates
// run the updates
- for (int i =
1; i <=
iupdate_sum; i++)
+ for (int i =
0; i <
iupdate_sum; i++)
{
handleInput();
{
handleInput();
- update(time_step
*i / 1000
);
+ update(time_step);
}
}
- // remove the updates that where run from the sum
+
+ // remove the updates that were run from the sum
update_Sum -= iupdate_sum;
last_Block_Update = tickCountMicro();
}
update_Sum -= iupdate_sum;
last_Block_Update = tickCountMicro();
}
@@
-165,42
+215,77
@@
void updateFPSCounters()
{
ups = update_Count;
fps = draw_Count;
{
ups = update_Count;
fps = draw_Count;
+ times = time_steps_Count;
update_Count = 0;
draw_Count = 0;
update_Count = 0;
draw_Count = 0;
+ time_steps_Count = 0;
last_Second = tickCountMicro();
#ifdef FPSUPS
cout << "ups:\t" << ups << endl;
cout << "fps:\t" << fps << endl;
last_Second = tickCountMicro();
#ifdef FPSUPS
cout << "ups:\t" << ups << endl;
cout << "fps:\t" << fps << endl;
+ cout << "times:\t" << times << endl;
#endif
}
}
void handleInput()
{
#endif
}
}
void handleInput()
{
-
input::update()
;
+
long int time
;
- game::handleInput();
+ time = tickCountMicro();
+ input::update();
- if(cfg::endGame())
- is_Running = false;
+ game::handleInput();
+
+ if(cfg::endGame())
+ is_Running = false;
+ time = tickCountMicro() - time;
+
+ rInput = (rInput*(num-1) + time) /num;
+
+ total += rInput;
}
void update(float time_step)
{
}
void update(float time_step)
{
+ long int time;
+
update_Count++;
update_Count++;
+ time_steps_Count += time_step;
- game::update(time_step);
+ time = tickCountMicro();
+ game::update(time_step);
+ time = tickCountMicro() - time;
+
+ rUpdate = (rUpdate * (num-1) + time) / num;
+
+ //cout << "ts:\t" << time_step << endl;
+ //cout << "ru:\t" << rUpdate << endl;
+
+ total += rUpdate;
}
void draw()
{
}
void draw()
{
+ long int time;
+
draw_Count++;
draw_Count++;
- game::draw();
+ time = tickCountMicro();
+ game::draw();
+
+ SDL_GL_SwapBuffers();
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ //SDL_Delay(10);
+ time = tickCountMicro() - time;
+
+ rDraw = (rDraw*(num-1) + time) /num;
-
SDL_GL_SwapBuffers()
;
+
//cout << "rd:\t" << rDraw << endl
;
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
;
+
total += rDraw
;
}
}