Skip to content

Commit

Permalink
Enable to work fps counter. #41
Browse files Browse the repository at this point in the history
  • Loading branch information
tanitta committed Oct 6, 2016
1 parent 88c8c97 commit 3bd53b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
22 changes: 20 additions & 2 deletions source/armos/app/runner.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ class Loop {
/++
FPS(Frame Per Second)を指定します.
+/
void targetFps(double fps){
void targetFps(in double fps){
fpscounter.targetFps = fps;
}

///
double targetFps()const{
return fpscounter.targetFps;
}

///
double currentFps()const{
return fpscounter.currentFps;
}
}//public

private{
Expand Down Expand Up @@ -117,6 +127,14 @@ double fpsUseRate(){
/++
FPS(Frame Per Second)を指定します.
+/
void targetFps(double fps){
void targetFps(in double fps){
mainLoop.targetFps(fps);
}

double targetFps(){
return mainLoop.targetFps;
}

double currentFps(){
return mainLoop.currentFps;
}
21 changes: 9 additions & 12 deletions source/armos/utils/fpscounter.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class FpsCounter {

void targetFps(in double fps){
_targetFps = fps;
_targetTime = convertedTimeFromFps(fps);
//convert from fps to nsecs
_targetNsecsTime = (1.0/fps*1000000000.0).to!int;
}

double targetFps()const{
Expand All @@ -39,29 +40,25 @@ class FpsCounter {

void adjust(){
immutable MonoTime after = MonoTime.currTime;
immutable def = ( after - _timer );
if( def.split.hnsecs < _targetTime){
Thread.sleep( dur!("hnsecs")( _targetTime - def.split.hnsecs ) );
immutable def = ( after.ticks - _timer.ticks ).ticksToNSecs;
if( def < _targetNsecsTime){
Thread.sleep( dur!("nsecs")( _targetNsecsTime - def ) );
}
immutable after2 = MonoTime.currTime;
immutable def2 = after2 - _timer;
_currentFps = 1.0/def2.split.hnsecs.to!double*10000000.0;
_fpsUseRate = def.split.hnsecs.to!double/_targetTime.to!double;
immutable def2 = ( after2.ticks - _timer.ticks ).ticksToNSecs;
_currentFps = 1.0/def2.to!double*1000000000.0;
_fpsUseRate = def.to!double/_targetNsecsTime.to!double;
}
}

private{
double _targetFps = 60.0;
double _currentFps = 60.0;
ulong _currentFrames = 0;
int _targetTime = 0;
int _targetNsecsTime = 0;
double _fpsUseRate = 0;
MonoTime _timer;

}
}

private int convertedTimeFromFps(in double fps){
return (1.0/fps*10000000.0).to!int;
}

0 comments on commit 3bd53b4

Please sign in to comment.