I didnt mean you should'nt use loops.
Consider this example:
//Main game loop
while( oDBP.LoopGDK() )
{
//Do stuff here
for(int i = 1; i < amountOfGameObjects; i++)
{
if( oDB3D.ObjectInScreen(i) == 0)
{
oDB3D.HideObject(i);
}
else
{
oDB3D.ShowObject(i);
}
}
oDBCore.Sync();
}
In DBP, this piece of code would boost your games FPS by ALOT. But in DGDK.Net, these extra for loops makes your game ALOT slower.
What im trying to say is, watch out with for and foreach loops INSIDE your main game loop.
From that other thread i linked:
C# code
oDBDisplay.SetDisplayMode(1024, 768, 32);
oDBDisplay.MaximiseWindow();
oDBCore.SyncOn();
oDBCore.SyncRate(0);
oDBCamera.AutoCamOff();
oDBInput.HideMouse();
oDBCamera.ColorBackdrop(0);
float amp = 20.0f;
int rows = 100;
int columns = 100;
float elasticity = 0.0002f;
float a = 0;
float b = 0;
oDBCamera.PositionCamera(rows / 2, rows/2, columns / 2.0f);
oDBCamera.YRotateCamera(-90);
oDBCamera.PointCamera(rows / 2, 0, columns / 2);
oDBBitmap.CreateBitmap(1, 10, 10);
oDB2D.BoxB(0, 0, 10, 10, oDB2D.RGBC(0, 255, 0), oDB2D.RGBC(255, 0, 0), oDB2D.RGBC(0, 0, 255), oDB2D.RGBC(0, 0, 0));
oDBImage.GetImage(1, 0, 0, 10, 10);
oDBBitmap.DeleteBitmap(1);
int num = rows * columns;
int[,] obnum = new int[rows + 1, columns + 1];
float[] v = new float[rows * columns];
oDBMatrix.MakeMatrix(1, rows, columns, rows, columns);
int ob = 0;
for (int x = 1; x <= rows; x++)
{
for (int z = 1; z <= columns; z++)
{
obnum[x, z] = ob;
ob++;
}
}
oDBMatrix.PrepareMatrixTexture(1, 1, rows, columns);
int tile = 1;
for (int x = rows - 1; x >= 0; x--)
{
for (int z = 0; z <= columns - 1; z++)
{
oDBMatrix.SetMatrixTile(1, z, x, tile);
tile++;
}
}
int starttime = oDBCore.Timer();
int time = 0;
int oldtime = 0;
float dtperloop = 0;
float totaldt = 0;
float dt = 0;
int loopnumber = 0;
float y = 0;
float theta = 0;
float distxp1 = 0;
float distxm1 = 0;
float distzp1 = 0;
float distzm1 = 0;
float vectorsumx = 0;
float vectorsumz = 0;
float vectorsum = 0;
int syncnumber = 0;
int calc = 0;
while (oDBP.LoopGDK)
{
oDBText.Text(0, 0, oDBDisplay.ScreenFPS().ToString());
time = oDBCore.Timer() - starttime;
dtperloop = time - oldtime;
totaldt = totaldt + dtperloop;
oldtime = time;
loopnumber++;
if (loopnumber == 10)
{
loopnumber = 0;
dt = totaldt / 10.0f;
totaldt = 0;
}
oDBCamera.RollCameraRight(0.005f * dt);
y = amp * oDBCore.SIN(theta);
theta = theta + 0.01f * dt;
oDBMatrix.SetMatrixHeight(1, (int)a, (int)b, y);
for (int x = 1 + 1; x <= rows - 1; x++)
{
for (int z = 1 + 1; z <= columns - 1; z++)
{
if (x < rows)
{
distxp1 = oDBMatrix.GetMatrixHeight(1, x + 1, z) - oDBMatrix.GetMatrixHeight(1, x, z);
}
if (x > 1)
{
distxm1 = oDBMatrix.GetMatrixHeight(1, x - 1, z) - oDBMatrix.GetMatrixHeight(1, x, z);
}
if (z < columns)
{
distzp1 = oDBMatrix.GetMatrixHeight(1, x, z + 1) - oDBMatrix.GetMatrixHeight(1, x, z);
}
if (z > 1)
{
distzm1 = oDBMatrix.GetMatrixHeight(1, x, z - 1) - oDBMatrix.GetMatrixHeight(1, x, z);
}
vectorsumx = (distxp1 + distxm1);
vectorsumz = (distzp1 + distzm1);
vectorsum = vectorsumx + vectorsumz;
a = vectorsum * elasticity;
v[obnum[x, z]] = v[obnum[x, z]] + a * dt;
if (v[obnum[x, z]] > 0.01f) v[obnum[x, z]] = 0.01f;
if (v[obnum[x, z]] < -0.01f) v[obnum[x, z]] = -0.01f;
oDBMatrix.SetMatrixHeight(1, x, z, oDBMatrix.GetMatrixHeight(1, x, z) + v[obnum[x, z]] * dt);
if (oDBMatrix.GetMatrixHeight(1, x, z) > amp) oDBMatrix.SetMatrixHeight(1, x, z, amp);
if (oDBMatrix.GetMatrixHeight(1, x, z) < -amp) oDBMatrix.SetMatrixHeight(1, x, z, -amp);
}
}
oDBMatrix.UpdateMatrix(1);
syncnumber++;
if (syncnumber > 20)
{
if (calc == 0)
{
calc = oDBCore.Timer() - starttime;
oDBDisplay.SetWindowTitle(calc.ToString());
}
oDBCore.Sync();
}
}
DBP Code
set display mode 1024,768,32
sync on
sync rate 0
autocam off
hide mouse
color backdrop 0
amp#=20.0
rows=100
columns=100
elasticity#=0.0002
a=0
b=0
position camera rows/2,50,columns/2
yrotate camera -90
point camera rows/2,0,columns/2
create bitmap 1,10,10
box 0,0,10,10,rgb(0,255,0),rgb(255,0,0),rgb(0,0,255),rgb(255,255,0)
get image 1,0,0,10,10
delete bitmap 1
num=rows*columns
dim obnum(rows+1,columns+1)
dim v#(rows,columns)
make matrix 1,rows,columns,rows,columns
for x=1 to rows
for z=1 to columns
obnum(x,z)=ob
ob=ob+1
next z
next x
prepare matrix texture 1,1,rows,columns
tile=1
for x=rows-1 to 0 step -1
for z=0 to columns-1
set matrix tile 1,z,x,tile
inc tile
next z
next x
starttime=timer()
do
text 0,0,str$(screen fps())
time=timer()-starttime
dtperloop#=time-oldtime
inc totaldt#,dtperloop#
oldtime=time
inc loopnumber
if loopnumber=10
loopnumber=0
dt#=totaldt#/10.0
totaldt#=0
endif
roll camera right 0.005*dt#
y#=amp#*sin(theta#)
theta#=theta#+0.01*dt#
set matrix height 1,a,b,y#
for x=1+1 to rows-1
for z=1+1 to columns-1
if x<rows
distxp1#=get matrix height(1,x+1,z)-get matrix height (1,x,z)
endif
if x>1
distxm1#=get matrix height(1,x-1,z)-get matrix height (1,x,z)
endif
if z<columns
distzp1#=get matrix height(1,x,z+1)-get matrix height (1,x,z)
endif
if z>1
distzm1#=get matrix height(1,x,z-1)-get matrix height (1,x,z)
endif
vectorsumx#=(distxp1#+distxm1#)
vectorsumz#=(distzp1#+distzm1#)
vectorsum#=vectorsumx#+vectorsumz#
a#=vectorsum#*elasticity#
v#(obnum(x,z))=v#(obnum(x,z))+a#*dt#
if v#(obnum(x,z))>0.01 then v#(obnum(x,z))=0.01
if v#(obnum(x,z))<-0.01 then v#(obnum(x,z))=-0.01
set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z))*dt#
if get matrix height(1,x,z)>amp# then set matrix height 1,x,z,amp#
if get matrix height(1,x,z)<-amp# then set matrix height 1,x,z,-amp#
next z
next x
update matrix 1
inc syncnumber
if syncnumber>20 then sync
loop
If you change the rows and columns variable in the C# code you thereby change the amount of for-loops in the main loop, the FPS slows down or speeds up by alot.
However, changing them in DBP has little to no effect.
Using Dark GDK.NET