zengine/test/ZTimerTest.cpp

122 lines
3.7 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
2002-11-21 05:40:49 +00:00
#include <ZEngine.h>
#include <string>
using namespace std;
using namespace ZE;
void Initialize()
{
ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf");
int w,h,bpp;
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");
engine->SetupDisplay(w,h,bpp,fs);
2002-11-28 23:15:52 +00:00
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->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit();
//pause current timer//
if(engine->KeyIsPressed(SDLK_p))
{
switch(curTimer)
{
case 0:
engine->PauseTimer();
break;
case 1:
TimerOne.Pause();
break;
case 2:
TimerTwo.Pause();
break;
}
}
//unpause current timer//
if(engine->KeyIsPressed(SDLK_u))
{
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;
2002-11-28 23:15:52 +00:00
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]);
engine->Clear(); //clear screen
for(int i=0; i <= 4; i++)
2002-12-03 06:34:09 +00:00
text[i].Draw(0,i*50.0f);
2002-11-21 05:40:49 +00:00
2002-12-12 02:57:32 +00:00
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();
Initialize();
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
Test();
ZEngine::ReleaseInstance(); //release engine instance
return 0;
}