Where's CreatePickup defined

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Where's CreatePickup defined

      I was comparing the book to the source code and was unable to find

      Source Code

      1. ActorComponent* CreateAmmoPickup()
      2. { return GCC_NEW AmmoPickup; }

      this is shown on pg. 171 of GCC4, at least not anywhere I thought it would be.

      In the process of trying I noticed that the source code is far more involved and is in some cases entirely different. For example, the ActorFactory ctor that I'm to add the above functions to the m_actorComponentCreators is done using a entirely different method. There are also some things like the ActorId is defined in a different place as a different type from the source and the book.

      It makes sense to me that they would be defined in the Pickup classes but I'm wanting to make sure I don't break the decoupling.

      So I really have three questions:
      1. Where should I be defining the creation functions for components?

      2. Is it semi pointless to try to re-write the code as I read the book considering it seems that a ton is missing from the it?

      3. Are the build scripts hidden somewhere that are talked about in the book or was that just informational?
    • RE: Where's CreatePickup defined

      Hey there!

      The book is an evolving project. What you see in the component architecture chapter is what I originally wrote, but it ended up changing quite a bit once Mike got to the editor chapter. This sort of thing is extremely common; your original implementation gets modified by someone else because they need to extend the behavior. In this case, Mike had to modify to get it working with his editor. Components needed to be identified by string to make it easier to load through XML and it required a bit of a refactor. I believe this is all explained once you get to the editor chapter.

      This is not the only example of the code being different. The text in the book is not modifiable, but the code certainly is. We've tweaked it a bunch over the years and submitted bug fixed (some caught by the people on this board) as well as done some minor refactors of existing systems.

      In the end, the architecture itself is what's important and that hasn't changed.


      1. Where should I be defining the creation functions for components?

      Using the GCC methodology, you register the component in the constructor of the factory. In my own engine, I instantiate the component directly in the CreateComponent() function. Either way, it doesn't break the architecture. The key is that only one system is actually instantiating all of these components.


      2. Is it semi pointless to try to re-write the code as I read the book considering it seems that a ton is missing from the it?

      Yes and no. I would say that it's pointless to just rewrite the code verbatim because it's definitely incomplete. The engine and game weigh in at about 38,356 lines of code so there's no way we can reprint all of it. Even if we could, I *still* wouldn't recommend doing it. Instead, I would read the chapter and try to understand the architecture that we're preaching. Then try to implement it on your own. Do that for each system. If you get stuck or want a pointer, take a look at the source code in the engine.


      3. Are the build scripts hidden somewhere that are talked about in the book or was that just informational?

      That section is just informational. You'd need a build machine to actually use them and they're are very different depending on the game.

      -Rez
    • Thanks for the speedy response Rez.

      To be clear because I'm perhaps already in the weeds...
      Using the GCC methodology, you register the component in the constructor of the factory. In my own engine, I instantiate the component directly in the CreateComponent() function. Either way, it doesn't break the architecture. The key is that only one system is actually instantiating all of these components.

      Isn't that what's already happening? The factory would need to know about all the CreateSomePickup()s; right? So, we'd do that in the factory constructor like

      Source Code

      1. m_actorComponentCreators["SomePickup"] = CreateSomePickup;

      Inside CreateComponent we grab the create function from the map and create a new pointer with that function, initialize it and return it to the actor creator like so...

      Source Code

      1. auto findIt = m_actorComponentCreators.find(name);
      2. if(findIt != m_actorComponentCreators.end())
      3. {
      4. ActorComponentCreator creator = findIt->second;
      5. pComponent.reset(creator());
      6. }
      7. else
      8. return StrongActorComponentPtr();
      9. if(pComponent)
      10. {
      11. if(!pComponent->VInit(pData))
      12. return StrongActorComponentPtr();
      13. }
      14. // will be nullptr if no component found
      15. return pComponent;
      Display All
      being that CreateComponent is called from CreateActor. Isn't that the instantiation, or am I missing your point?
      I would say that it's pointless to just rewrite the code verbatim because it's definitely incomplete. The engine and game weigh in at about 38,356 lines of code so there's no way we can reprint all of it.
      I realize that :D! I was wanting to write the systems with a few minor changes like using tinyXML2, nullptr and some other C++11 niceties. I got a little concerned when I, as you suggest, tried to check my implementations of the missing parts against the source code and couldn't find it. After further searching I've been able to find, or at least deduce, what was needed. I think as I continue on it will start to work itself out.
      Also...
      That section is just informational. You'd need a build machine to actually use them and they're are very different depending on the game.
      ;( I was afraid of that. It's fairly obvious that build scripts would vary from game to game, I was really just wanting to take a look at one. I've written some simple makefiles for very simple programs, but I've also seen some I couldn't understand and the ones I've written were for linux, not sure if that makes much of a difference. I was hopping to see how this is done using VS and the file structure you recommend. I also have no experience in repositories and was hoping to see those aspects too. It'd be nice to see an example that relates to a project I have access to as opposed to some random one. Oh well!

      I'll keep pushing forward, thanks again.