skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
9.99k stars 878 forks source link

Call for comments: debugging tools. #60

Closed skypjack closed 6 years ago

skypjack commented 6 years ago

I was wondering if some debugging tools could help the development of applications that use EnTT (or any other entity-component system in general). I've my idea based on my own experiences of what could be useful. However, feedbacks from users that used EnTT in a real world scenario would be really useful!!

If you have any suggestion, feel free to leave a comment. I cannot guarantee everything will be implemented, but I'll take in consideration each comment for sure!!

I'll close this issue at the end of the week. Thank you very much for your help.

ArnCarveris commented 6 years ago

natvis for visual studio will greatly improve debugging process, I've planned some day to do it.

vblanco20-1 commented 6 years ago

Havent really needed debugging tools for my experiments. But if there is something i think would be really useful, is a way to "query" the ECS for details about the pools, listeners, views, and general memory usage. It would be super useful if one can query the memory use of the whole ECS and the number of allocations. For something like that, some kind of "get_pool_information" function on the registry would do, maybe returning some kind of array of pools with the data for each.

dbacchet commented 6 years ago

I plus @vblanco20-1 on that. More introspection on the memory management would be useful. For example knowing how many sparse sets are allocated, size and capacity for each, and ideally info about the type of component that they are managing

skypjack commented 6 years ago

Thank you very much. I'm closing the issue in a few hours and adding these suggestions to the TODO file. Stay tuned. :-) It shouldn't be much difficult to provide the users with a tool for introspection on internal pools. Good idea.

samaursa commented 1 year ago

Was there any progress on this?

natvis debugging of an Entity to see the components that compose it and peek inside the components would be a huge step forward. In my framework on top of entt, I provided this functionality manually (and it's slow) but having native support in entt for natvis would eliminate one of the biggest downsides of using entt (and ECS in general). It will be much easier to adopt by people new to ecs/entt.

Flecs like debugger would be a great addition as well although I would prioritize it lower than full natvis support. Flecs debugger is browser based which is a dealbreaker unfortunately.

ArnCarveris commented 1 year ago

@samaursa why unfortunately?

samaursa commented 1 year ago

@ArnCarveris we can do a discussion about it on entt gitter (I want to avoid derailing this issue's discussion)

skypjack commented 1 year ago

@samaursa Summer time, sorry for the lag. 🙂 A web-based debugger is definitely a no-go for me, so don't expect it. On the other hand, I've a half-baked in-game imgui debugger in a project of mine that I could make a little more generic and put into the repo for other devs. As for natvis, everything I can support out of the box is there already. The entity viewer is trickier though. We have it in a 🤔 project that uses EnTT but it requires an intermediate class that stores both an identifier and a pointer to a registry. Something like the handle class or even simpler actually. Do you have other suggestions or a better knowledge of natvis?

samaursa commented 1 year ago

@skypjack I did something similar where there is another class that stores the identifier and all the pointers to the components. This was done to simplify the natvis.

I am curious on how you were able to peer into the registry with natvis with an identifier such that you were able to get a list of all the components of the entity and display them in the watch window.

skypjack commented 1 year ago

It shows a list of entities with their components but it cannot show the component itself because it's a plain void * when you plot or look into the storage classes. So, what you get is more like:

* entity 10/7
  * struct foo
  * struct bar
* entity 13/2
  * struct bar
  * struct quux

You have to inspect the storage if you also want the component data. Otherwise, the imgui panel uses EnTT meta to drop all the data automatically and have the same list above with the components info too.

ArnCarveris commented 1 year ago

Or just write visual studio extension: https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2022#BKMK_CustomVisualizer

skypjack commented 1 year ago

Yeah, no, that's a pain 😅 and an in-game tool is much better anyway, so I prefer to maintain the latter. 🙂

samaursa commented 1 year ago

@skypjack regarding natvis experience, I have enough to get low to medium complexity natvis files up and running. Because natvis does not have any way to alias (see my question on SO here: https://stackoverflow.com/q/75633070/368599), the script can become quite difficult to manage.

Regardless, in my case type-erased pointers to components were stored (entt storage policy was taken into account) in a dense std::vector which were in turn stored in a sparse std::vector (entity ID was the index into the sparse vector), making it possible for the debugger (at least with VS) to be able to resolve the underlying component and allow peeking into the component. Of course, this ultimately created a much slower version of what entt is, but that was okay since it was very useful for debugging.

skypjack commented 1 year ago

Oh, another thing we do is using views for the same purpose. @samaursa Roughly speaking, plotting the whole registry is mostly useless in 90% of cases or more. On the other hand, you can have the list of entities and their components (with data) at once with a natvis snippet for a view. We use a debug-only natvis helper class for the purpose because natvis doesn't work well with tuples but that's just a trampoline object used to iterate an array of sparse sets that we know how to cast to the right storage type. Performance wise, it doesn't sum up on the view. This one (and the trampoline class) could enter EnTT probably. I think a full representation of a view is what a dev needs in the vast majority of cases anyway. I hardly ever need to inspect the entire registry and you can still do it one storage at a time if you need to, even if it's more cumbersome.

samaursa commented 1 year ago

@skypjack hmm, how would a view show me all the components/tags an entity currently has? But if that's what the trampoline class will do i.e. to let one inspect all the components/tag on an entity, that will solve the entt debugging woes with the debugger!

skypjack commented 1 year ago

how would a view show me all the components/tags an entity currently has?

The ones in the view ofc, not all of them if that's what you mean. Sorry for the misunderstanding.

samaursa commented 1 year ago

No worries. Sorry from me too as I am having trouble understanding without code/diagrams.

If I want to debug all the components I have, would the view then have to done such that it has all of the components? It will have to be a different type of view, which I guess is what you meant by the trampoline class?

skypjack commented 1 year ago

If you want to debug all components 🤔 (and sorry for the lag during this month but it's a mix of vacation and free time spent to enjoy the Summer with my son) 🤔 I guess in that case a trampoline class for a registry would work better actually. I can try to implement it or a quick example as a start point but I think I won't manage to do that this week because I'm leaving in a few days for a vacation without my PC. I'm more than willing to help with this though. If you can wait, feel free to open an issue (or I'll forget about thit 😅) and i'll try to pack something as soon as I'm back. 👍

samaursa commented 1 year ago

and sorry for the lag during this month but it's a mix of vacation and free time spent to enjoy the Summer with my son

no problem!

If you want to debug all components

To clarify, just in case: I would like to debug all components (and tags) on a particular Entity

Sounds good. I'll open up a new issue.