Mind Map Sharing

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

    • Mind Map Sharing

      Hey Guys,

      I have been using XMind (Thanks Rez) to help plot out system connections and different processes, normally I would write it on my white board however when I want to start something new, I have to erase it and lose it forever.

      I thought it would be cool to share these things with everyone else on this forum and maybe encourage other people to create their own and share them for various systems and methods of doing things. Maybe I could keep this post as an index with links to different posts to keep it organized and easy to find.

      Mind Maps
      Actor System - mholley519
      Actor System using Lua Function Environments
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 2 times, last by mholley519 ().

    • Actor System using Lua Function Environments

      Here is my second idea for my actor system, this time instead of having to have a Lua Actor Factory, I would expose my Actor class to Lua with functions for retrieving components, I would also expose each C++ component to Lua.

      Then If I need to grab an actor in Lua I would simply call the Lua version of LoadActor or CreateActor which would return the pointer to the C++ instance.

      I hope LuaPlus is not too different from LuaBind as in LuaBind if you exposed a class to Lua it allowed you to simply pass a C++ pointer into a variable and it would automatically allow the calling of any exposed functions.

      I hope to use the Lua Function Environments to seperate scripts into objects, allowing me to have multiple Update functions in different files. Has anyone had experience in using Function Environments?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • So I got the function environments working, and man do they work good. I wasn't sure if anyone would be interested in seeing a actor script system more like Unity, if someone wants me to post how I got this set up let me know.

      Basically instead of connecting a C++ Actor to a Lua Actor, you attach script components which are created as 'instances' of that script, the scripts have predefined function names like Update, Init and ShutDown which are searched for in the script instance. You can add multiple scripts to actors all with there own Update function and they will all be properly called for the specific instance.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Nice. :) I looked up Lua Function environments (I had never seen them before) and it looks pretty slick. I'm interested to see how it goes when you have tons of objects and non-object scripts.

      -Rez
    • I have been having issues with something, the C++ GetComponent function uses templates for good reason, to automatically cast the component to its type. I am trying to implement a GetComponent in Lua. Assume that I have my Actor class exposed, as well as each component class exposed to Lua.

      I want to make a GetComponent class without having to make specific functions for each component in the actor class, ie.

      TransformComponent* GetTransformComponent();

      which returns the compont ptr in its correct form. However I wish to have something like this

      Source Code

      1. function Update(deltaT)
      2. local transformComponent = this:GetComponent("TransformComponent")
      3. end;


      However as far as I know there is no way to pass a C++ typename from a string, which the default get component requires. And without templates there is no way to automatically cast the component to the correct type. So I would have to make a

      ActorComponent* GetComponent(const char* szName);

      However this brings me back to a downcasted component pointer, which doesn't seem to work with the metatable that is specific for a TransformComponent.

      How should I be going about this?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Yup, the downcast pointer is tricky! I think you're on the right track, but I would handle it a bit differently.

      Looking through your diagram, it looks like you your flow is to create an empty actor, then load it from XML. This load seems to be on the Lua side, which I assume calls into C++ functions to create the C++ components. Is that correct?

      What you want to do is pass in the Lua actor you created to the various component creation functions. When the component is created in C++, it should add itself to the actor.

      The idea is that you're never doing this:

      Source Code

      1. function Update(deltaT)
      2. local transformComponent = this:GetComponent("TransformComponent");
      3. end

      You're doing this:

      Source Code

      1. function Update(deltaT)
      2. local transformComponent = this.TransformComponent;
      3. end

      transformComponent will be nil if it doesn't exist. If it does, it'll point to a table with the appropriate C++ __object set.

      There are two benefits here. First, accessing a component doesn't require you to jump over the Lua -> C++ boundary, which is very expensive. You want to minimize the number of times you have to jump that boundary.

      The second is that you can create components entirely in Lua. If you have a gameplay component that has nothing at all to do with the game engine, it should live in Lua. For example, a monster will likely have hitpoints, which can be done with a HitPoints component. Anything that's damageable would have this component, but C++ doesn't need to know or care about it. The best part is that from the script's point of view, there is no difference between a C++ and a Lua component except how it's loaded. That means you can iterate on a potentially expensive component in Lua, then move the whole thing to C++ if necessary without changing any other code.

      This system is exactly what we did on Rat Race and it worked really well. I believe MySims did something similar as well (I didn't work on it, but the Sims Medieval team came from those projects so I learned bits and pieces).

      -Rez
    • I'm not exactly sure what you meant, but maybe I'll explain exactly how my actors are created.

      First off in my script exports I create meta-tables for my actor, and every component that I need to use in Lua.

      Then at actor creation (In C++), I simply create a new lua object that my c++ actor holds onto, this object takes on the actor metatable, and passes the actor pointer into the __object field

      every component on creation will grab there owners lua object, and add a new table to it which takes on the meta table for that component, and passes the component pointer into the __object field.

      Finally in a script component the function environment is created, and I then SetObject on the environment table a 'this' variable with my actors lua object as the value.

      in my lua file I then am able to do this

      Source Code

      1. function Update(deltaT)
      2. this.TransformComponent:Rotate(0.5, 0.0, 0.0);
      3. end;
      4. function Init()
      5. _G.print("Actor" .. this:GetID() .. " Initializing");
      6. end;


      It works great now, thanks for the help Rez, accessing the components in this way works great. And like you said with the proper error checking if the component is not created it will be nil.

      I think out of anything to do with modern game programming, the one thing that had me so stuck was actor behaviours, not how to draw objects, or recieve input etc, but how to make object A do something different then object B and also interact with one another.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • RE: Mind Map Sharing

      Yeah, the devil is in the details. Every game struggles with this and there a lot of great resources on it.

      -Rez
    • rezination wrote:



      There are two benefits here. First, accessing a component doesn't require you to jump over the Lua -> C++ boundary, which is very expensive. You want to minimize the number of times you have to jump that boundary.

      The second is that you can create components entirely in Lua. If you have a gameplay component that has nothing at all to do with the game engine, it should live in Lua. For example, a monster will likely have hitpoints, which can be done with a HitPoints component. Anything that's damageable would have this component, but C++ doesn't need to know or care about it. The best part is that from the script's point of view, there is no difference between a C++ and a Lua component except how it's loaded. That means you can iterate on a potentially expensive component in Lua, then move the whole thing to C++ if necessary without changing any other code.

      This system is exactly what we did on Rat Race and it worked really well. I believe MySims did something similar as well (I didn't work on it, but the Sims Medieval team came from those projects so I learned bits and pieces).

      -Rez


      That opended a whole new world for me, until now i always tried to include actor properties directly inside a c++ component, indeed i came here for a more generic solution instead of a per actor type solution (like a map of string) and whether it was a good idea (i know that in the book you mention about ultima doing this so i don't argue this itself). However now you dropped this idea that changed everything. My question remain about the persistence of these properties.


      Thanks in advance