1. Phix While Loop Inside pGUI Main Loop

Pete, is there a way to run a while loop inside pGUI's main thread?

For example, if I wanted to do a high-frame FPS game with GL or somesuch, I'd need a simple while loop inside to manage game state, etc. Is that possible?

I guess I could assign that to another thread, though, and leave the main for GUI processing, but even then... can I do that without a timer?

new topic     » topic index » view message » categorize

2. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

For example, if I wanted to do a high-frame FPS game with GL or somesuch...

Would probably be better to use a library suited for game development, now that I think about it. I just saw the OpenGL (?) compatibility and my mind went on a tangent. grin

new topic     » goto parent     » topic index » view message » categorize

3. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

Would probably be better to use a library suited for game development, now that I think about it. I just saw the OpenGL (?) compatibility and my mind went on a tangent. grin

Most dedicated graphics libraries work this way. You create your own event/render loop around the library. Allegro, GLFW, SDL, etc. all work this way.

I'm actually really liking Sigil right now because of how dead simple it is: https://openeuphoria.org/forum/133840.wc

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Phix While Loop Inside pGUI Main Loop

ghaberek said...

I'm actually really liking Sigil right now because of how dead simple it is: https://openeuphoria.org/forum/133840.wc

I saw that! It's giving me that game-dev itch again, but I don't have time for that!

new topic     » goto parent     » topic index » view message » categorize

5. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

Pete, is there a way to run a while loop inside pGUI's main thread?

For example, if I wanted to do a high-frame FPS game with GL or somesuch, I'd need a simple while loop inside to manage game state, etc. Is that possible?

I guess I could assign that to another thread, though, and leave the main for GUI processing, but even then... can I do that without a timer?

Along those lines:

GTK has two "event handlers" - one "fires off" every x milliseconds, which you choose when writing the program, the other runs as fast as the processor can go , calling your Eu game function(s) whenever there isn't input from the user or a graphic update to be done.

The second would be a likely candidate for a game. EuGTK also has an openGL "container", but openGL is something that I don't know anything about, so I haven't written any demos for openGL. A wrapper for openGL calls would have to be found, modified, or written.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Phix While Loop Inside pGUI Main Loop

irv said...

GTK has two "event handlers" - one "fires off" every x milliseconds, which you choose when writing the program, the other runs as fast as the processor can go , calling your Eu game function(s) whenever there isn't input from the user or a graphic update to be done.

The second would be a likely candidate for a game. EuGTK also has an openGL "container", but openGL is something that I don't know anything about, so I haven't written any demos for openGL. A wrapper for openGL calls would have to be found, modified, or written.

This is good to know! Thanks, irv!

new topic     » goto parent     » topic index » view message » categorize

7. Re: Phix While Loop Inside pGUI Main Loop

I've spent the morning searching the web, and it appears that the best approach to doing this would be by wrapping GLFW3. It's current (most are really old) and has pre-compiled dlls for windows and excellent documentation.

https://www.glfw.org/docs/latest/index.html

OpenGL itself is awfully complex, and there are several Euphoria wrappers for openGL in the archives, if someone wants to use (modify?) those. At any rate, EuGTK just allows you to create a GLArea and obtain an openGL "context". The setup should be simple, see below. As is, this opens a window with a blank black area for drawing. The hard part is writing the openGL code, and about this, like Sergeant Schultz, "I Know Nothing. Nothing!".

include GtkEngine.e 
 
constant 
    win = create(GtkWindow,"size=300x300;border=10;$destroy=Quit"), 
    gla = create(GtkGLArea), 
    glx = get(gla,"context"), 
    clk = create(GIdle,"DoStuff"), --* calls DoStuff repeatedly, as fast as possible; 
    tik = create(GTimeout,250,"Tock") --* calls your "Tock" function 4 times per second; 
 --* = optional, use one or both, as appropriate for the game; 
 
    add(win,gla) 
     
    show_all(win) 
    connect(gla,"render","Render") -- do whenever needed; 
    main() 
     
global function DoStuff() -- fast as possible; 
-- you compute the collisions and moves here, 
-- (and, presumably, call openGL draw function) 
return 1 
end function 
     
global function Render(atom area, atom context) 
-- redraw the stuff that needs redrawing; 
-- here's where the fun starts (And I Get Lost Totally!) 
return 1 
end function 
 
global function Tock() -- do something every x milliseconds; 
return 1 -- returning 0 will shut off the tik timer; 
end function 
 
 
new topic     » goto parent     » topic index » view message » categorize

8. Re: Phix While Loop Inside pGUI Main Loop

A quick check shows that if GIdle calls a simple Eu function that just increments a variable and returns, that function will be called about 720,000 times per second (on my computer).

That makes me think that you could do quite a bit of processing inside that function, and still have the ability to do "real time" animation. I would probably set up the GTimeout to fire off at perhaps 30 times per second to re-draw the graphics. No need for more than that, you couldn't see the difference.

Also, compiling this simple program doesn't increase the speed much - maybe 750,000. Of course, if the Eu function was complex, then I'd expect compiling would be beneficial.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

Pete, is there a way to run a while loop inside pGUI's main thread?

For example, if I wanted to do a high-frame FPS game with GL or somesuch, I'd need a simple while loop inside to manage game state, etc. Is that possible?

I finally stumbled upon the answer while updating some prior code:

Define the Iup IDLE_ACTION function:

IupSetGlobalFunction("IDLE_ACTION", Icallback("idle_cb")) 

That function will be called constantly, when no other events are happening.

Pete, you might want to at least make some reference to this functionality in the Phix/pGUI docs. You also have an example that uses it, gears.exw!

new topic     » goto parent     » topic index » view message » categorize

10. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

Pete, you might want to at least make some reference to this functionality in the Phix/pGUI docs.

Wot, like http://phix.x10.mx/docs/html/callbacks.htm#IDLE_ACTION ? smile

new topic     » goto parent     » topic index » view message » categorize

11. Re: Phix While Loop Inside pGUI Main Loop

petelomax said...
euphoric said...

Pete, you might want to at least make some reference to this functionality in the Phix/pGUI docs.

Wot, like http://phix.x10.mx/docs/html/callbacks.htm#IDLE_ACTION ? smile

Yeah, exactly! grin

Let's say a user, like me, needs to find that data in the Phix docs. What would that process look like?

I obviously failed in my attempt, so future n00bs might appreciate a search function.

Wait. Is there a search function for the docs?!? shocked

new topic     » goto parent     » topic index » view message » categorize

12. Re: Phix While Loop Inside pGUI Main Loop

euphoric said...

Let's say a user, like me, needs to find that data in the Phix docs. What would that process look like?

Nothing wrong with posting questions on here when you get stuck.

euphoric said...

Wait. Is there a search function for the docs?!? shocked

There is a search facility in the chm, I also search Phix/docs/phix/src using Edita/Edix on a nearly daily basis, and if I were ever to finish loading up the whole manual to http://phix.x10.mx/pmwiki/pmwiki.php?n=Docs.Phix there is a search function on that too. Lastly I know that if you download the Euphoria docs they come with quite a decent search, however I never did get round to finding the time to investigate/crib that for use with the phix docs.

new topic     » goto parent     » topic index » view message » categorize

13. Re: Phix While Loop Inside pGUI Main Loop

petelomax said...
euphoric said...

Let's say a user, like me, needs to find that data in the Phix docs. What would that process look like?

Nothing wrong with posting questions on here when you get stuck.

I appreciate that, but if it's already in the docs, I'd at least like to be able to smartly traverse that first.

petelomax said...
euphoric said...

Wait. Is there a search function for the docs?!? shocked

There is a search facility in the chm...

That's really nice! And it's available directly from the Edita Help menu! Woo hoo!

Thank you!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu