18
MEngine Advanced Concepts

MEngine Advanced

  • Upload
    euming

  • View
    261

  • Download
    0

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: MEngine Advanced

MEngine

Advanced Concepts

Page 2: MEngine Advanced

List Objects

• Make a CLinkList into a CObject

• Now lists can be manipulated like CObjects!

Page 3: MEngine Advanced

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

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

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

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

Camera Display List

GComplex MenuDisplay List

C

E

D

B

F

J M Z

A

H

ComplexSubelementMini-DisplayList

Page 8: MEngine Advanced

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

CObject

Functor ListF1

Functors are added to each individual CObject

F2

Page 10: MEngine Advanced

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

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

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

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

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

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

Low Level Functor Operation

• pCamera->ExecuteFunctor(“Render”, NULL, pCamera->GetDisplayList());

• Or: pCamera-> ForEachArgExecuteFunctor(cobj_reserved_functor_render, NULL, pCamera->GetDisplayList());

Page 17: MEngine Advanced

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

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!”