After my internet stopped working this week-end, I decided to start working on my OOP precompiler for dbp again
You can now have methods within classes, and have arrays in classes, so all sorts of things are now possible
Here is an example header file and code file:
class Vector3
X as float
Y as float
Z as float
endclass
class Object3D
ObjNum as integer
Position()
GetPosition() as Vector3
endclass
class ArrayTest
data[] as integer
endclass
sync on
MyTest as ArrayTest
MyTest = new ArrayTest
MyTest.data = new integer[5]
MyTest.data[0] = 1
MyTest.data[1] = 2
MyTest.data[2] = 3
MyTest.data[3] = 4
MyTest.data = ResizeArray(MyTest.data,3)
print MyTest.data[0]
print MyTest.data[1]
print MyTest.data[2]
print MyTest.data[3]
print ArraySize(MyTest.data)
sync : sync
wait key
MyVector as Vector3
MyObject as Object3D
MyObject = CreateCube(10)
do
if MyVector
delete MyVector
endif
MyVector = MyObject.GetPosition()
MyVector.X = MyVector.X + 0.01
MyObject.Position(MyVector)
text 0,0,str$(MyObject.GetPosition().X)
sync
loop
function Object3D.Position(Pos as Vector3)
position object me.ObjNum,Pos.X,Pos.Y,Pos.Z
endfunction
function Object3D.GetPosition()
Pos as Vector3
Pos = new Vector3
Pos.X = object position x(me.ObjNum)
Pos.Y = object position y(me.ObjNum)
Pos.Z = object position z(me.ObjNum)
endfunction Pos
function CreateCube(size as float)
obj as Object3D
obj = new Object3D
obj.ObjNum = find free object()
make object cube obj.ObjNum,size
endfunction obj
And the code produced (I know it's unreadable, but it keeps the line numbers the same

:
sync on
MyTest as integer
MyTest = alloc zeroed(8)
poke integer MyTest+0, InitArray(5,4)
poke integer peek integer(MyTest+0)+8+(0)*4, 1
poke integer peek integer(MyTest+0)+8+(1)*4, 2
poke integer peek integer(MyTest+0)+8+(2)*4, 3
poke integer peek integer(MyTest+0)+8+(3)*4, 4
poke integer MyTest+0, ResizeArray(peek integer(MyTest+0),3)
print peek integer(peek integer(MyTest+0)+8+(0)*4)
print peek integer(peek integer(MyTest+0)+8+(1)*4)
print peek integer(peek integer(MyTest+0)+8+(2)*4)
print peek integer(peek integer(MyTest+0)+8+(3)*4)
print ArraySize(peek integer(MyTest+0))
sync : sync
wait key
MyVector as integer
MyObject as integer
MyObject = CreateCube(10)
do
if MyVector
free MyVector
endif
MyVector = object3d_getposition(MyObject)
poke float MyVector+0, peek float(MyVector+0) + 0.01
object3d_position(MyObject, MyVector)
text 0,0,str$(peek float(object3d_getposition(MyObject)+0))
sync
loop
function object3d_position(me as integer, Pos as integer)
position object peek integer(me+0),peek float(Pos+0),peek float(Pos+4),peek float(Pos+8)
endfunction
function object3d_getposition(me as integer)
Pos as integer
Pos = alloc zeroed(12)
poke float Pos+0, object position x(peek integer(me+0))
poke float Pos+4, object position y(peek integer(me+0))
poke float Pos+8, object position z(peek integer(me+0))
endfunction Pos
function CreateCube(size as float)
obj as integer
obj = alloc zeroed(4)
poke integer obj+0, find free object()
make object cube peek integer(obj+0),size
endfunction obj
function InitArray(size as integer,elementsize as integer)
array = alloc zeroed(size*elementsize+8)
poke integer array,size
poke integer array+4,elementsize
endfunction array
function ArraySize(array as integer)
size = peek integer(array)
endfunction size
function CloneArray(array as integer)
size = peek integer(array)*peek integer(array+4)+8
newarray = alloc zeroed(size)
copy memory newarray,array,size
endfunction newarray
function ResizeArray(array as integer, newsize as integer)
elementsize = peek integer(array+4)
oldbytes = peek integer(array)*elementsize
newbytes = newsize*elementsize
if newbytes < oldbytes then oldbytes = newbytes
newarray = alloc zeroed(newbytes+8)
copy memory newarray+8,array+8,oldbytes
free array
endfunction newarray
I have included a .bat file with the executable. To set what files you want to precompile, right-click on it, and select 'edit'. You will see where to write the file names.
Download the latest version
here (27 July 08)