good starting point ?

Monkey Forums/Monkey Beginners/good starting point ?

GC-Martijn(Posted 2015) [#1]
Maybe i'm going to try the new mojo2, and want to make a good start.
Using some examples, and this deltatimer (did some tests in a other topic)
https://github.com/Regal-Internet-Brothers/deltatime/blob/master/LICENSE

My target is: desktop,ios,android

What I have is this, what do you think ?
Are there some faults already inside this setup ?

file1.monkey


classes/game.monkey


classes/editor.monkey


classes/deltatime.monkey


configfile.monkey


As you can see I pass the canvas/deltatime ref into the other 2 classes.
the game is build inside the game.monkey class.
the editor is a live editor if needed.


ImmutableOctet(SKNG)(Posted 2015) [#2]
Looks good to me. I personally like following the argument-only approach for shared/modular data, though. So, for update and render routines, I'd pass the 'DeltaTime' object per-method, and I'd pass a 'DrawList' to the render routines, as a full 'Canvas' is usually unneeded. Since you're going for a separated framework approach with 'Game', there's good reason to pass a full 'Canvas' in this case. Personally, I'd go with keeping things housed in Mojo, unless I had a reason to separate it (There are quite a few, actually). Though honestly, I'm also the guy who goes full object-oriented and builds advanced CRTP hierarchies to reuse every bit of my code, so I'm not always the best example.


GC-Martijn(Posted 2015) [#3]
yea, I don't know if passing or storing a reference is a huge difference in speed.

Method A:Void(canvas:Canvas)
 ' do something with canvas
End Method

Field canvas:Canvas ' need to set this once
Method B:Void()
 ' do something with canvas
End Method


Both use the same reference, to only thing is that by B I store the reference inside a Field.
I think it only will cost some little bits.
Using method A, you will send the reference.
Maybe at the end there is no speed difference at all ?

I don't know what the best option is.

Inside the Game class, i'm going to use the argument-only approach sometimes for the other drawable objects and stuff.


Pharmhaus(Posted 2015) [#4]
Putting all the information needed into the constructor seems fine to me.
If you go with an constructor approach and you try to keep the number of globals low everything should be fine.
The only thing you should think of in my opinion is the 'how hard is future change' if you can refactor everything because the code is clean enough you don't have a problem.