In-game debugging system

Monkey Forums/Monkey Programming/In-game debugging system

V. Lehtinen(Posted 2014) [#1]
Codes updated 7/18/2014 !!


Hello peeps!

I was tempted to start coding an advanced debugging system while reading this thread. This system uses Monkey's Reflection module as it's core.

So far done:
 - Objects on the screen can be selected in various ways (clicking on it, area selection or pressing SHIFT+A)

 - Selected objects can be dragged and dropped

 - Selecting one object will show fields that are set up to the watch list. Does not show when multiple objects selected

 - Custom mouse can be added to the system as a singleton class with globals, or as an object-instance with fields

 - Custom camera can be added to the system same way as custom mouse

 - Dev-console with working inputs:
        - "get_obj" command that allows user to get fields, globals, constants, methods, functions and super-class from selected object
        - "get_class" command is same as above, but for classes
        - "set_obj" command that allows user to set values of fields for selected object
        - "call_obj" command that allows user to call selected object's methods


Still to be done:
 - Dev-console with various input commands and output features.
    - Input commands will allow user to manipulate selected object's properties and call it's methods
with inputs
        - "put" command that allows user to place an object behind a "variable name" for later access
        - "new" command that allows user to create new instances of classes (can be used with "put" command)
        - "watch" command that allows user to add fields for debug watch on-the-run
        - ....and more once I figure them out.
    - Output features, such as coloring and overriding default Print()

 - System that allows users to add GUI elements, such as sliders for property manipulations

 - Various information displays, such as FPS


Images:

Single object selected:


Multiple objects selected:


Getting globals and fields for selected object:


Changing the size of an object:


Called object's method with input:


Testing array outputting from method:


Adding variables to watch list:


Codes:

@ https://github.com/misthema/In-game-debugging-tool

Demo:
Try it!

TAB-key toggles the system on/off.


I'll keep you updated... ;)


Yay, I made a Github repository without conflicts \o/

Sincerely
~V. Lehtinen


V. Lehtinen(Posted 2014) [#2]
Forums are so fucked up.... Editing post results double-post of the one that was edited... *SIGH!!* -.-


V. Lehtinen(Posted 2014) [#3]
(Once again I saw first post doubled... Wth is wrong with the forums??)


V. Lehtinen(Posted 2014) [#4]
*snip* Sorry. Nothing valuable here. :<


V. Lehtinen(Posted 2014) [#5]
Okay, never mind that problem. I GOT STUFF WORKING HERE!! It is now possible to select objects on the screen and see their field values in watch list!!!

Images from the progress so far:
*snip* Moved to first post.

So yeah.. Implementing this system is fairly simple! I'll keep you guys updated and if you have ideas or optimizations please tell me! :)


Paul - Taiphoz(Posted 2014) [#6]
this might be cool as part of diddy.


V. Lehtinen(Posted 2014) [#7]
@Paul:
Not a bad idea at all, but the idea is to be able to implement this system anywhere, with any engine you want. So far it works and is really easy.
But of course, if Diddy wants, he can add this easily to his system.

I've also added a possibility to add your engine's custom mouse and camera coordinates (whether it's a singleton with globals or an object-instance with fields) to the system, so the system can use them within its features... :)

Still some work to do... I'm missing the whole console system... xD And about that - is it wrong if I implement an already existing GUI system to this? Is just that... Every user might have their own GUIs and such, so feels kinda dumb to implement another. It would make things easier though, since I'm planning on a slider system for user-defined values and properties etc. But since this is only used for debugging of course, so it wouldn't matter that much ...right?


V. Lehtinen(Posted 2014) [#8]
Picture update: Dev-console and first commands!!


("get" command fetches the information from the selected object, or from the first object in the list, if multiple selected)
And for some reason, "Field color:Color" is printed out as "Void"... o_O

EDIT:
Okay, it's fixed now.


programmer(Posted 2014) [#9]
Looks awesome!


V. Lehtinen(Posted 2014) [#10]
Picture update: Dev-console progressing!
*image moved to first post*

And for some reason, it didn't get me information for "Game" class (extends from App), even though it's in the same file with "TestObject" and "CustomMouseClass". Any ideas?

Also, once I get "set" command done I'll put a HTML5 example somewhere so you guys can play around. :P

And I really need a better parser... *sigh*


programmer(Posted 2014) [#11]
And for some reason, it didn't get me information for "Game" class (extends from App), even though it's in the same file with "TestObject" and "CustomMouseClass". Any ideas?

You could try to print all reflected classes names. Maybe this will help.



V. Lehtinen(Posted 2014) [#12]
@programmer:
That would definitely work, but reflecting everything could be reeeeally heavy if you have a lot of modules... :S Hmmh. Of course I'm going to try that, right now! :P

EDIT: Oh, I understood you wrong, haha... Okay yes, thank you for that. It will help :)

Also want to mention, that commands went through some remodeling... I'm such a bad parser-coder ;D

But here's a peek:



ziggy(Posted 2014) [#13]
The problem is related to this which makes Reflection not an option sometimes (which is something a bit sad, as it's a great module). http://www.monkey-x.com/Community/posts.php?topic=8140


V. Lehtinen(Posted 2014) [#14]
@ziggy:
Yeah I noticed that while playing around... And yes, it is sad. BUT, on the other hand, it's the user that will be setting the reflection filter, of course. And I think it might not be the whole engine that is needed when debugging around - personally I'd think that this would mostly be used for the objects on the screen, rather than changing lots of stuff engine-wise on the run. But yeah, it's for the user to decide what they will be reflecting when using this tool (so they might reflect what they need, when they need it).


V. Lehtinen(Posted 2014) [#15]
Picture update: Dev-console progressing, set and call commands working!

And would like to know where I could upload the HTML5 game for testing? Not sure if I have any web hosts.. :S
*image moved to first post*


@Ziggy:
Spaces have no effect on FontMachine's GetTxtWidth() and that makes me sad.. :'(

EDIT:
Invoke() for method does not return anything...?

EDIT2:
Never mind that, my mistake... ^^


V. Lehtinen(Posted 2014) [#16]
Updated! New images moved to first post and codes are updated.. :)

Currently working in tool:
- Get selected object's fields, globals, constants, methods, functions and super class! (get_obj)
- Get class's fields, globals, constants, methods, functions and super class! (get_class)
- Set selected object's field values! (set_obj)
- Call selected object's method with input and get an output! (call_obj)


V. Lehtinen(Posted 2014) [#17]
Finally, it's all in Github ....success without conflicts \o/


V. Lehtinen(Posted 2014) [#18]
Picture update: Methods can now be called with array inputs!
Methods with array outputs also working!


In image below, it didn't find the method because my input array had the wrong element type... ;)


Method TestStringArray:String(arrStr:String[])
        Local rtn:String = "Elements in array: "
        
        If arrStr.Length() > 0 Then
            rtn += arrStr.Length()
        Else
            rtn += "0 :("
        End If
        
        DevConsole.Log("DEBUG::Elements:",[128, 64, 64])
        For Local i:= 0 Until arrStr.Length()
            DevConsole.Log("  - " + arrStr[i])
        End For
        
        Return "~q" + rtn + "~q"
    End Method



Fred(Posted 2014) [#19]
@ziggy: this gives me an idea for Jungle IDE: as it knows all symbols and funcs names, it could generate a Monkey file with some debug functions like class fields dump, without using reflection.
the dump values function could just draw fields in a tree way
func DumpFields( t, x, y )
if Image(t)
DrawText "width:Int = " + t.width, x, y
height...
elseif MyClass( t )
...
endif
end
An advanced version of that could allow to fold or unfold all fields dump like arrays with a light interface all included in the debug.monkey generated on demand with Jungle.


Samah(Posted 2014) [#20]
@V. Lehtinen: Not a bad idea at all, but the idea is to be able to implement this system anywhere, with any engine you want.

Diddy is not an "engine", nor will it ever be one. It's just a bunch of utility functions and classes.
If you don't want to use the DiddyApp screen framework, don't. Adding "lehtinendevconsole.monkey" to src/diddy would make zero difference to having it as standalone.

@V. Lehtinen: But of course, if Diddy wants, he can add this easily to his system.

I would be more likely to write my own system that (optionally) makes use of some of Diddy's other features. In fact, I already have a very simple dev console module in my local repository that I wrote a few months ago. I've put it on hold while I work on the storyboard editor.

Your module does look nice, and if you're interested in adding it to Diddy we might be able to look at adding you as a contributor. I'm interested to see where you take it.


V. Lehtinen(Posted 2014) [#21]
Diddy is not an "engine", nor will it ever be one. It's just a bunch of utility functions and classes.
If you don't want to use the DiddyApp screen framework, don't. Adding "lehtinendevconsole.monkey" to src/diddy would make zero difference to having it as standalone.

Ooh, right, I forgot. :D And yes, you are right.

I would be more likely to write my own system that (optionally) makes use of some of Diddy's other features. In fact, I already have a very simple dev console module in my local repository that I wrote a few months ago. I've put it on hold while I work on the storyboard editor.

Actually, talking about using features; reflecting parts of Diddy (or the whole utility) would make it possible to call anything out of Diddy's classes etc. My system has no restrictions on what it can do, except that private properties aren't accessible of course. Anything else is available from reflected class files etc.
But what features are you talking about?

Your module does look nice, and if you're interested in adding it to Diddy we might be able to look at adding you as a contributor. I'm interested to see where you take it.

Thank you! I'm not yet sure if I want it bundled, though, since the only thing you need to do for this to work is to import single file. After importing the file, all you do is set the reflection filter and you're all done, ready to go and do stuff.

EDIT:
Also the whole system will be re-written, once I get the functionality I want. At the moment the code is ridiculously UGLY, but it does work! So far it's just been a "playground" for me to test all the stuff I want into it.


V. Lehtinen(Posted 2014) [#22]
Picture update: Fields and Globals can now be set with array values!

Try it out!
TAB-key toggles the system.

Picture is from HTML5 build, so the FPS is much lower... FontMachine's or SetColor's fault?



Samah(Posted 2014) [#23]
@V. Lehtinen: ...FontMachine's or SetColor's fault?

Without even looking at your code, I can unequivocally say SetColor is the problem.


ziggy(Posted 2014) [#24]
Yes, image tinting on HTML5 is VERY slow and that's what happens when you tint FontMachine fonts


V. Lehtinen(Posted 2014) [#25]
Awwhh damn... Maybe I could generate an image from the log in HTML5.. Just because I want to keep the colors :-)


ziggy(Posted 2014) [#26]
Depending on the amount of colors, you could load several fonts.


V. Lehtinen(Posted 2014) [#27]
Exactly that! That's much better idea. :) Thank you!