zengine/test/ZTimerTest.cpp

132 lines
4.2 KiB
C++
Raw Normal View History

2002-11-21 05:40:49 +00:00
/*******************************************************************************
2002-12-29 06:50:19 +00:00
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
2002-11-21 05:40:49 +00:00
2002-12-29 06:50:19 +00:00
Licensed under a BSD-style license.
2002-11-21 05:40:49 +00:00
2002-12-29 06:50:19 +00:00
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
2002-11-21 05:40:49 +00:00
*******************************************************************************/
2002-12-29 07:09:44 +00:00
/*$Id: ZTimerTest.cpp,v 1.11 2003/01/12 19:00:25 cozman Exp $*/
2003-01-04 05:17:56 +00:00
2002-11-21 05:40:49 +00:00
#include <ZEngine.h>
#include <string>
using namespace std;
using namespace ZE;
bool Initialize()
2002-11-21 05:40:49 +00:00
{
ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf");
2003-01-04 05:16:01 +00:00
int w,h,bpp,rate;
2002-11-21 05:40:49 +00:00
bool fs;
string title;
w = cfg.GetInt("ZTimerTest","width",800);
h = cfg.GetInt("ZTimerTest","height",600);
bpp = cfg.GetInt("ZTimerTest","bpp",32);
fs = cfg.GetBool("ZTimerTest","fullscreen",false);
title = cfg.GetString("ZTimerTest","title","ZTimer Test");
2003-01-04 05:16:01 +00:00
rate = cfg.GetInt("ZTimerTest","framerate",60);
2002-11-21 05:40:49 +00:00
engine->SetupDisplay(w,h,bpp,fs);
2003-01-04 05:16:01 +00:00
engine->SetDesiredFramerate(rate);
return engine->CreateDisplay(title);
2002-11-21 05:40:49 +00:00
}
void Test()
{
ZEngine *engine = ZEngine::GetInstance();
string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
int curTimer = 0;
//Open and Setup Font and Create Images and Timers//
ZImage text[5];
ZFont font("data/almontew.ttf",48);
ZTimer TimerOne, TimerTwo(false); //Timer Two is on the SDL Timer.
//do this only once//
font.DrawText("(T)oggle | (P)ause | (U)npause",text[4]);
do
{
//In the active loop, check events first//
engine->CheckEvents();
if(engine->IsActive())
2002-11-21 05:40:49 +00:00
{
if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit();
//pause current timer//
if(engine->KeyIsPressed(SDLK_p))
2002-11-21 05:40:49 +00:00
{
switch(curTimer)
{
case 0:
engine->PauseTimer();
break;
case 1:
TimerOne.Pause();
break;
case 2:
TimerTwo.Pause();
break;
}
2002-11-21 05:40:49 +00:00
}
//unpause current timer//
if(engine->KeyIsPressed(SDLK_u))
2002-11-21 05:40:49 +00:00
{
switch(curTimer)
{
case 0:
engine->UnpauseTimer();
break;
case 1:
TimerOne.Unpause();
break;
case 2:
TimerTwo.Unpause();
break;
}
}
//switch//
if(engine->KeyIsPressed(SDLK_t))
{
if(++curTimer > 2)
curTimer = 0;
engine->Delay(200);
2002-11-21 05:40:49 +00:00
}
//Render all the fonts//
font.DrawText(FormatStr("Current Timer: %s",TimerName[curTimer].c_str()),text[0]);
font.DrawText(FormatStr("%s Time: %d",TimerName[0].c_str(),engine->GetTime()),text[1]);
font.DrawText(FormatStr("%s Time: %d",TimerName[1].c_str(),TimerOne.GetTime()),text[2]);
font.DrawText(FormatStr("%s Time: %d",TimerName[2].c_str(),TimerTwo.GetTime()),text[3]);
2002-11-21 05:40:49 +00:00
engine->Clear(); //clear screen
2002-11-21 05:40:49 +00:00
for(int i=0; i <= 4; i++)
text[i].Draw(0,i*50.0f);
engine->Update(); //update the screen
}
2002-11-21 05:40:49 +00:00
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
}
int main(int argc, char *argv[])
{
ZEngine *engine = ZEngine::GetInstance();
if(Initialize())
{
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
Test();
}
2002-11-21 05:40:49 +00:00
ZEngine::ReleaseInstance(); //release engine instance
return 0;
}