Just curious, how taxing would it be to create a framework that runs it's loops entirely off Events rather than just a while(true) loop? Are there any implications to doing it this way?
Reason I ask is, the Framework is being written to organize various components separately:
I.E.
Framework (top level, manages all Handlers)
|
V
FormHandler, InputHandler, GraphicsHandler, NetworkingHandler, GameHandler
Each "Handler" is managing a seperate part of the game basically, and the loop goes as follows:
Everything is initialized.
Game.Start() calls Game.Tick()
------------------------------
Game.Tick fires a Tick event
Framework listening for Tick events, receives event
Framework calls Application.DoEvents()
Framework calls on the GraphicsHandler to render the next frame
Framework calls on the InputHandler to poll input
Framework calls on the NetworkHandler to check for whatever.
Framework will exit the application if any response from the handlers tells it to
If everything checks out Framework calls Game.Tick
Game.Tick fires a Tick event...
repeat
Is this poor design? Would I be better doing this another way? I didn't notice any noticeable performance hit during debugging (maybe 1-2 FPS out of a mere 1000'ish?), and it seems like everything runs somewhat smoothly.
I was looking for a good way to organize the code but I don't know if this will be shooting myself in the foot later down the road or not. Just thought I'd ask any experts in devising organized code and event handling. Thanks!
Also, if for any reason you think threading would be a better way to go performance-wise, let me know so I can start researching that a bit. I only know the basics of threading.
[C#] Question about Custom Event Handlers and designing a framework
Started by Mephs, Jul 31 2008 05:32 PM
4 replies to this topic
#1
Posted 31 July 2008 - 05:32 PM
#2
Posted 31 July 2008 - 05:47 PM
Best way is to keep it simple. Anything else is most likely poor design.
Sounds like a while-loop will do the trick, so why look for anything else? :) My experience with event-based systems, is that they're more difficult to debug, and can cause more problems with update order. Better with a few calls in a while loop which you can just shuffle around as needed, and step straight into using the debugger...
Sounds like a while-loop will do the trick, so why look for anything else? :) My experience with event-based systems, is that they're more difficult to debug, and can cause more problems with update order. Better with a few calls in a while loop which you can just shuffle around as needed, and step straight into using the debugger...
- www.mattiasgustavsson.com - My blog and current projects
- www.rivtind.com - My Fantasy world and isometric RPG engine
- www.pixieuniversity.com - My Software 2D Game Engine
#3
Posted 31 July 2008 - 05:55 PM
Mattias Gustavsson said:
Best way is to keep it simple. Anything else is most likely poor design.
Sounds like a while-loop will do the trick, so why look for anything else? :) My experience with event-based systems, is that they're more difficult to debug, and can cause more problems with update order. Better with a few calls in a while loop which you can just shuffle around as needed, and step straight into using the debugger...
Sounds like a while-loop will do the trick, so why look for anything else? :) My experience with event-based systems, is that they're more difficult to debug, and can cause more problems with update order. Better with a few calls in a while loop which you can just shuffle around as needed, and step straight into using the debugger...
Well the main reason of doing it this way is just to base everything off the Tick event, which is more of a way of the framework "confirming" everything is in working order and in synch, there really aren't any other major events going on during the main loop.
The way the framework is supposed to work (at least how I wrote it up) is interchanging these messages between the different handlers so later when I implement the network code it is more easily transferrable to sending those messages to the server and the server can send the same kind of messages back to the client (really neatly packed messages, at that =)).
I figure why not just make a GameHandler that sends tick events after each just in case I need it. Is this going to kill me other than for debugging purposes?
Also, this is really just going to be a Framework that I was going to release as a separate part of the game. I wanted to make it as simple as possible to set up and seperate the component handlers so people could use things that they like from the Framework without having to be forced into using my loop.
Also might make recycling some of the code easier in subsequent projects, or if I just scrap it altogether and don't want to retype it all out.
#4
Posted 31 July 2008 - 06:35 PM
I still think you're overcomplicating it. Make the game first, then break it out into a framework if you see a need to....
- www.mattiasgustavsson.com - My blog and current projects
- www.rivtind.com - My Fantasy world and isometric RPG engine
- www.pixieuniversity.com - My Software 2D Game Engine
#5
Posted 31 July 2008 - 07:40 PM
Mattias Gustavsson said:
I still think you're overcomplicating it.
Probably :D
I'm using a half-half concept now, trying to see how that goes. I.E. the game loop is still sending Tick events to the Framework but not relying on them for the main loop. It is in it's own confined (while) loop, and the Framework pokes the other Handlers each game tick instead of relying completely on events to perform it's loop.
Using the full event loop method I was getting really wierd hangs when the window lost focus, now that problem is solved and the FPS even went up a tad (like 5 avg). I like the general ease in changing separate parts of the game using this method so far, but mostly just in experimenting between the two ways of writing it.
If it starts getting overwhelmingly complicated I'll probably just KISS.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












