#include "CRM32Pro.h"
#define EXAMPLE_VERSION "Example 9: Logic and Render Rates"
#define GFX_RESOURCE "data/gfx.dpf" // DPF with graphic resources
void RenderGraphics(int);
void RenderGraphicsGL(int);
void PrintHelp();
SDL_Surface *bg, *info, *backinfo, *surfCursor;
SDL_Rect inf;
Uint32 lastinfo = 0;
int bSmooth = -1;
int main(int argc,char *argv[])
{
Uint8 done = 0;
SDL_Event event;
int tmp = 0;
int iPos1, iDir1, iPos2, iDir2, iPos3, iDir3, iPos4, iDir4;
PrintHelp();
if(CRM32Pro.
Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
{
ILogSystem.
Msg(
LOG_NORMAL,
" · [LOG] - Couldnīt initialize CRM32Pro: %s\n",SDL_GetError());
return 1;
}
CRM32Pro.
Config.
Title = EXAMPLE_VERSION;
CRM32Pro.Config.
Icon = IImage->
Load(GFX_RESOURCE,
"icono");
{
return 1;
}
bg = IImage->
Load(GFX_RESOURCE,
"background2");
info = IImage->
Load(GFX_RESOURCE,
"info2");
inf.x = 6;inf.y = 6;inf.w = info->w;inf.h = info->h;
backinfo = IImage->
Load(GFX_RESOURCE,
"info2");
fInfo->
Load(GFX_RESOURCE,
"InfoFont");
spr1->
Load(GFX_RESOURCE,
"rabbit");
iPos1 = 0;
iDir1 = 1;
iPos2 = CRM32Pro.
screen->w - tmp;
iDir2 = -1;
iPos3 = CRM32Pro.
screen->h - tmp;
iDir3 = -1;
iPos4 = 1;
iDir4 = 1;
done = 1;
int test =0;
while(done)
{
iPos1 = iPos1 + (iDir1);
if((iPos1 < 1) || (iPos1 > CRM32Pro.
screen->h)) iDir1 = iDir1 * (-1);
iPos2 = iPos2 + (2 * iDir2);
if((iPos2 < 1) || (iPos2 > CRM32Pro.
screen->w)) iDir2 = iDir2 * (-1);
iPos3 = iPos3 + (3 * iDir3);
if((iPos3 < 1) || (iPos3 > CRM32Pro.
screen->h)) iDir3 = iDir3 * (-1);
iPos4 = iPos4 + (4 * iDir4);
if((iPos4 < 1) || (iPos4 > CRM32Pro.
screen->w)) iDir4 = iDir4 * (-1);
while(CRM32Pro.
Update(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE) done = 0;
if(event.key.keysym.sym == SDLK_F1)
{
bSmooth = bSmooth * (-1);
}
break;
case SDL_QUIT:
done = 1;
break;
break;
default:
break;
}
}
}
delete fInfo;
delete spr4;
delete spr3;
delete spr2;
delete spr1;
return 0;
}
void RenderGraphics(int bLogicUpdate)
{
char sTmp[16];
SDL_BlitSurface(bg,NULL,CRM32Pro.
screen,NULL);
SDL_BlitSurface(info,NULL,CRM32Pro.
screen,&inf);
if((lastinfo + 500) < ITimeSystem->
GetTime())
{
SDL_BlitSurface(backinfo,NULL,info,NULL);
if(bSmooth == 1) fInfo->
PutString(info,65,40,
"ON");
}
}
void RenderGraphicsGL(int bLogicUpdate)
{
char sTmp[16];
SDL_BlitSurface(bg,NULL,CRM32Pro.
screen,NULL);
SDL_BlitSurface(backinfo,NULL,CRM32Pro.
screen,NULL);
}
void PrintHelp()
{
char *sMsg;
sMsg = new char[1024];
strcpy(sMsg,"-----------------------------------------------------------\n");
strcat(sMsg," ");
strcat(sMsg,EXAMPLE_VERSION);
strcat(sMsg,"\n-----------------------------------------------------------\n\n");
strcat(sMsg," Press [ESCAPE] key to exit.\n");
strcat(sMsg," Press [F1] key to enable/disable smooth animation.\n");
strcat(sMsg," Press [RIGHT] key to increase the Logic Frame Rate.\n");
strcat(sMsg," Press [LEFT] key to decrease the Logic Frame Rate.\n");
strcat(sMsg,"\n Runtime information is logged into 'LogicRenderRates.log' file.\n");
strcat(sMsg,"\n");
#ifdef _WINDOWS
MessageBox(NULL,sMsg,"CRM32Pro SDK - HelpScreen",MB_OK);
#endif
#ifdef _LINUX
printf("CRM32Pro SDK - HelpScreen\n%s",sMsg);
#endif
delete sMsg;
}