I've written a small macro to add to ATC which I believe will prove to be quite popular.
It basically allows you to call class methods on objects which, instead of being created using new(), are implicitly defined as local structs in procedures, explicitly defined as (possibly initiated) structs in global data, or implicitly defined as named struct fields of another class.

This works because when ATC preprocesses a class definition, it defines a struct whose name is "the classname" and which is composed of all the "data fields" from the class definition (ie, the classdef, sans functions).

Knowing that a struct has been defined whose name matches our classname, we can simply define structs wherever we like whose type is our classname, then use my new hcall macro to call class methods on structs by their names.

example:

SomeProc PROC pVelocity:ptr VECTOR, pDirection
local vDirection:VECTOR
local fSpeed_REAL8
;Split Velocity vector into Speed and Direction components
hcall vDirection, VECTOR, Set, pVelocity
hcall vDirection, VECTOR, Magnitude
fstp fSpeed
hcall vDirection, VECTOR, Normalize
;we now have unit direction vector and speed scalar
...
...
blah


Anyhow, here's the goody :)


hcall macro ObjectName:REQ, ObjectType:REQ, FuncName:REQ, var1:VARARG
push ecx
lea ecx, ObjectName
icall ecx, ObjectType, FuncName, var1
pop ecx
endm


As you can see, all it does is preload the objectpointer for icall.
This is just fine for simple "utility classes", and will prove handy for data-oriented object manipulation, etc, but comes with one caveat.

Since we won't need to use new() or delete() apon these object instances, their Constructor and Destructor will not be called.
That means if the Class needs to allocate or free anything, you're going to have to perform your own housekeeping.

For classes which don't need any other resources, it's not an issue.
I've implemented classes :VECTOR, RAY and PLANE using this methodology so far, and found the ability to call classmethods on locals to be a wonderful addition to ATC.
Posted on 2005-03-06 21:42:27 by Homer