本文整理汇总了C++中SDL_AddTimer函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_AddTimer函数的具体用法?C++ SDL_AddTimer怎么用?C++ SDL_AddTimer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_AddTimer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_AddTimer
void *SDLStub::addTimer(uint32 delay, TimerCallback callback, void *param) {
return SDL_AddTimer(delay, (SDL_NewTimerCallback)callback, param);
}
示例2: game_loop
//.........这里部分代码省略.........
// rotate to a new position
tetromino_setNextPosition(current_tetromino);
tetromino_setShape(current_tetromino, current_tetromino->type,
current_tetromino->position);
// make sure the new position doesn't cause any collisions
// if it does, reverse the rotation
if (grid_checkCollision(grid, current_tetromino)) {
tetromino_setPrevPosition(current_tetromino);
tetromino_setShape(current_tetromino, current_tetromino->type,
current_tetromino->position);
}
break;
case SPACE_KEY:
tetromino_moveDown(current_tetromino);
// move the tetromino down until it causes a collision
while (!grid_checkCollision(grid, current_tetromino)) {
tetromino_moveDown(current_tetromino);
}
// once we have a collision, move it back into place
tetromino_moveUp(current_tetromino);
break;
case PAUSE_KEY:
debug_print("Pausing game");
game.paused = !game.paused;
// stop the game timer
if (game.paused) {
SDL_RemoveTimer(timer);
timer = NULL;
}
else { // start it again
timer = SDL_AddTimer(1000, game_updateTime, NULL);
}
break;
case ESCAPE_KEY:
// pause game updates
debug_print("Escape key pressed.");
// toggle paused game state if we're in game
if (grid && current_tetromino) {
game.paused = !game.paused;
if (game.paused) { // stop couting time played
SDL_RemoveTimer(timer);
timer = NULL;
}
// starting timer again, only if we're still in a game
else if (grid && current_tetromino) {
timer = SDL_AddTimer(1000, game_updateTime, NULL);
}
}
// show or hide the menu
if (grid && current_tetromino) {
ui_toggleMenuVisible();
}
// enable ui message pump if its visible
if (ui_isMenuVisible()) {
// if we're in game, show in-game menu
if (grid && current_tetromino) {
ui_menuPageSetCurrentById(MENU_IN_GAME);
}
// otherwise show main menu
else {
示例3: main
int
main(int argc, char *argv[])
{
int i, desired;
SDL_TimerID t1, t2, t3;
Uint64 start, now;
if (SDL_Init(SDL_INIT_TIMER) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
/* Start the timer */
desired = 0;
if (argv[1]) {
desired = atoi(argv[1]);
}
if (desired == 0) {
desired = DEFAULT_RESOLUTION;
}
SDL_SetTimer(desired, ticktock);
/* Wait 10 seconds */
printf("Waiting 10 seconds\n");
SDL_Delay(10 * 1000);
/* Stop the timer */
SDL_SetTimer(0, NULL);
/* Print the results */
if (ticks) {
fprintf(stderr,
"Timer resolution: desired = %d ms, actual = %f ms\n",
desired, (double) (10 * 1000) / ticks);
}
/* Test multiple timers */
printf("Testing multiple timers...\n");
t1 = SDL_AddTimer(100, callback, (void *) 1);
if (!t1)
fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
t2 = SDL_AddTimer(50, callback, (void *) 2);
if (!t2)
fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
t3 = SDL_AddTimer(233, callback, (void *) 3);
if (!t3)
fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());
/* Wait 10 seconds */
printf("Waiting 10 seconds\n");
SDL_Delay(10 * 1000);
printf("Removing timer 1 and waiting 5 more seconds\n");
SDL_RemoveTimer(t1);
SDL_Delay(5 * 1000);
SDL_RemoveTimer(t2);
SDL_RemoveTimer(t3);
start = SDL_GetPerformanceCounter();
for (i = 0; i < 1000000; ++i) {
ticktock(0);
}
now = SDL_GetPerformanceCounter();
printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Quit();
return (0);
}
示例4: schedule_refresh
/* schedule a video refresh in 'delay' ms */
static void schedule_refresh(VideoState *is, int delay) {
SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
}
示例5: main
int main(int argc, const char * argv[]) {
SDL_Surface *ecran = NULL, *zozor = NULL;
SDL_Rect positionZozor;
SDL_Event event;
SDL_TimerID timer;
char continuer = 1;
char versLaDroite = 1, versLeBas = 1;
char pause = 0;
int tempsPrecedent = 0, tempsActuel = 0;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
timer = SDL_AddTimer(30, bougerZozor, &positionZozor);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion du temps en SDL", NULL);
zozor = SDL_LoadBMP("zozor.bmp");
SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));
positionZozor.x = ecran->w / 2 - zozor->w / 2;
positionZozor.y = ecran->h / 2 - zozor->h / 2;
SDL_EnableKeyRepeat(10, 10);
while (continuer) {
SDL_PollEvent(&event);
switch (event.type) {
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_p:
pause = !pause;
break;
case SDLK_ESCAPE:
continuer = 0;
break;
default:
break;
}
break;
}
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > TIMER)
{
if (!pause) {
if (positionZozor.x + zozor->w == ecran->w) {
versLaDroite = 0;
}else if (positionZozor.x == 0) {
versLaDroite = 1;
}
if (positionZozor.y + zozor->h == ecran->h) {
versLeBas = 0;
} else if (positionZozor.y == 0) {
versLeBas = 1;
}
if (versLaDroite) {
positionZozor.x++;
} else {
positionZozor.x--;
}
if (versLeBas) {
positionZozor.y++;
} else {
positionZozor.y--;
}
}
tempsPrecedent = tempsActuel;
}
else
{
SDL_Delay(TIMER - (tempsActuel - tempsPrecedent));
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(zozor, NULL, ecran, &positionZozor);
SDL_Flip(ecran);
}
SDL_RemoveTimer(timer);
SDL_FreeSurface(zozor);
SDL_Quit();
return EXIT_SUCCESS;
}
示例6: main
int main(int argc, char *argv[])
{
// Variables
SDL_Surface *ecran = NULL,*texte=NULL, *imgFond = NULL, *imgCar = NULL, *tileset = NULL, *imgTrain = NULL, *menutrain=NULL,*bouton1=NULL,*bouton0=NULL,*bouton2=NULL;
SDL_Rect position_texte_menu;
SDL_Event event;//variable event
T_VOIT car[NBCARMAX], cartmp;
T_BOUTON bout[8];
int continuer;
int menucontinuer;
int nbVoitures;
int flag;
int flag1;
flag=0;
flag1=0;
int flag2;
flag2=0;
int transparence;
int i;
int j;
int u;
int tabbouton[8];
int positionsourisx;
int positionsourisy;
// Variables du Timer
SDL_TimerID idTimerTrain, idTimerCar;
int periode;
int tmp;
tmp=0;
// initialisation
continuer = 1;
periode = 10;
setParamVoiture(&car[0],1,358,0); // car[0] -> le train
affichageParamVoiture(car[0]); // le train
nbVoitures = 1;
tileset = SDL_LoadBMP("route.bmp");
//initialisation fmod
FMOD_SYSTEM *system;
FMOD_System_Create(&system);
FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);
FMOD_SOUND *circulation = NULL,*train = NULL,*menu=NULL,*defilement=NULL;
FMOD_System_CreateSound(system, "circulation.wav", FMOD_CREATESAMPLE, 0, &circulation);
FMOD_System_CreateSound(system, "train.wav", FMOD_CREATESAMPLE, 0, &train);
FMOD_System_CreateSound(system, "menu.mid", FMOD_CREATESAMPLE, 0, &menu);
FMOD_System_CreateSound(system, "defilement.wav", FMOD_CREATESAMPLE, 0, &defilement);
// SDL init
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
idTimerTrain = SDL_AddTimer(periode,actualisePosTrain,&car[0]);
idTimerCar = SDL_AddTimer(periode,actualisePosVoitures,car);
ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Premiere collision de vehicules ...", NULL);
imgCar = SDL_LoadBMP("voiture.bmp");
imgTrain = SDL_LoadBMP("train.bmp");
menutrain = SDL_LoadBMP("mapmenu.bmp");
bouton1 = SDL_LoadBMP("boutonappuyer.bmp");
bouton2 = SDL_LoadBMP("boutonselectionner.bmp");
bouton0 = SDL_LoadBMP("bouton.bmp");
SDL_SetColorKey(bouton0, SDL_SRCCOLORKEY, SDL_MapRGB(bouton0->format, 255, 255, 255));
//
TTF_Init();
TTF_Font *police = NULL;
SDL_Color couleurNoire = {0, 0, 0};
police = TTF_OpenFont("airwaves.ttf", 50);
position_texte_menu.x = 500;
position_texte_menu.y = 500;
for(i=0;i<8;i++)
{
setParambouton(&bout[i],0, 50,37+64*i);
}
for (transparence = 0 ; transparence <= 255 ;transparence++)
{
SDL_SetAlpha(menutrain, SDL_SRCALPHA,transparence);
SDL_BlitSurface(menutrain, NULL, ecran, NULL);
SDL_Flip(ecran);
}
//FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, menu, 0, NULL);
for(i=0;i<8;i++)
{
if(i==0)
{
for(j=0;j<485;j=j+5)
{
setParambouton(&bout[i],0, 50,j);
SDL_BlitSurface(menutrain, NULL, ecran, NULL);
SDL_BlitSurface(bouton0, NULL, ecran, &bout[i].pos);
for(u=0;u<=i;u++)
{
//.........这里部分代码省略.........
示例7: main
int main(int argc,char* argv[])
{
SDL_Surface *screen;
SDL_Surface *ball_bmp;
struct ball red_ball, blue_ball;
SDL_TimerID timer, timer2;
int done;
/*The following code does the initialization for Audio and Video*/
int i_error=SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
/*If initialization is unsuccessful, then quit */
if(i_error==-1)
exit(1);
atexit(SDL_Quit);
/* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
* */
screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
if ( screen == NULL )
{
fprintf(stderr, "Couldn't set 640x480x8 video mode: %sn",SDL_GetError());
exit(1);
}
/* Load the BMP file into a surface */
red_ball.ball_bmp = SDL_LoadBMP("ball.bmp");
if (red_ball.ball_bmp == NULL) {
fprintf(stderr, "Couldn't load %s: %sn", "ball.bmp", SDL_GetError());
exit(1);
}
/* Load the BMP file into a surface */
blue_ball.ball_bmp = SDL_LoadBMP("ball2.bmp");
if (blue_ball.ball_bmp == NULL) {
fprintf(stderr, "Couldn't load %s: %sn", "ball2.bmp", SDL_GetError());
exit(1);
}
/*
* Palettized screen modes will have a default palette (a standard
* 8*8*4 colour cube), but if the image is palettized as well we can
* use that palette for a nicer colour matching.
* */
if (red_ball.ball_bmp->format->palette && screen->format->palette) {
SDL_SetColors(screen, ball_bmp->format->palette->colors, 0, ball_bmp->format->palette->ncolors);
}
/* Blit onto the screen surface */
if(SDL_BlitSurface(red_ball.ball_bmp, NULL, screen, NULL) < 0)
fprintf(stderr, "BlitSurface error: %sn", SDL_GetError());
if(SDL_BlitSurface(blue_ball.ball_bmp, NULL, screen, NULL) < 0)
fprintf(stderr, "BlitSurface error: %sn", SDL_GetError());
SDL_UpdateRect(screen, 0, 0, red_ball.ball_bmp->w, red_ball.ball_bmp->h);
//This could be put in an init function:
red_ball.startx=0; red_ball.starty=0; red_ball.destx=0; red_ball.desty=0;
red_ball.x = (float)red_ball.startx; red_ball.y = (float)red_ball.starty;
red_ball.dx = 0.0; red_ball.dy = 0.0;
red_ball.screen = screen;
blue_ball.startx=0; blue_ball.starty=0; blue_ball.destx=0; blue_ball.desty=0;
blue_ball.x = (float)blue_ball.startx; blue_ball.y = (float)blue_ball.starty;
blue_ball.dx = 0.0; blue_ball.dy = 0.0;
blue_ball.screen = screen;
timer = SDL_AddTimer(20, move_ball, &red_ball);
SDL_Delay(10);
timer2 = SDL_AddTimer(20, move_ball, &blue_ball);
//printf("So far.\n");
/*Handle the keyboards events here. Catch the SDL_Quit event to exit*/
done = 0;
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_MOUSEBUTTONDOWN:
{
switch(event.button.button)
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
int i;
preld_sf = malloc(sizeof(SDL_Surface *) * num_pages);
for (i = 0; i < num_pages; i++) {
preld_sf[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | 0,
screen->w,
screen->h,
32,
CAIROSDL_RMASK,
CAIROSDL_GMASK,
CAIROSDL_BMASK, 0);
draw_page(pg_sf, cr, document, i + 1);
SDL_BlitSurface(pg_sf, NULL, preld_sf[i], NULL);
}
}
while (SDL_WaitEvent(&event)) {
int new_page = 0;
switch (event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) {
goto done;
} else if (event.key.keysym.sym == SDLK_SPACE) {
new_page = 1;
++page_num;
} else if (event.key.keysym.sym == SDLK_RIGHT) {
new_page = 1;
++page_num;
} else if (event.key.keysym.sym == SDLK_LEFT) {
new_page = 1;
--page_num;
} else if (event.key.keysym.sym == SDLK_PAGEUP) {
new_page = 1;
--page_num;
} else if (event.key.keysym.sym == SDLK_PAGEDOWN) {
new_page = 1;
++page_num;
}
if (new_page) {
SDL_Rect sr, sd;
float x;
SDL_RemoveTimer(t);
if (page_num > num_pages)
page_num = num_pages;
if (page_num < 1)
page_num = 1;
src_sf = pg_sf;
if (!prerender)
draw_page(pg_sf, cr, document,
page_num);
else {
src_sf = preld_sf[page_num - 1];
}
SDL_BlitSurface(src_sf, NULL, screen, NULL);
ofs = num_pages - page_num;
ofs /= num_pages;
x = n1l->w;
x *= ofs;
sr.x = x;
sr.w = n1l->w - x;
sr.h = n1l->h;
sr.y = 0;
#ifndef NYAN_TOP
sd.y = screen->h - n1l->h;
#else
sd.y = 0;
#endif
sd.w = sr.w;
sd.x = 0;
sd.h = sr.h;
SDL_BlitSurface(page_num & 1 ? n1l : n2l, &sr,
screen, &sd);
SDL_Flip(screen);
t = SDL_AddTimer(1000, timer_cb, NULL);
}
break;
case SDL_QUIT:
goto done;
case SDL_USEREVENT:
SDL_BlitSurface(src_sf, NULL, screen, NULL);
SDL_Flip(screen);
break;
default:
break;
}
}
done:
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}
示例9: HandleEvent
bool SDLApplication::Update () {
SDL_Event event;
event.type = -1;
#if (!defined (IPHONE) && !defined (EMSCRIPTEN))
if (active && (firstTime || WaitEvent (&event))) {
firstTime = false;
HandleEvent (&event);
event.type = -1;
if (!active)
return active;
#endif
while (SDL_PollEvent (&event)) {
HandleEvent (&event);
event.type = -1;
if (!active)
return active;
}
currentUpdate = SDL_GetTicks ();
#if defined (IPHONE)
if (currentUpdate >= nextUpdate) {
event.type = SDL_USEREVENT;
HandleEvent (&event);
event.type = -1;
}
#elif defined (EMSCRIPTEN)
event.type = SDL_USEREVENT;
HandleEvent (&event);
event.type = -1;
#else
if (currentUpdate >= nextUpdate) {
SDL_RemoveTimer (timerID);
OnTimer (0, 0);
} else if (!timerActive) {
timerActive = true;
timerID = SDL_AddTimer (nextUpdate - currentUpdate, OnTimer, 0);
}
}
#endif
return active;
}
示例10: main
//.........这里部分代码省略.........
fm->build_floor(0,10,40);
fm->build_floor(1,12,38);
fm->build_floor(2,14,36);
fm->changeFloorLeft(1, 11);
office *of = new office(11,1,tm,gt);
fm->addBuilding(1, of);
of->occupied = true;
office *of2 = new office(20,1,tm,gt);
fm->addBuilding(1, of2);
//////////////////////////////////////////////////////
done = 0;
while ( !done ) {
/* Check for events */
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_MOUSEMOTION:
mousex = event.motion.x;
mousey = event.motion.y;
break;
case SDL_USEREVENT:
if(event.type==SDL_USEREVENT) {
glClear( GL_COLOR_BUFFER_BIT );
bg->drawBG();
fg->drawFG();
mg->drawMenu();
SDL_GL_SwapBuffers();
Uint32 time = 50;
timer1 = SDL_AddTimer(time, game_event_push, NULL);
}
break;
case (SDL_USEREVENT+1):
if(event.type==(SDL_USEREVENT+1)) {
// timer2 = SDL_AddTimer(84000, rent_event_push, 0);
}
break;
case SDL_MOUSEBUTTONDOWN:
// toolLayerClicked(event.button.x,event.button.y);
break;
case SDL_MOUSEBUTTONUP:
//toolLayerUnClicked(event.button.x,event.button.y);
break;
case SDL_VIDEORESIZE:
screen_width = event.resize.w;
screen_height = event.resize.h;
/*screen=SDL_SetVideoMode(screen_width,screen_height, 16, SDL_OPENGL | SDL_RESIZABLE);
if (screen == NULL) {
fprintf(stderr,"Unable to grab surface after resize event: %s\n",SDL_GetError());
exit(1);
}*/
glOrtho(0.0f, 1000, 1000, 0.0f, -1.0f, 1.0f);
glViewport( 0, 0, screen_width, screen_height );
glLoadIdentity();
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym){
case SDLK_q:
removetimers();
示例11: main
int main (int argc, char *argv[])
{
SDL_Surface *screen;
int before = 0;
int delta = 0;
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
fprintf (stderr, "Failed to init SDL: %s\n", SDL_GetError ());
return -1;
}
atexit (SDL_Quit);
PDL_Init (0);
atexit (PDL_Quit);
screen = SDL_SetVideoMode (0, 0, 0, SDL_SWSURFACE);
if (!screen) {
fprintf (stderr, "Failed to set video mode: %s\n", SDL_GetError ());
return -1;
}
SDL_Event event;
while (true) {
if (paused) {
//switch to WaitEvent on pause because it blocks
SDL_WaitEvent (&event);
if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1 && event.active.state & SDL_APPACTIVE) {
paused = false;
continue;
}
//while not active the OS may ask us to draw anyway, don't ignore it
if (event.type == SDL_VIDEOEXPOSE) {
draw_frame (screen);
}
}
else {
before = SDL_GetTicks ();
while (SDL_PollEvent (&event)) {
process_event (event);
}
draw_frame (screen);
//we don't want to draw too fast, limit framerate
delta = SDL_GetTicks () - before;
while (delta < TICKS_PER_FRAME) {
//we setup a timer that sends a user (custom) event
SDL_TimerID timer = SDL_AddTimer (TICKS_PER_FRAME - delta, limiter, NULL);
//clear the event type and wait for another event
event.type = -1;
SDL_WaitEvent (&event);
//if it wasn't the user event process it and loop
SDL_RemoveTimer (timer);
if (event.type != SDL_USEREVENT) {
process_event (event);
//some time has passed, reset delta
delta = SDL_GetTicks () - before;
}
else {
break;
}
}
printf ("FPS: %d\n", 1000 / (SDL_GetTicks () - before));
}
}
return 0;
}
示例12: addtimers
void addtimers(unsigned int timer1_time, unsigned int timer2_time) {
//timer2 = SDL_AddTimer(timer2_time, rent_event_push, 0); // 84000
timer1 = SDL_AddTimer(timebase, game_event_push, 0);
}
示例13: av_setup
/**
* Setup SDL audio, video and window subsystems.
*/
void
av_setup(void)
{
#ifdef PACKAGE_BUILD
std::string title(PACKAGE_NAME " " PACKAGE_VERSION " build " PACKAGE_BUILD);
#else
std::string title(PACKAGE_STRING);
#endif
display::graphics.create(title, (options.want_fullscreen == 1));
#ifdef SET_SDL_ICON
char *icon_path;
if ((icon_path = locate_file("moon_32x32.bmp", FT_IMAGE))) {
SDL_Surface *icon = SDL_LoadBMP(icon_path);
if (icon != NULL) {
SDL_WM_SetIcon(icon, NULL);
} else {
INFO2("setting icon failed: %s\n", SDL_GetError());
}
free(icon_path);
}
#endif
fade_info.step = 1;
fade_info.steps = 1;
do_fading = 1;
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
if (have_audio) {
int i = 0;
audio_desired.freq = 11025;
audio_desired.format = AUDIO_S16SYS;
audio_desired.channels = 1;
/* audio was unresponsive on win32 so let's use shorter buffer */
audio_desired.samples = 2048; /* was 8192 */
audio_desired.callback = audio_callback;
/* initialize audio channels */
for (i = 0; i < AV_NUM_CHANNELS; ++i) {
Channels[i].volume = AV_MAX_VOLUME;
Channels[i].mute = 0;
Channels[i].chunk = NULL;
Channels[i].chunk_tailp = &Channels[i].chunk;
Channels[i].offset = 0;
}
/* we don't care what we got, library will convert for us */
if (SDL_OpenAudio(&audio_desired, NULL) < 0) {
ERROR2("SDL_OpenAudio error: %s", SDL_GetError());
NOTICE1("disabling audio");
have_audio = 0;
} else {
SDL_PauseAudio(0);
}
}
SDL_AddTimer(30, sdl_timer_callback, NULL);
}
示例14: mOptions
//.........这里部分代码省略.........
#endif
const int width = config.getIntValue("screenwidth");
const int height = config.getIntValue("screenheight");
const int bpp = 0;
const bool fullscreen = config.getBoolValue("screen");
const bool hwaccel = config.getBoolValue("hwaccel");
// Try to set the desired video mode
if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel))
{
logger->error(strprintf("Couldn't set %dx%dx%d video mode: %s",
width, height, bpp, SDL_GetError()));
}
// Initialize for drawing
graphics->_beginDraw();
Theme::prepareThemePath();
// Initialize the item and emote shortcuts.
itemShortcut = new ItemShortcut;
emoteShortcut = new EmoteShortcut;
gui = new Gui(graphics);
// Initialize sound engine
try
{
if (config.getBoolValue("sound"))
sound.init();
sound.setSfxVolume(config.getIntValue("sfxVolume"));
sound.setNotificationsVolume(config.getIntValue("notificationsVolume"));
sound.setMusicVolume(config.getIntValue("musicVolume"));
}
catch (const char *err)
{
mState = STATE_ERROR;
errorMessage = err;
logger->log("Warning: %s", err);
}
// Initialize keyboard
keyboard.init();
// Initialise player relations
player_relations.init();
userPalette = new UserPalette;
setupWindow = new Setup;
sound.playMusic(branding.getStringValue("loginMusic"));
// Initialize default server
mCurrentServer.hostname = options.serverName;
mCurrentServer.port = options.serverPort;
loginData.username = options.username;
loginData.password = options.password;
loginData.remember = config.getBoolValue("remember");
loginData.registerLogin = false;
if (mCurrentServer.hostname.empty())
mCurrentServer.hostname = branding.getValue("defaultServer","").c_str();
if (mCurrentServer.port == 0)
{
mCurrentServer.port = (short) branding.getValue("defaultPort",
DEFAULT_PORT);
mCurrentServer.type = ServerInfo::parseType(
branding.getValue("defaultServerType", "tmwathena"));
}
if (chatLogger)
chatLogger->setServerName(mCurrentServer.hostname);
if (loginData.username.empty() && loginData.remember)
loginData.username = config.getStringValue("username");
if (mState != STATE_ERROR)
mState = STATE_CHOOSE_SERVER;
// Initialize logic and seconds counters
tick_time = 0;
mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, NULL);
mSecondsCounterId = SDL_AddTimer(1000, nextSecond, NULL);
// Initialize frame limiting
SDL_initFramerate(&mFpsManager);
listen(Event::ConfigChannel);
//TODO: fix having to fake a option changed event
Event fakeevent(Event::ConfigOptionChanged);
fakeevent.setString("option", "fpslimit");
event(Event::ConfigChannel, fakeevent);
// Initialize PlayerInfo
PlayerInfo::init();
}
示例15: l_mainloop
static int l_mainloop(lua_State *L)
{
luaL_checktype(L, 1, LUA_TTHREAD);
lua_State *dispatcher = lua_tothread(L, 1);
fps_ctrl *fps_control = (fps_ctrl*)lua_touserdata(L, luaT_upvalueindex(1));
SDL_TimerID timer = SDL_AddTimer(30, timer_frame_callback, nullptr);
SDL_Event e;
while(SDL_WaitEvent(&e) != 0)
{
bool do_frame = false;
bool do_timer = false;
do
{
int nargs;
switch(e.type)
{
case SDL_QUIT:
goto leave_loop;
case SDL_KEYDOWN:
lua_pushliteral(dispatcher, "keydown");
lua_pushstring(dispatcher, SDL_GetKeyName(e.key.keysym.sym));
l_push_modifiers_table(dispatcher, e.key.keysym.mod);
lua_pushboolean(dispatcher, e.key.repeat != 0);
nargs = 4;
break;
case SDL_KEYUP:
lua_pushliteral(dispatcher, "keyup");
lua_pushstring(dispatcher, SDL_GetKeyName(e.key.keysym.sym));
nargs = 2;
break;
case SDL_TEXTINPUT:
lua_pushliteral(dispatcher, "textinput");
lua_pushstring(dispatcher, e.text.text);
nargs = 2;
break;
case SDL_TEXTEDITING:
lua_pushliteral(dispatcher, "textediting");
lua_pushstring(dispatcher, e.edit.text);
lua_pushinteger(dispatcher, e.edit.start);
lua_pushinteger(dispatcher, e.edit.length);
nargs = 4;
break;
case SDL_MOUSEBUTTONDOWN:
lua_pushliteral(dispatcher, "buttondown");
lua_pushinteger(dispatcher, e.button.button);
lua_pushinteger(dispatcher, e.button.x);
lua_pushinteger(dispatcher, e.button.y);
nargs = 4;
break;
case SDL_MOUSEBUTTONUP:
lua_pushliteral(dispatcher, "buttonup");
lua_pushinteger(dispatcher, e.button.button);
lua_pushinteger(dispatcher, e.button.x);
lua_pushinteger(dispatcher, e.button.y);
nargs = 4;
break;
case SDL_MOUSEWHEEL:
lua_pushliteral(dispatcher, "mousewheel");
lua_pushinteger(dispatcher, e.wheel.x);
lua_pushinteger(dispatcher, e.wheel.y);
nargs = 3;
break;
case SDL_MOUSEMOTION:
lua_pushliteral(dispatcher, "motion");
lua_pushinteger(dispatcher, e.motion.x);
lua_pushinteger(dispatcher, e.motion.y);
lua_pushinteger(dispatcher, e.motion.xrel);
lua_pushinteger(dispatcher, e.motion.yrel);
nargs = 5;
break;
case SDL_WINDOWEVENT:
switch (e.window.event) {
case SDL_WINDOWEVENT_FOCUS_GAINED:
lua_pushliteral(dispatcher, "active");
lua_pushinteger(dispatcher, 1);
nargs = 2;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
lua_pushliteral(dispatcher, "active");
lua_pushinteger(dispatcher, 0);
nargs = 2;
break;
default:
nargs = 0;
break;
}
break;
case SDL_USEREVENT_MUSIC_OVER:
lua_pushliteral(dispatcher, "music_over");
nargs = 1;
break;
case SDL_USEREVENT_CPCALL:
if(luaT_cpcall(L, (lua_CFunction)e.user.data1, e.user.data2))
{
SDL_RemoveTimer(timer);
lua_pushliteral(L, "callback");
return 2;
}
//.........这里部分代码省略.........