Upload
euming
View
261
Download
0
Tags:
Embed Size (px)
DESCRIPTION
These are some more advanced concepts in the dynamic polymorphic object design paradigm
Citation preview
MEngine
Advanced Concepts
List Objects
• Make a CLinkList into a CObject
• Now lists can be manipulated like CObjects!
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.
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)
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
Camera Display List
HUD Display List
E F GH
A
A = Shell_dragonWidget
C
C = Red Dragon Icon
HUD element example continued
Camera Display List
GComplex MenuDisplay List
C
E
D
B
F
J M Z
A
H
ComplexSubelementMini-DisplayList
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
CObject
Functor ListF1
Functors are added to each individual CObject
F2
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
Getting a Functor
CObj
CObj Functor List
F1 F2CFunctor *pFunc = CObj->FindFunctor(“F2”);ORCFunctor *pFunc = CObj->FindFunctor(cobj_functor_type);
F2
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
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.
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.
Camera Display List
GComplex MenuDisplay List
C
E
J M Z
A
H
ComplexSubelementMini-DisplayList
Apply Functor: “Render” to the Camera Display List
Low Level Functor Operation
• pCamera->ExecuteFunctor(“Render”, NULL, pCamera->GetDisplayList());
• Or: pCamera-> ForEachArgExecuteFunctor(cobj_reserved_functor_render, NULL, pCamera->GetDisplayList());
Animated Frame List
Transform Frame List
Camera Display List
Apply Functors “Animate”, “Transform”, and “Render”
A
C
D
E
F
G
H
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!”