Better method than smart-pointers for dealing with circular dependency?

Started by
10 comments, last by _the_phantom_ 10 years, 8 months ago

Hmm...

The staggered loading part makes sense in the case of actual resources. I didn't think that was what you meant, though, since you were talking about plugging things into the world. Do you mean like loading configuration data for the object from files?

I don't get why this pattern is associated with improved performance, though. A constructor is just a function. It would have to do the same work as the other functions are doing. Do you mean that performance is improved by the staggered loading?

In my mind I'm thinking that an entity would be created, then plugged in. Any resources (graphics, audio, etc) that it needs should be owned remotely (by a cache or something) so that they can be shared between instances. The entity may trigger loads from the cache, but the cache could be designed to provide a placeholder 'blank' resource until the loading is complete. I get that the loading could be moved to the plug-in/activate stage rather than the construction, which would spread the work out.

I guess what I don't get is why you can't do something like:


class Thing {
  Thing() {
    //set default values here
    commonCtor();
  }
 
  Thing(SerialThing*) {
    //deserialize here? (or deserialize externally and pass in a pimpl?)
    commonCtor();
  }
 
  void commonCtor() {
    //construction (maybe notify the cache of impending resource requests so that it can get a head start if it's not busy?)
  }
 
  void OnPlacedInWorld() {
    //activate the object
  }
};


I'm thinking that it would make more sense if I saw it in action. I just don't get why the actual ctor would be left blank and then have a number of initialization functions. Possibly this relates to that fact that I've not yet worked with the Entity-Component pattern.

I don't fully understand what you mean by point 7. Does GameObject() have a meaningful constructor or is it left blank? From your earlier post I had the impression that the ctor was doing nothing, and either the OnCreate() function or some kind of external(?) deserialization was being used instead. So what you're saying is that the base ctor is doing some kind of common work, and then OnCreate() or alternative is doing the local construction?

It isn't a case of non-construction. The game object is fully constructed after the constructor.

?

Yeah, I'd need to see what kind of overall framework this is in before I'd understand the reasoning behind it.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Advertisement
What he means is that object is 'valid' for a given definition of 'valid'.

For example we have two types in our engine; 'surfaces' and 'shader resource views'. The latter requires the former to work yet the latter can be created before the former.

The 'construction' and initialisation just allows the surfaces to say 'hey, I require this resource, let me know when it exists' and then it is informed when it comes into existence so it can hook itself up.

This 'ready' message can happen 1 or more frames after the view is constructed.
(This is a centralised dispatch which allows you to limit the number of 'ready' messages sent per frame and also capture all the new ones to dispatch later instead of throwing them all out at once.)

This topic is closed to new replies.

Advertisement