用于创建计时器的 Vala/SDL 回调
我想每 200 毫秒刷新一次屏幕,而不必在循环中添加一些代码。
因此,我想使用 SDL 在 Vala 中创建一个带有回调的计时器。
我阅读了文档,但不明白第二个参数的预期内容: http:// /www.valadoc.org/sdl/SDL.Timer.html
以下代码编译时没有任何错误:
this.timer = new SDL.Timer( 200, () => { this.refresh(); return 0; } );
编辑:这是带有 SDL 的完整代码:
public View( int width, int height, bool fullscreen, string window_name = "AKITA application" )
{
SDL.init( InitFlag.VIDEO | InitFlag.TIMER );
this.last_tick = 0;
this.fps = 25; // Set default value for FPS
uint32 video_flags = SurfaceFlag.DOUBLEBUF | SurfaceFlag.HWACCEL | SurfaceFlag.HWSURFACE;
this.screen = Screen.set_video_mode( width, height, 32, video_flags);
if ( this.screen == null )
{
stderr.printf ("Could not set video mode.\n");
}
WindowManager.set_caption (window_name, "");
this.timer = new SDL.Timer( 200, () => { this.refresh(); return 0; } );
}
public void refresh()
{
stdout.printf( "refresh...\n" );
}
但没有出现任何内容(refresh()
应该在标准输出上写一些东西)。
有人可以帮我解决这个问题(或者有更好的方法来做我想做的事)吗?
谢谢,
达米安
I want to refresh my screen every 200ms without having to add some code in a loop.
So, I would like to create a Timer with a callback in Vala using SDL.
I read the documentation but I don't understand what is excpected as a second parameter : http://www.valadoc.org/sdl/SDL.Timer.html
The following code compile without any error :
this.timer = new SDL.Timer( 200, () => { this.refresh(); return 0; } );
EDIT : here is the full code with SDL :
public View( int width, int height, bool fullscreen, string window_name = "AKITA application" )
{
SDL.init( InitFlag.VIDEO | InitFlag.TIMER );
this.last_tick = 0;
this.fps = 25; // Set default value for FPS
uint32 video_flags = SurfaceFlag.DOUBLEBUF | SurfaceFlag.HWACCEL | SurfaceFlag.HWSURFACE;
this.screen = Screen.set_video_mode( width, height, 32, video_flags);
if ( this.screen == null )
{
stderr.printf ("Could not set video mode.\n");
}
WindowManager.set_caption (window_name, "");
this.timer = new SDL.Timer( 200, () => { this.refresh(); return 0; } );
}
public void refresh()
{
stdout.printf( "refresh...\n" );
}
But nothing appears (refresh()
should write something on stdout).
Could someone help me with this (or have a better way to do what I want) ?
Thanks,
Damien
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须运行事件循环(例如使用
SDL.Event.wait()
或SDL.Event.poll()
的循环),否则计时器将不会被触发。You have to run the event loop (e.g. a loop with
SDL.Event.wait()
orSDL.Event.poll()
), otherwise timers won't get fired.