Should we hardcode MovableObject type names?

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
chilly willy
Halfling
Posts: 65
Joined: Tue Jun 02, 2020 4:11 am
x 19

Should we hardcode MovableObject type names?

Post by chilly willy »

Whenever I wanted to test the type of a MovableObject, I would compare it to the factory's public static FACTORY_TYPE_NAME, like this:

Code: Select all

if (mo->getMovableType() == Ogre::EntityFactory::FACTORY_TYPE_NAME)

I just updated to Ogre 14 and it seems that all the MovableObjectFactory classes have been moved into a new header file "OgreBuiltinMovableFactories.h" which is in the /src directory instead of the /include directory. I interpret that to mean that it is not meant to be included by users of the library. Should users of the library hard-code the type names into our code? Or is there a different header for us to include?

Also, as far as I found, that header file is only included by "OgreStableHeaders.h", (which is also in /src instead of /include). Neither of those files show up in the project generated by CMake. That seems to make it very difficult to find for anybody working on the code of OGRE itself. Is this intentional or an oversight?

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Should we hardcode MovableObject type names?

Post by paroj »

Ogre 14 is still in development, so things like that may happen. Fixed in:
https://github.com/OGRECave/ogre/pull/2811

Putting headers into src/ is a common practice for private headers i.e. things that should not be consumed by user code.

I dont use Visual Studio, so I typically dont notice if the generated project is incomplete. If you find a way to include the private headers, feel free to create a PR.

DolfHoll
Gnoblar
Posts: 3
Joined: Wed Sep 13, 2023 3:04 pm
x 1

Re: Should we hardcode MovableObject type names?

Post by DolfHoll »

You are correct in interpreting that the OgreBuiltinMovableFactories.h header file is not meant to be included by users of the library. This is because the factories are now implemented in a more modular way, and the header file is only needed by the library itself.

If you need to test the type of a MovableObject, you can use the MovableObject::getMovableType() method to get the string name of the factory that created it. You can then compare this string to the factory's FACTORY_TYPE_NAME constant.

For example:

const Ogre::String& movableType = mo->getMovableType();
if (movableType == Ogre::EntityFactory::FACTORY_TYPE_NAME)
{
// The MovableObject is an Entity.
}
The OgreStableHeaders.h header file is included by the CMake project to ensure that the user includes all of the necessary headers for the library. However, it is not meant to be included by the user directly.

The decision to move the MovableObjectFactory classes to the src directory and to not include them in the CMake project was intentional. This is because the factories are now implemented in a more modular way, and the user should not need to know about them.

I hope this answers your question. Let me know if you have any other questions.

Post Reply