Torque Script Array Implemented
by Hardi Bhatt · 05/15/2007 (11:42 am) · 1 comments
Download Code File
These Integer and Float array classes are implemented within the Torque Game Engine SDK to utilize array usage and make it possible for the game engine to implement its "array style" processes to run faster and more efficiently.
This means:
-array support is made possible within TGE
This code allows you to declare arrays dimensions from 1D - 3D as either an Integer or a float and set and get its size and value without having to used wrapper classes like ScriptObjects or declaring a series of variables and put a strain on the symbol table for larger projects. This convention can be easily extended to other types and higher dimensions if the need arises.
INSTALLATION:
1.) Copy and paste the 12 files in the ../Torque/SDK/engine/sim directory
2.) Rebuild the Compile
I have tested it with Torque Game Engine SDK 1.4 but it should work for all versions of TGE
USAGE:
%array = new IntArray();
%array.setSize( %t );
for (%i = 0; %i < %t; %i++)
{
%array.setValue(%i, 2*%i);
%x = %array.getValue( %t-%i-1 );
}
or for 3D
%array = new Int3DArray();
%array.setSize( %t , %t, %t);
for (%i = 0; %i < %t; %i++)
{
for(%j = 0; %j < %t; %j++)
{
for(%k = 0; %k < %t; %k++)
{
%array.setValue(%i, %j, %k, (2*(%i*%j*%k)));
%x = %array.getValue( %t-%i-1, %t-%j-1, %t-%k-1 );
}
}
}
COMMANDS:
void setSize (int newSize)
int getSize ()
void setValue (int newValue)
int getValue ()
The convention is different for greater dimensions where the getSize() method will convey the use of asking for the its specific dimension like getXSize() ot getYSize...
I have timed the implementation on all the classes and the results were
1D integer array size of 125,000
Elapsed time
1.5s for the Torque Script symbol table version
6.3s for the Torque Script script object version
1.6s for the array implemented version
1D float array size of 125,000
Elapsed time
1.5s for the Torque Script symbol table version
6.1s for the Torque Script script object version
1.6s for the array implemented version
2D integer array size of 500x500 equivalent to 250,000 array size of a 1D array
Elapsed time
4.5s for the Torque Script symbol table version
42.5s for the Torque Script script object version
4.7s for the array implemented version
2D float array size of 500x500 equivalent to 250,000 array size of a 1D array
Elapsed time
4.4s for the Torque Script symbol table version
51.9s for the Torque Script script object version
5.4s for the array implemented version
3D integer array size of 50x50x50 equivalent to 125,000 array size of a 1D array
Elapsed time
2.9s for the Torque Script symbol table version
11.0s for the Torque Script script object version
2.9s for the array implemented version
3D float array size of 50x50x50 equivalent to 125,000 array size of a 1D array
Elapsed time
2.9s for the Torque Script symbol table version
9.8s for the Torque Script script object version
3.3s for the array implemented version
Any questions about usage please post them here
These Integer and Float array classes are implemented within the Torque Game Engine SDK to utilize array usage and make it possible for the game engine to implement its "array style" processes to run faster and more efficiently.
This means:
-array support is made possible within TGE
This code allows you to declare arrays dimensions from 1D - 3D as either an Integer or a float and set and get its size and value without having to used wrapper classes like ScriptObjects or declaring a series of variables and put a strain on the symbol table for larger projects. This convention can be easily extended to other types and higher dimensions if the need arises.
INSTALLATION:
1.) Copy and paste the 12 files in the ../Torque/SDK/engine/sim directory
2.) Rebuild the Compile
I have tested it with Torque Game Engine SDK 1.4 but it should work for all versions of TGE
USAGE:
%array = new IntArray();
%array.setSize( %t );
for (%i = 0; %i < %t; %i++)
{
%array.setValue(%i, 2*%i);
%x = %array.getValue( %t-%i-1 );
}
or for 3D
%array = new Int3DArray();
%array.setSize( %t , %t, %t);
for (%i = 0; %i < %t; %i++)
{
for(%j = 0; %j < %t; %j++)
{
for(%k = 0; %k < %t; %k++)
{
%array.setValue(%i, %j, %k, (2*(%i*%j*%k)));
%x = %array.getValue( %t-%i-1, %t-%j-1, %t-%k-1 );
}
}
}
COMMANDS:
void setSize (int newSize)
int getSize ()
void setValue (int newValue)
int getValue ()
The convention is different for greater dimensions where the getSize() method will convey the use of asking for the its specific dimension like getXSize() ot getYSize...
I have timed the implementation on all the classes and the results were
1D integer array size of 125,000
Elapsed time
1.5s for the Torque Script symbol table version
6.3s for the Torque Script script object version
1.6s for the array implemented version
1D float array size of 125,000
Elapsed time
1.5s for the Torque Script symbol table version
6.1s for the Torque Script script object version
1.6s for the array implemented version
2D integer array size of 500x500 equivalent to 250,000 array size of a 1D array
Elapsed time
4.5s for the Torque Script symbol table version
42.5s for the Torque Script script object version
4.7s for the array implemented version
2D float array size of 500x500 equivalent to 250,000 array size of a 1D array
Elapsed time
4.4s for the Torque Script symbol table version
51.9s for the Torque Script script object version
5.4s for the array implemented version
3D integer array size of 50x50x50 equivalent to 125,000 array size of a 1D array
Elapsed time
2.9s for the Torque Script symbol table version
11.0s for the Torque Script script object version
2.9s for the array implemented version
3D float array size of 50x50x50 equivalent to 125,000 array size of a 1D array
Elapsed time
2.9s for the Torque Script symbol table version
9.8s for the Torque Script script object version
3.3s for the array implemented version
Any questions about usage please post them here

Torque Owner Dumbledore