I'm digging around the code, familiarising myself with its various aspects and I've come across creg.h; it seems like it's recreating a class system (amongst many other things), what exactly does this do?
I've looked around in the forums and the wiki, but there doesn't seem to be any good documentation about this - can anybody give me some pointers to the motivation/ideas behind this?
creg.h
Moderator: Moderators
Re: creg.h
It is used to register all the classes and their members, so they can be serialized (used for save/load), or dynamically modified (used by the explosion generator).
Re: creg.h
Cool. Does that mean you expect classes in an AI to be serializable?
I suppose the answer is that it depends on whether I want to be able to save/load AI states, if so, do I just place the CR constructs in my classes and let creg take care of the rest?
I suppose the answer is that it depends on whether I want to be able to save/load AI states, if so, do I just place the CR constructs in my classes and let creg take care of the rest?
Re: creg.h
The AI has to implement its own way to read and write its state, see the IGlobalAI interfaceCool. Does that mean you expect classes in an AI to be serializable?
Mostly yeah, although some classes also supply PostLoad or Serialize methods to handle the special cases.I suppose the answer is that it depends on whether I want to be able to save/load AI states, if so, do I just place the CR constructs in my classes and let creg take care of the rest?
Re: creg.h
I've nearly finished restructuring the AI interface, but for some reason the code is bombing out when I start with my test AI. I haven't yet dealt with registering my class through creg: might this be a reason?
My class is deriving CGlobalAI, which is a subclass of CObject, so I'm wondering if this is because I've not implemented all of the creg stuff yet. Might it be?
I have another class in /ExternalAI that doesn't subclass anything at the moment, and I just wanted to check that I should be subclassing CObject.
Also, I have a wrapper class that uses multiple inheritence, again in /ExternalAI, what's the protocol for dealing with creg here?
My class is deriving CGlobalAI, which is a subclass of CObject, so I'm wondering if this is because I've not implemented all of the creg stuff yet. Might it be?
I have another class in /ExternalAI that doesn't subclass anything at the moment, and I just wanted to check that I should be subclassing CObject.
Also, I have a wrapper class that uses multiple inheritence, again in /ExternalAI, what's the protocol for dealing with creg here?
Re: creg.h
You shouldn't need creg for AI interface classes, it's only needed if the class contains game state that has to be serialized. Your problem has to be something other than creg stuff.
creg doesn't support multiple inheritance, but as said you don't need it anyway.Also, I have a wrapper class that uses multiple inheritence, again in /ExternalAI, what's the protocol for dealing with creg here?
Re: creg.h
None of the creg stuff is of relevance when not loading a saved
state, your code can't crash for not registering with the system.
Looking at the macro's, multiple inheritance presents a problem
since there's only CR_BIND_DERIVED() and you can't simply insert
that macro twice (as each class only has one member registrator,
etc). No part of Spring actually uses MI so I'm not surprised it isn't
supported though*. Can't you rewrite the wrapper?
* not counting CInfoConsole and some boost::noncopyable types
e: ninja'ed
state, your code can't crash for not registering with the system.
Looking at the macro's, multiple inheritance presents a problem
since there's only CR_BIND_DERIVED() and you can't simply insert
that macro twice (as each class only has one member registrator,
etc). No part of Spring actually uses MI so I'm not surprised it isn't
supported though*. Can't you rewrite the wrapper?
* not counting CInfoConsole and some boost::noncopyable types

e: ninja'ed
Re: creg.h
Thanks for letting me know. Yes, I'll rewrite the wrapper if need be :)
Re: creg.h
Inheriting CObject is only needed if you want to register to be notified on deaths of dependent object.