• entries
455
639
• views
424682

# Bonsai - it aint' dead yet...

91 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 = falsewhile(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.

There are no comments to display.

## Create an account

Register a new account