Help understanding CK's sources: separated video thread?

All discussion about the Commander Genius project (a Keen interpreter + more).
Post Reply
vanfanel
Meep
Posts: 2
Joined: Fri May 13, 2011 15:05

Help understanding CK's sources: separated video thread?

Post by vanfanel »

hi there,

I need some help with CK.

I've hacked a simple KMS backend for SDL 1.2, and it uses double buffering in my SDL_Flip implementation. What's more, it has a delay in SDL_Flip that waits for the flipping event to finish, in order to avoid tearing.
However, after I chose CK as a test case to polish this backend, I found some facts that have me keep wondering...

If I leave g_pTimer->TimeToDelay(), that call introduces some more delay in the game's main loop that, as a side effect, frees the cpu when there's time left after processing events and graphics in the current loop: in other words, it prevents "fast wild looping" in the game's main loop that would cause 100% CPU to be used. BUT since I introduced my own delay for each frame (in the SDL_Flip() implementation), this extra delays causes the game to miss vblanks, so it runs with less FPS than it should.

Well, my SDL_Flip() function does precissely that, too, but if I disable g_pTimer->TimeToDelay() call, I still get 100% CPU usage, wich shouldn't happen since as I said my SDL_Flip() implementation would block the program for the time remaining to the 16ms, when the "flipping complete" event takes place.

So I was wondering: does g_pVideoDriver run in a separate thread? That would explain why, even if I have the delay in the function SDL_Flip() called by g_pVideoDriver->updateScreen(), the main game loop runs like crazy and still takes 100% CPU.
If it's true, where's that thread launched? Is it at g_pVideoDriver->start() ?
How? I can't see anything in g_pVideoDriver->start() mentioning threads or the SDL fnx to manage them.

I'd like to discuss these sources more in-depth so I entered the IRC channel, but it seems to be pretty dead these days...
gerstrong
Vorticon Elite
Posts: 1244
Joined: Wed Dec 31, 2008 14:44
Location: Frankfurt - Germany
Contact:

Post by gerstrong »

hi vanfanel,

I have been on vacations lately. Please be patient, I'll visit IRC very soon so we can talk about the source.
Having fun developing stuff...
ysangkok
Meep
Posts: 1
Joined: Fri Aug 31, 2012 13:08

KMS SDL backend

Post by ysangkok »

I'd like to use this KMS SDL backend of yours. Any chance of open sourcing it? I see you're on Github, I'm sure it would be useful for others too. Maybe you would consider putting it on there?
gerstrong
Vorticon Elite
Posts: 1244
Joined: Wed Dec 31, 2008 14:44
Location: Frankfurt - Germany
Contact:

Post by gerstrong »

Well, then just use it and mention us. The code is free and available on the Github.
Having fun developing stuff...
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Post by NY00123 »

Dunno why have I thought of this only now but... guess it is a coincidence!
To the few random visitors who may be interested, looks like the KMS backend has been uploaded (very) recently.

Forum post: http://www.raspberrypi.org/phpBB3/viewt ... 78&t=25146
GitHub page: https://github.com/vanfanel/SDL12-kms-dispmanx
gerstrong
Vorticon Elite
Posts: 1244
Joined: Wed Dec 31, 2008 14:44
Location: Frankfurt - Germany
Contact:

Post by gerstrong »

Very interesting
Having fun developing stuff...
Post Reply