I'm designing a game engine in C++, and I ran into a problem with my messaging system.
ResultData" system is very appealing to me, because I only have to create a
ResultData object, call the send message method (calling functions in chain while request is not fulfilled), and then use the
For example, there is a
GameObjectResultData object, which will store game object pointers which fulfill a criteria. This can be used to get one object, two objects, etc.
I have a
GameObjectRequestData, which has the following members:
int requestedNum: the number of game objects to be found, so the request stops broadcasting after the right number is found.
GameObjectResultData: the resulting data objects pointer, in which the result will be stored.
I have to store the criteria in the request, without creating a lot of different
RequestData classes. For examples,
RequestData object arrives at a
GameObject object, how do I check the criteria?
My current idea is to use a
SearchCriteria abstract class and a
SearchCriteriaType enum, which will both be stored in the
RequestData. For example, I could use a
NameEqualsCriteria class and a
NAME_EQUALS_CRITERIA enum. In this case, when the
RequestData arrives at
GameObject, I check the enum value, and dynamically cast the
SearchCriteria object to the corresponding class.
if(type == NAME_EQUALS_CRITERIA) dynamic_cast<NameEqualsCriteria>(SearchCriteria); // then, check criteria.
I think it should work, but I am not so experienced, so I am not sure. Is this a good practice?
I think there is an overhead on creating the new enum and class types. How do I set up the
RequestData.SearchCriteria object, in the simplest form?
If I use the name criteria, I have to set a string; if I use the range criteria, I have to set a point and a range. My current solution is to pass the enum to the
RequestData constructor, which will create a corresponding
SearchCriteria object. Then, back where I called the constructor, I dynamically cast the
SearchCriteria object to the corresponding class, and call its setters.
How do I properly set criterias, when sending search requests in messaging system?