mengine advanced
DESCRIPTION
These are some more advanced concepts in the dynamic polymorphic object design paradigmTRANSCRIPT
![Page 1: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/1.jpg)
MEngine
Advanced Concepts
![Page 2: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/2.jpg)
List Objects
• Make a CLinkList into a CObject
• Now lists can be manipulated like CObjects!
![Page 3: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/3.jpg)
Oh God no. Why?
• A list of lists is useful
• Passing a list as an argument to a function is useful
• List of lists allows a tree to have branches as well as leaves
• Don’t need to add lists together when we have a list of lists. Just traverse the elements of the list of lists.
![Page 4: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/4.jpg)
Examples of List Objects
• Small display list for a HUD element
• List of triangles in an Octree leaf
• Arguments to a functor (later advanced concept)
• Camera display lists
• List of global lists available
• List of menu lists (future architecture)
![Page 5: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/5.jpg)
HUD Display List
HUD element example
HUD Display List
A = Shell_dragonWidget
A
B = Green Dragon Icon
B
A = Shell_dragonWidget
A C
C = Red Dragon Icon
![Page 6: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/6.jpg)
Camera Display List
HUD Display List
E F GH
A
A = Shell_dragonWidget
C
C = Red Dragon Icon
HUD element example continued
![Page 7: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/7.jpg)
Camera Display List
GComplex MenuDisplay List
C
E
D
B
F
J M Z
A
H
ComplexSubelementMini-DisplayList
![Page 8: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/8.jpg)
Functors
• Functions can be made into CObjects
• Now functions can be manipulated like CObjects!
• Procedural programming? So last millenium!
• C++ Object-Oriented? No, it’s STATICALLY Object-Oriented
• That’s why they use ‘static’ 8 million times
![Page 9: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/9.jpg)
CObject
Functor ListF1
Functors are added to each individual CObject
F2
![Page 10: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/10.jpg)
Functor Calling Conventions
CObj
Automatic Argument List
• Each Functor has a default argument list
CObj Functor List
Fn
• Each Cobject has its own list of Functors
• The first argument in the Argument List is the Cobject itself. This allows the global Functor to access the ‘this’ pointer.
• Other arguments passed depends upon how the Functor is constructed and what arguments it needs
![Page 11: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/11.jpg)
Getting a Functor
CObj
CObj Functor List
F1 F2CFunctor *pFunc = CObj->FindFunctor(“F2”);ORCFunctor *pFunc = CObj->FindFunctor(cobj_functor_type);
F2
![Page 12: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/12.jpg)
Execute the Functor
• Functors operate in 2 ways– On a list attached to the functor itself
(parameter list)– On a list provided to the functor
![Page 13: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/13.jpg)
Why does Functor execute have 2 different modes of operation?
• A Functor with an arglist performs a binary operation (ie. C = A+B, “Attach”)
• A Functor without an arglist performs a unary operation using its parameter list as its arguments (ie. A = -A, “Render”, “Instantiate”, “Materialize”, “Animate”)
• The Functor’s operation is performed on each CObject in the list.
![Page 14: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/14.jpg)
Warning: NO SAFETY CHECKS
• Functor operations are very versatile.
• You can write code to violate the argument passing conventions.
• Please don’t!
• If you don’t like my conventions, make new ones. But keep some sort of convention, otherwise it will get crazy.
![Page 15: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/15.jpg)
Camera Display List
GComplex MenuDisplay List
C
E
J M Z
A
H
ComplexSubelementMini-DisplayList
Apply Functor: “Render” to the Camera Display List
![Page 16: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/16.jpg)
Low Level Functor Operation
• pCamera->ExecuteFunctor(“Render”, NULL, pCamera->GetDisplayList());
• Or: pCamera-> ForEachArgExecuteFunctor(cobj_reserved_functor_render, NULL, pCamera->GetDisplayList());
![Page 17: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/17.jpg)
Animated Frame List
Transform Frame List
Camera Display List
Apply Functors “Animate”, “Transform”, and “Render”
A
C
D
E
F
G
H
![Page 18: MEngine Advanced](https://reader035.vdocument.in/reader035/viewer/2022062319/5550f415b4c905417d8b55d6/html5/thumbnails/18.jpg)
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!”