Smooth gameloop with TinyGL?
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Hi.

    I have tested different ways to have a smooth game loop with TinyGL. I have tested glTimerFunc and glIdleFunc. glTimerFunc gives a low cpu use, but i can't get a smooth game loop. With glIdleFunc works at full cpu use, but even in this case it have small jumps. I tried to added some code to put the task at idle state, using delay function doesn't gives an accurate game loop, it's minimal value is 1/50 seconds, i have used also sleep function but it didn't appear to do nothing. Any idea to make a smooth game loop?

    [ Edited by BalrogSoft on 2011/2/3 21:12 ]
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »03.02.11 - 20:12
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I have modified Feathers TinyGL example, i have added three defines at top of feathers.c. TEST_1 compiles one version that uses glIdleFunc, at full cpu use, on my MacMini system it show small jumps. TEST_2 compiles with glTimerFunc, it doesn't work smooth. Last test is TEST_3, it's the same that TEST_1 but a WaitTOF call was added at the end of display function, it doesn't work smooth on my system. Here is the pack:

    Feathers TinyGL example
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »03.02.11 - 23:06
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    for me the same results as you :D

    from whai i've sperimented, the SDL timer is a good gameloop timer.
    so in turn you can/must use the system timer function.

    look at the powersdl sources ,the file is morphos/SDL_systimer.c (but is a little mess :D )

    Or use SDL+GL directly

    8-)
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »04.02.11 - 10:34
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Well, now i know that it's not my system at least. I will make more tests, a Mac mini system should be enough to run a simple 2d engine smoothly, feathers example have small jumps, but on a 3d enviroment it doesn't looks too bad, but a 2d game with elements moving at a constant speed, this small jumps are more notable. SDL is an option, but it add a extra layer to the game, that isn't really need.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »04.02.11 - 11:29
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    maybe i've found a little error in your example.
    when using the glut timer function, you must reset the timer callback inside the timer function.

    ----- old code ----
    void ctimer(int value)
    {
    glutPostRedisplay();
    }

    ------ new code ----
    void ctimer(int value)
    {
    glutPostRedisplay();
    glutTimerFunc(20, ctimer, 1);
    }

    with this trick the animation run smooth
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »04.02.11 - 13:31
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    This is correct, i have read GLUT documentation, and glutTimerFunc only makes one call, for this reason is need to call again glutTimerFunc, but on TinyGL implementation it calls every slice of time defined on glultTimerFunc. Anyway adding this line of code, it works like using glutIdleFunc, it have small jumps, and cpu is busy at 100%.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »04.02.11 - 13:49
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    here with this modified code i have no jumps, and the cpu is at least to 20-30% full

    in addition i have the mac mini 1.25 with the same 2.5 release of morphos (i've forgotten to update to 2.8)

    maybe it's the compiler?
    here i've compiled it with amidevcpp (so gcc 2.95.3)

    edit: now it jumps (mostly the rotating skybox):D :D
    but it's the 6th time i launched it, if i reset the machine the first try it dosn't jump.

    [ Edited by raistlin77it on 2011/2/4 14:38 ]
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »04.02.11 - 14:30
    Profile
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Andreas_Wolf
    Posts: 12073 from 2003/5/22
    From: Germany
    > i've forgotten to update to 2.8

    Yeah, time machine broken here as well ;-)
  • »04.02.11 - 18:26
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    Quote:


    Andreas_Wolf wrote:
    > i've forgotten to update to 2.8

    Yeah, time machine broken here as well ;-)


    eheheheh indeed :D
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »04.02.11 - 20:06
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I have updated the feathers example to use SDL, and it appears that it has same problems than TinyGL version. Here is the code:

    feathers.c

    [ Edited by BalrogSoft on 2011/2/5 1:42 ]
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »05.02.11 - 00:41
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    amigadave
    Posts: 2794 from 2006/3/21
    From: Northern Calif...
    Quote:


    raistlin77it wrote:
    here with this modified code i have no jumps, and the cpu is at least to 20-30% full

    in addition i have the mac mini 1.25 with the same 2.5 release of morphos (i've forgotten to update to 2.8)

    maybe it's the compiler?
    here i've compiled it with amidevcpp (so gcc 2.95.3)

    edit: now it jumps (mostly the rotating skybox):D :D
    but it's the 6th time i launched it, if i reset the machine the first try it dosn't jump.

    [ Edited by raistlin77it on 2011/2/4 14:38 ]


    Since you say it doesn't happen when run right after a reboot and you are using a 1.25GHz MacMini that only has 32mb VRAM, could it have something to do with your computer running low on VRAM after it has been running for a while and you run this code?

    Just an "uneducated" guess.
    MorphOS - The best Next Gen Amiga choice.
  • »05.02.11 - 06:58
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    Quote:


    amigadave wrote:

    Since you say it doesn't happen when run right after a reboot and you are using a 1.25GHz MacMini that only has 32mb VRAM, could it have something to do with your computer running low on VRAM after it has been running for a while and you run this code?

    Just an "uneducated" guess.


    no , no way.
    the program should not jump (like the feather scrensaver)

    so back on topic pls.

    i've downloaded your example modified for sdl.

    The first error come in my mind is :

    you use the sdl, but not the timer to update at desidered frame rate the demo.

    Here some modification i've made in a hurry :
    http://pastebin.com/PYXPic2P

    A good example of an fps limiter is here http://sdl.beuc.net/sdl.wiki/Time_Examples

    [ Edited by raistlin77it on 2011/2/5 12:23 ]

    [ Edited by raistlin77it on 2011/2/5 13:38 ]
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »05.02.11 - 12:11
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Quote:


    The first error come in my mind is :

    you use the sdl, but not the timer to update at desidered frame rate the demo.



    Yes, the verion posted was a dirty adaptation to sdl, i was playing with the sdl version later, and added a SDL_Delay, and it seem to work even worse.

    I tried to compile with GCC 4.4.4 and 2.95.3, and it have same behavior.

    I have read a lot about how to order render commands with swap buffer to optimize the execution of cpu and gpu in parallel, but it doesn't solve the small jumps.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »05.02.11 - 21:03
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Quote:


    The first error come in my mind is :

    you use the sdl, but not the timer to update at desidered frame rate the demo.



    Yes, the verion posted was a dirty adaptation to sdl, i was playing with the sdl version later, and added a SDL_Delay, and it seem to work even worse.

    I tried to compile with GCC 4.4.4 and 2.95.3, and it have same behavior.

    I have read a lot about how to order render commands with swap buffer to optimize the execution of cpu and gpu in parallel, but it doesn't solve the small jumps.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »05.02.11 - 21:14
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Trying feathers screensaver, i just found that if you change screen mode, for example 640x480 instead clone actual screen mode, it runs with small jumps. I have changed feathers sdl example, to run at same resolution, and it works very well, it have small jumps also, but only a few, it works fine most of time.

    Edited:

    After some testings, it doesn't work fine as i said. I have added SetTaskPri to set an higher priority, but it makes small jumps.

    [ Edited by BalrogSoft on 2011/2/6 2:37 ]
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »06.02.11 - 00:16
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 575 from 2003/2/24
    From: finland, the l...
    You did try running the task at higher priority than the default 0?
  • »06.02.11 - 00:30
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    i don't know what to think :S

    the scrensaver here look smooth, on every resolution.

    pls test this demo (an unifinished port by me ) it uses sdl+gl and uses the same delay from the code i've pasted.

    you need an dual analog joystick to play (in poseidon select the 2 sticks as 2 joystick separately on port 1 and 0 and enable the analog hack )

    http://www.mediafire.com/?gfzap97z551cvqg

    here it dosn't jump , and there are a lot of polygon/particle
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »06.02.11 - 13:42
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I found that the game i'm developing works without jumps on windowed mode, but at fullscreen, it has small jumps. Anyway the demo works with small jumps on my system. I have changed the screen resolution and task priority to +5 on my game, and it works fine, there are a few jumps but aren't very notable.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »06.02.11 - 14:15
    Profile Visit Website