11-12-2023, 11:06 AM
Code: (Select All)
' Program to create an array of Doubles in a UDT
DIM AS LONG i
DIM AS DOUBLE v
CONST cMAXELEMENTS = 10
TYPE tARRAY
array AS _MEM
END TYPE
DIM AS tARRAY object
' initialize the array
createObject object
' set the array to random values
FOR i = 0 TO 10
v = RND * 5
setElement object, i, v
PRINT "index:"; i; "->"; v
NEXT
' retrieve vales from array
FOR i = 0 TO 10
PRINT "index:"; i; "->"; getElement(object, i)
NEXT
SUB createObject (o AS tARRAY)
' make array one larger than number of elements
o.array = _MEMNEW((cMAXELEMENTS + 1) * 8) ' 8 is the number of bytes in a double
END SUB
FUNCTION getElement# (o AS tARRAY, element AS LONG)
getElement = _MEMGET(o.array, o.array.OFFSET + (element * 8), DOUBLE)
END FUNCTION
SUB setElement (o AS tARRAY, element AS LONG, v AS DOUBLE)
_MEMPUT o.array, o.array.OFFSET + (element * 8), v AS DOUBLE
END SUB
Is this what you are looking for?
2D physics engine https://github.com/mechatronic3000/fzxNGN
Untitled Rouge-like https://github.com/mechatronic3000/Untitled-Rougelike
QB Pool https://github.com/mechatronic3000/QBPool
Untitled Rouge-like https://github.com/mechatronic3000/Untitled-Rougelike
QB Pool https://github.com/mechatronic3000/QBPool