|
|
发表于 2007-6-7 08:19:00
|
显示全部楼层
Re:讨论:效率最高的游戏循环,怎么写?
你都别用windows,用linux!!!不用linux也用SDL吧!你在编opengl,又不是directX.
SDL 是这个,SDL_PollEvent()
- /* wait for events */
- while ( !done )
- {
- /* handle the events in the queue */
- while ( SDL_PollEvent( &event ) )
- {
- switch( event.type )
- {
- case SDL_ACTIVEEVENT:
- /* Something's happend with our focus
- * If we lost focus or we are iconified, we
- * shouldn't draw the screen
- */
- if ( event.active.gain == 0 )
- isActive = FALSE;
- else
- isActive = TRUE;
- break;
- case SDL_VIDEORESIZE:
- /* handle resize event */
- surface = SDL_SetVideoMode( event.resize.w,
- event.resize.h,
- 16, videoFlags );
- if ( !surface )
- {
- fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
- Quit( 1 );
- }
- resizeWindow( event.resize.w, event.resize.h );
- break;
- case SDL_KEYDOWN:
- /* handle key presses */
- handleKeyPress( &event.key.keysym );
- break;
- case SDL_QUIT:
- /* handle quit requests */
- done = TRUE;
- break;
- default:
- break;
- }
- }
- /* draw the scene */
- if ( isActive )
- drawGLScene( );
- }
复制代码
我本人以为,100是 O(100) = 1。 想想,很少会有100msg...
重要是看那理慢,该那了加速!Windows MSG不是你的bottle neck!
|
|