MEngine Advanced

353 views

Published on

These are some more advanced concepts in the dynamic polymorphic object design paradigm

  • Be the first to comment

  • Be the first to like this

MEngine Advanced

  1. 1. MEngine Advanced Concepts
  2. 2. List Objects <ul><li>Make a CLinkList into a CObject </li></ul><ul><li>Now lists can be manipulated like CObjects! </li></ul>
  3. 3. Oh God no. Why? <ul><li>A list of lists is useful </li></ul><ul><li>Passing a list as an argument to a function is useful </li></ul><ul><li>List of lists allows a tree to have branches as well as leaves </li></ul><ul><li>Don’t need to add lists together when we have a list of lists. Just traverse the elements of the list of lists. </li></ul>
  4. 4. Examples of List Objects <ul><li>Small display list for a HUD element </li></ul><ul><li>List of triangles in an Octree leaf </li></ul><ul><li>Arguments to a functor (later advanced concept) </li></ul><ul><li>Camera display lists </li></ul><ul><li>List of global lists available </li></ul><ul><li>List of menu lists (future architecture) </li></ul>
  5. 5. HUD element example HUD Display List HUD Display List A = Shell_dragonWidget A B = Green Dragon Icon B A = Shell_dragonWidget A C C = Red Dragon Icon
  6. 6. HUD Display List HUD element example continued Camera Display List E F G H A A = Shell_dragonWidget C C = Red Dragon Icon
  7. 7. Camera Display List G Complex Menu Display List C E D B F J M Z A H Complex Subelement Mini-Display List
  8. 8. Functors <ul><li>Functions can be made into CObjects </li></ul><ul><li>Now functions can be manipulated like CObjects! </li></ul><ul><li>Procedural programming? So last millenium! </li></ul><ul><li>C++ Object-Oriented? No, it’s STATICALLY Object-Oriented </li></ul><ul><li>That’s why they use ‘static’ 8 million times </li></ul>
  9. 9. CObject Functors are added to each individual CObject Functor List F1 F2
  10. 10. Functor Calling Conventions <ul><li>Other arguments passed depends upon how the Functor is constructed and what arguments it needs </li></ul>CObj Automatic Argument List <ul><li>Each Functor has a default argument list </li></ul>CObj Functor List Fn <ul><li>Each Cobject has its own list of Functors </li></ul><ul><li>The first argument in the Argument List is the Cobject itself. This allows the global Functor to access the ‘this’ pointer. </li></ul>
  11. 11. Getting a Functor CObj CObj Functor List F1 F2 CFunctor *pFunc = CObj->FindFunctor(“F2”); OR CFunctor *pFunc = CObj->FindFunctor(cobj_functor_type); F2
  12. 12. Execute the Functor <ul><li>Functors operate in 2 ways </li></ul><ul><ul><li>On a list attached to the functor itself (parameter list) </li></ul></ul><ul><ul><li>On a list provided to the functor </li></ul></ul>
  13. 13. Why does Functor execute have 2 different modes of operation? <ul><li>A Functor with an arglist performs a binary operation (ie. C = A+B, “Attach”) </li></ul><ul><li>A Functor without an arglist performs a unary operation using its parameter list as its arguments (ie. A = -A, “Render”, “Instantiate”, “Materialize”, “Animate”) </li></ul><ul><li>The Functor’s operation is performed on each CObject in the list. </li></ul>
  14. 14. Warning: NO SAFETY CHECKS <ul><li>Functor operations are very versatile. </li></ul><ul><li>You can write code to violate the argument passing conventions. </li></ul><ul><li>Please don’t! </li></ul><ul><li>If you don’t like my conventions, make new ones. But keep some sort of convention, otherwise it will get crazy. </li></ul>
  15. 15. Apply Functor: “Render” to the Camera Display List Camera Display List G Complex Menu Display List C E J M Z A H Complex Subelement Mini-Display List
  16. 16. Low Level Functor Operation <ul><li>pCamera->ExecuteFunctor(“Render”, NULL, pCamera->GetDisplayList()); </li></ul><ul><li>Or: pCamera-> ForEachArgExecuteFunctor(cobj_reserved_functor_render, NULL, pCamera->GetDisplayList()); </li></ul>
  17. 17. Apply Functors “Animate”, “Transform”, and “Render” Animated Frame List Transform Frame List Camera Display List A C D E F G H
  18. 18. I, Voltron, highly recommend Functors. You can attach or detach them from your classes to change your functionality dynamically as the situation demands. I can tell you from experience that it was a bitch getting all these different robot lion heads to interface properly in C++. But with functors, I didn’t have to care about the interface! I just say, “Left Arm fire!” or “Right Arm Detach!”

×