Visual helpers

About Monkey 2 Forums Monkey 2 Code Library Visual helpers

Tagged: ,

This topic contains 8 replies, has 5 voices, and was last updated by  Hezkore 3 months, 2 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #13850

    Ethernaut
    Participant

    I’ve been using these simple classes a lot lately, and they help me debug things more quickly.

    The first one is the “Echo” system, it basically prints out values to a screen overlay. You don’t have to worry about where each line falls, only the initial placement of the text box. You can easily extend it, check out how the “Entity” class is extended to add recursive echoing of all entities in a scene.

    Echo system

    Usage is simple. For instance, to add the current FPS do:

    Then at the end of your render loop you call:

    It’s important to call “Clear()” if you’re not drawing anything, otherwise the stacks will explode…
    Use Echo.font to set the font to your liking.

     

    The second helper is a simple Graph system, extremely helpful when debugging animation problems. It will graph any values over time, with different colors and user specified scale/range.

    Graph systemUse it by adding named values (on every frame, it won’t add a new “channel” twice if it has the same name), like this:

    And then call at the end of your render loop, just like Echo, something like:

    The “height” value is how tall the positive values of the curve will be, in pixels, and the range is the maximum visible value. Better names? Amplitude maybe?

     

    Anyway, here’s the code for Echo:

    And for Graph…

    Hope that helps.
    Cheers!

    #13853

    degac
    Participant

    Nice!
    Thanks for the source code.
    I did something like this on Bmax… but this is much ‘cleaner’ (and I like the Extension thing everytime I see it in use!)

    #13855

    Amon
    Participant

    Woah. This is very good. Very helpful, indeed.

     

    Thank you.

    #13867

    Ethernaut
    Participant

    and I like the Extension thing everytime I see it in use!

    Yeah, it’s one of my favorite M2 features! I usually find it cleaner to add a method to an existing class instead of making up a new one or a new function that takes the object as an argument. Also makes it really easy to add recursion, as you can see in the Entity example.

    #13876

    Hezkore
    Participant

    Very nice Ethernaut. 🙂
    I’d love for this to be a simple module you could just import and use everywhere, not just for Mojo3D.

    Something like this should definitely be part of Monkey2 by default.
    Each module, like Mojo3D and Mojo, could then use Echo themselves to give the user some info about entities, images or whatever.

    Btw the graph crashes at canvas.DrawCircle( cursor+leftBorder, (-values[cursor] * scale) + h/2.0, 3 ) in debug mode.
    “Deque index out of range”

    Also, if you let the graph work its way to the end, then make the window smaller, the graph continue outside of the screen.

    #13879

    Ethernaut
    Participant

    not just for Mojo3D

    If you comment out the Entity and Scene related lines it should work just fine in ‘vanilla’ Mojo.

    Btw it seems to crash at canvas.DrawCircle( cursor+leftBorder, (-values[cursor] * scale) + h/2.0, 3 ) in debug mode.

    Not crashing here! Are you in the latest dev branch?

    #13880

    Ethernaut
    Participant

    Also, if you let the graph work its way to the end, then make the window smaller, the graph continue outside of the screen

    Yeah, it needs more polish if it’s gonna be a module… I kept it basic for now just so I could keep moving.
    Volunteers? 🙂

    #13890

    cocon
    Participant

    These are tremendously important components, thanks for posting. 🙂

    Perhaps we could drop various ideas in case there is interest into making a full featured profiling framework, if it’s really useful and needed by the people who use Monkey. One such idea would be to attach some sort of console input and logging mechanism which can be useful when debugging the application at runtime. http://monkeycoder.co.nz/forums/topic/mojox-gui-components/ .

    #13898

    Hezkore
    Participant

    If you comment out the Entity and Scene related lines it should work just fine in ‘vanilla’ Mojo.

    Yeah, but I mean if it were a module it should probably stay clear of using other module specific things, like Mojo3D.

    Not crashing here! Are you in the latest dev branch?

    I sure am!
    You can fix it by doing something like:
    canvas.DrawCircle( cursor+leftBorder, (-values.Last() * scale) + h/2.0, 3 )
    So basically, use values.Last() instead of values[cursor]
    And I’d suggest setting radius to something like 2.25 instead of 3.
    3 very often seems to look like a square, where as 2.25 more consistently looks like a circle.

    Yeah, it needs more polish if it’s gonna be a module… I kept it basic for now just so I could keep moving.
    Volunteers?

    I won’t be fixing it up, I sadly have too much to do right now.
    But I really think Mark should add something like this in the future.
    Maybe even tools like “frame step” so you can jump one “frame” forward to inspect things more closely.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.