Sign in to follow this  
  • entries
    455
  • comments
    639
  • views
    422460

Bonsai - it aint' dead yet...

Sign in to follow this  
_the_phantom_

55 views

Tonight I took it upon myself to do some coding, a rare event indeed of late (aside from work, where I have burst of activity during the day between reading web comics and playing vectorTD).

I figured it was time I hacked the event system into Bonsai, if only because at some point I need to process keyboard input and the events are kinda important for that [grin]

I decided to model it on the PyGame method; you ask for events and then you can process them as you want. When you ask for the events you run the event pump as well to get the events moving.

At the moment the event system is very tied to my OpenGL Window Framework's way of working; at some point I'll do some voodoo on this so that other systems can be compiled/plugged in instead, such as *shudder* SDL or some other windowing library to let games work on other platforms (well, GTL is cross platform and so is Lua so it'd be a shame to have the windowing code screw things up).

However, regardless of what happens in the backend I intend to keep the main loop looking like this;


quit = false
while(quit == false)
do
events = bonsai.getEvents()
for i = 1, #events
do
if events.message == bonsai.Event.types.quit
then
quit = true
end
end

eng:startFrame()
eng:renderQuads(imgs)
eng:renderText(0,100,"Testing",font,{r=0,g=255,b=255})

img:update()
img2:update()

eng:endFrame()
end



"getEvents" returns a table with a number of event tables in it; each event table has 'message', 'param1' and 'param2' entries in them so that you can extract the event information. The params aren't always valid for all messages.

Right now it supports all the messages OGLWFW does, which is kinda 'the big 6';
- quit
- close
- destroy
- size
- move
- active

At some point I'll add support for mouse move, click and scroll events as well as keyboard input, with the final one being top of my list right now as I need it for the game.

Returning to the 'plugable' idea, I'll probably just have a system where I'll get Lua to load a windowing DLL for me, which would nicely isolate the main Bonsai code from the windowing system; end of the day it doesn't need to know HOW you handle events or make a window, just that it's done in a sane way; from there any windowing system implimenting the correct interface could be used.

I'll puzzle out the refactoring for that tomorrow I think, for now I'm feeling happy with the code and I'm going to bed.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now