creg.h

creg.h

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
zenzike
Posts: 77
Joined: 12 Apr 2008, 13:19

creg.h

Post by zenzike »

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?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Re: creg.h

Post by jcnossen »

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).
zenzike
Posts: 77
Joined: 12 Apr 2008, 13:19

Re: creg.h

Post by zenzike »

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?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Re: creg.h

Post by jcnossen »

Cool. Does that mean you expect classes in an AI to be serializable?
The AI has to implement its own way to read and write its state, see the IGlobalAI interface
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?
Mostly yeah, although some classes also supply PostLoad or Serialize methods to handle the special cases.
zenzike
Posts: 77
Joined: 12 Apr 2008, 13:19

Re: creg.h

Post by zenzike »

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?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Re: creg.h

Post by jcnossen »

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.
Also, I have a wrapper class that uses multiple inheritence, again in /ExternalAI, what's the protocol for dealing with creg here?
creg doesn't support multiple inheritance, but as said you don't need it anyway.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: creg.h

Post by Kloot »

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
zenzike
Posts: 77
Joined: 12 Apr 2008, 13:19

Re: creg.h

Post by zenzike »

Thanks for letting me know. Yes, I'll rewrite the wrapper if need be :)
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: creg.h

Post by Tobi »

Inheriting CObject is only needed if you want to register to be notified on deaths of dependent object.
Post Reply

Return to “Engine”