/****************************************************************************/
/* Nebula2 - Tutorial 04 */
/* 使用TimeServer */
/* author: happykevins */
/****************************************************************************/
///----------------------------------------------------------------------------
/// +必要头文件
#include "kernel/nkernelserver.h"
#include "kernel/ntimeserver.h"
/// -必要头文件
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +链接库
#pragma comment(lib, "wsock32.lib")
#pragma comment(lib, "d_nkernel.lib")
/// -链接库
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +Application
int main(int argc, const char** argv)
{
/// 创建KernelServer
nKernelServer* ks = n_new(nKernelServer);
/// 获得TimeServer
nTimeServer* time = (nTimeServer*)ks->Lookup("/sys/servers/time");
double totaltime = 0;
double frametime = 0;
///----------------------------------------------------------------------------
/// +默认情况
ks->Print("*****Start Timer!***** ");
time->ResetTime();
time->StartTime();
while ( totaltime < 0.5f )
{
time->Trigger();
frametime = time->GetTime() - totaltime;
totaltime += frametime;
ks->Print("[FRAME:%f] ", frametime);
}
time->StopTime();
ks->Print("[TOTAL:%f] ", totaltime);
ks->Print("*****Stop Timer!***** ");
/// +默认情况
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +设置WaitDelta
/// @note:
/// 在WaitDeltaT<0.001时几乎没有什么作用
/// 在WaitDeltaT>=0.001时每一帧的间隔时间会远远大于0.001
time->WaitDeltaT(0.001f);
ks->Print("[WAIT:%fsec] ", time->GetWaitDeltaT());
ks->Print("*****Start Timer(WaitDeltaT)!***** ");
time->StartTime();
while ( totaltime < 2.0f )
{
time->Trigger();
frametime = time->GetTime() - totaltime;
totaltime += frametime;
ks->Print("[FRAME:%f] ", frametime);
}
time->StopTime();
ks->Print("[TOTAL:%f] ", totaltime);
ks->Print("*****Stop Timer(WaitDeltaT)!***** ");
/// -设置WaitDelta
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// +设置LockDelta
/// @note:
/// LockDeltaT的用途是锁定帧速率
/// 在LockDeltaT>0时,每一帧将不会按照真实时间来更新
time->LockDeltaT(0.1);
ks->Print("[LOCK:%fsec] ", time->GetLockDeltaT());
ks->Print("*****Start Timer(LockDeltaT)!***** ");
time->StartTime();
while ( totaltime < 4.0f )
{
time->Trigger();
frametime = time->GetTime() - totaltime;
totaltime += frametime;
ks->Print("[FRAME:%f] ", frametime);
}
time->StopTime();
ks->Print("[TOTAL:%f] ", totaltime);
ks->Print("*****Stop Timer(LockDeltaT)!***** ");
/// +设置LockDelta
///----------------------------------------------------------------------------
/// 销毁KernelServer
n_delete(ks);
getchar();
return 0;
}
/// -Application
///----------------------------------------------------------------------------