🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Straight Forward c++ RTTI

Started by
12 comments, last by LorenzoGatti 4 years, 1 month ago

karlmar said:
the reason for querying is too be able to fetch pools of components when i implement ECS

Components should not be free floating around your memory rather than stay at least in a continous array in memory so you don't never ever need to use RTTI to get component types. As I wrote above, using RTTI is incredibly slow if done for 100.000 components every frame and yes, you have to do it every raem sometimes if your game is changing components frequently and this will happen at certain points

Advertisement

Im using CRTP as it seems valid for now, all this was for a future implementation and my “pools” are contagious blocks of data but if i have a script that wants to grab a component i need to know the component type in order to grab the component. I don't have a system such that i could “hard code” the type. So you would end up doing:

MyComponentExampleHandle m_Component;
void Start()
{
	m_Component = m_World->GetComponent<MyComponentExampleHandle>(EntityID);
}

Obviously for systems you would feed in cached contagious sets of components but for scripts that doesn't make sense? at least the idea of building a System to play a fart sound on 1 item in the entire game world seems very over the top. I imagine you would have a BehaviourSystem that ticks behaviour (script) components that implement unique behaviours that interact with the data components used internally by the engine etc. So those scripts need a method to grab hold of components and Type identification seems like the solution?

So your actual problem is the architecture of a script interpreter on top of an ECS. What kind of scripts?

  • High-performance because you run them for many objects very often (e.g. BulletML)? In this case scripts are probably part of the operation of imporyant systems and there should be no need and no way to “grab” arbitrary components.
  • Sparse, general and possibly complex (e.g. for special level features like reacting to events and spawning actors)? In this case the mapping between names and classes can probably be hardcoded: you are designing a closed set of language primitives and component types with carefully selected semantics, not a generic and open-ended system in which anything could happen.
  • Invasively modifying and controlling the whole game state and the systems that update it, or limited to a restricted context like a single entity?

karlmar said:

at least the idea of building a System to play a fart sound on 1 item in the entire game world seems very over the top.

Why over the top? What do you mean by “building a system”? To play even a single fart sound in the whole game you need to implement a sound effects mixer and the related component and resource types.
It isn't the large investment it might appear to be: the difficult and performance-critical aspects of playing sound are covered by libraries, and if you can implement graphics sound is normally simpler.

karlmar said:
I imagine you would have a BehaviourSystem that ticks behaviour (script) components that implement unique behaviours that interact with the data components used internally by the engine etc.

This is probably where you forget types: the same BehaviourSystem is used for every entity, doesn't know what entity it's operating on, and expects the script to know type information.

How would you restrict the commands in a script by entity type (e.g. query the temperature of a vehicle's engine, but not of a piece of scenery)?

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement