Adam's Lair Forum

game development and casual madness
It is currently 2018/09/25, 15:55

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Visual Logging
PostPosted: 2014/02/16, 14:24 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2060
Location: Germany
Role: Professional
Hey everyone,

I've recently committed a new Duality version (both binary and source) that features a new logging functionality called "Visual Logging". It allows you to log spatial and visual information from anywhere in your source code, anytime, and takes care of displaying it on screen within the same frame.

If not specified otherwise, each of those visual logs lasts exactly one frame, so it can be used nicely in a fire & forget way - for example in the OnUpdate method. Here is how it works:

Code:
// Draws a point on screen at 100, 100
VisualLog.Default.DrawPoint(100, 100);

// Draws a point at world coordinate zero
VisualLog.Default.DrawPoint(0, 0, 0);

// Draws a point at object coordinate zero of GameObject "someGameObject"
VisualLog.Default.DrawPoint(0, 0, 0).AnchorAt(someGameObject);

// Draws a red point on screen at 200, 100
VisualLog.Default.DrawPoint(200, 100).WithColor(ColorRgba.Red);

// Draws a green point on screen at 300, 100 and keeps it alive for one second.
// A new one will be generated with each call, so this is obviously intended for
// specific events, rather than being called each frame.
VisualLog.Default.DrawPoint(200, 100).WithColor(ColorRgba.Green).KeepAlive(1000.0f);


Of course, there are other things to visualize except points:

Code:
VisualLog log = VisualLog.Default;
log.DrawPoint(...);
log.DrawVector(...);
log.DrawConnection(...);
log.DrawCircle(...);
log.DrawPolygon(...);
log.DrawText(...);


You can also maintain multiple logs and configure each of them individually, for example to switch certain layers on and off:

Code:
VisualLog logA = VisualLog.Get("A");
logA.VisibilityGroup = VisibilityFlag.Group2;
logA.BaseColor = ColorRgba.Green.WithAlpha(0.5f);

VisualLog logB = VisualLog.Get("B");
log.B.Visible = false;


However, you should keep in mind that logging is a debugging device. Don't use it to draw game-related stuff - especially, since the visual representation of these logs may change at any point - and don't leave it in there when you're releasing your library or game.

To make sure you're only logging in debug mode, you can wrap them in the appropriate preprocessor directive:
Code:
#if DEBUG
VisualLog logB = VisualLog.Get("B");
logB.DrawPoint(200, 100).WithColor(ColorRgba.Red);
logB.DrawPoint(200, 200).WithColor(ColorRgba.Green);
logB.DrawPoint(100, 200).WithColor(ColorRgba.Blue);
#endif


Or, for simple one-line statements, you can also use this syntactical sugar I'm experimenting with:
Code:
DualityApp.Dbg(() => VisualLog.Default.DrawPoint(200, 100).WithColor(ColorRgba.Red));


Since DualityApp.Dbg is compiled using the [Conditional("DEBUG")] attribute, it will be omitted when compiling in release mode and thus has more or less the same effect as using a preprocessor directive.

Attachment:
VisualLogStuff.png


That's basically it. I hope this will ease some of your debugging and diagnostic tasks. Especially for debugging algorithms that operate on spatial data, I expect this to be very useful. It's still new and yet needs to prove itself though, so.. let me know what you think!

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2014/02/17, 00:33 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
Oooh, I like this!
Great addition!


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/14, 09:31 
Veteran Member
Veteran Member
User avatar

Joined: 2015/01/07, 09:58
Posts: 102
Location: Sweden
Role: Hobbyist
This was not a new post, but oooh yeah! That's some great stuff right there :D


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/14, 19:18 
Veteran Member
Veteran Member
User avatar

Joined: 2015/01/07, 09:58
Posts: 102
Location: Sweden
Role: Hobbyist
Adam, is there any way to get this logging to show up in the editor? I'm using zones for triggering events and it seems like a good way to display those zones in the editor.


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/14, 20:35 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2060
Location: Germany
Role: Professional
skoggy wrote:
Adam, is there any way to get this logging to show up in the editor? I'm using zones for triggering events and it seems like a good way to display those zones in the editor.


They actually do show up in the editor, as there is no distinction for Visual Logging between editor and game. I guess you'll just need to hit "Play", so your Update methods that - I suspect - do the logging will be triggered. :D

Also, knowing that ICmpEditorUpdatable exists might prove helpful to you. Please don't use Visual Logging for anything else than logging or temporary stuff though.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/15, 20:23 
Veteran Member
Veteran Member
User avatar

Joined: 2015/01/07, 09:58
Posts: 102
Location: Sweden
Role: Hobbyist
Adam wrote:
They actually do show up in the editor, as there is no distinction for Visual Logging between editor and game. I guess you'll just need to hit "Play", so your Update methods that - I suspect - do the logging will be triggered. :D


I mean in the editor view editor. (Don't remember the actual name) And not when running, but when editing stuff? I was using some trigger areas and just wanted a quick way to make them visible when laying out a level.


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/15, 20:33 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 879
Location: Italy
Role: Hobbyist
Don't know if this is what you are interested in, but this will tell you if you are inside the editor or not (the condition will evaluate to false also when you click "play" inside the editor)

Code:
if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor &&
    DualityApp.ExecContext == DualityApp.ExecutionContext.Editor)
{
  VisualLog........
}

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/16, 12:21 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2060
Location: Germany
Role: Professional
skoggy wrote:
I mean in the editor view editor.


They will show up there while the game is running! However, my previous comment here:
Adam wrote:
Also, knowing that ICmpEditorUpdatable exists might prove helpful to you.

won't help. I looked into the code again and found out why you only ever get Visual Logging while the game is running inside the editor (any view though) and not while you're editing: Because it will create a temporary GameObject for rendering the logs - which would mean logging to interfere with actual Scene contents while editing. I figured this was a no-go and intentionally disabled it.

So, Visual Logging is only for the running game, be it in the launcher or the editor. Not available while editing. Since it could be useful, I might improve this later, but it would require some work to get this running properly without touching your Scene.

skoggy wrote:
I was using some trigger areas and just wanted a quick way to make them visible when laying out a level.


Do they happen to use RigidBody sensor shapes for detecting entering objects? If so, you could simply activate the "RigidBody Shape" Layer in the Camera View. It's the dropdown button right next to the Camera View State selector on the far left of it. :)

If that doesn't work, you can always create your own Camera View Layer, be it for debugging, level layout or something else. Just add a new class to your existing Editor plugin that derives from CamViewLayer. See here for inspiration!

I wouldn't normally recommend this for a quick solution because of the "create an Editor plugin" overhead, but since you already have an Editor plugin, this shouldn't be a big deal :)

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Visual Logging
PostPosted: 2015/01/18, 21:58 
Veteran Member
Veteran Member
User avatar

Joined: 2015/01/07, 09:58
Posts: 102
Location: Sweden
Role: Hobbyist
Adam wrote:
Do they happen to use RigidBody sensor shapes for detecting entering objects? If so, you could simply activate the "RigidBody Shape" Layer in the Camera View. It's the dropdown button right next to the Camera View State selector on the far left of it. :)


Nope :P Just some Vector2's that makes up a path.


Adam wrote:
If that doesn't work, you can always create your own Camera View Layer, be it for debugging, level layout or something else. Just add a new class to your existing Editor plugin that derives from CamViewLayer. See here for inspiration!

I wouldn't normally recommend this for a quick solution because of the "create an Editor plugin" overhead, but since you already have an Editor plugin, this shouldn't be a big deal :)


To much work for me :) (maybe laterâ„¢). I just created a renderer instead and have a flag for rendering when editing it, then I turn it off after I'm done editing it. Quick and not super awesome solution but it works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group