TGame or not?

BlitzMax Forums/BlitzMax Programming/TGame or not?

tonyg(Posted 2008) [#1]
I'm currently creating a TGame 'singleton' and then using the instance for all my commands
e.g. local mygame:TGame=new TGame
game.update()
game.draw()
Because EVERYTHING is done through that single Game instance it ends up simply passing methods onto other managers (statemanager, mediamanager etc).
It's working OK *BUT* it just seems odd to always have to say game.something().
I am also checking a list of functions which 'wraps' all the various methods which seems to read better :
e.g. InitGame
Loaddata
Update
Draw
To some degree it seems like Bmax where you can use the command (function) or the method (object) to do the same thing. Other than cosmetics what are any other pros/cons of putting everything withing a wrapper object as opposed to everything in a number of wrapper functions?


Schragnasher(Posted 2008) [#2]
im doing this as well, for things that make sense im putting them into tgameengine (in my case). But if it doesnt really fit, then whats wrong with just having a nice global function for it? There really isnt that much that doesnt make sense outside of a gameengine type or a gamestate type


tonyg(Posted 2008) [#3]
You see everything DOES fit in my TGame (TGameEngine or TGameManager or whatever). It just seems odd calling a method for the same object for every 'command'. It might just be a cosmetic thing but, really, that's what I am asking here for.


Schragnasher(Posted 2008) [#4]
yeah i understand. Why not setup some functions outside of the type that do things. like a PlaySound() function that you can call from anywhere to play a sound.


tonyg(Posted 2008) [#5]
Yep. I am trying that and it seems to make more sense.
Playsound() will call mediamanager.playsound(). MediaManager playsound() loads the sound if needed (it loads most media files are startup) and then plays it.
The same thing happened with Game.Playsound().
Maybe using functions is frowned upon rather than methods? Maybe the wrapper messes up encapsulation (or whatever it's called) but that would be solved by get/set stuff.
Maybe it really doesn't matter! It doesn't seem to but I wouldn't want to spends weeks only to find some stupid architecture mistake is stuffing me.


Schragnasher(Posted 2008) [#6]
lol i feel your pain and im in the same position. i hate thinking i might be making an architecture mistake. But iv seen this used quite a bit. setting up functions to do things you already can. such as creating objects, you could use object.create() but instead CreateObject() that returns the new object is used to make it more readable and easier to understand.