Skip to main content
gamedev.net
🔒 Locked

Optimizing Dibits Wrapper?

Started by Lord Chiko 2 replies 900+ views
Original Post
Lord Chiko
Lord Chiko
hey all i've developed a wrapper for the dibits api function thingo and...well i feel its 2 slow i've programmed the interface in visual basic and the main code in c++ vb sends pointers to the coordinates to 500 Objects and to the screen (byte array) and the image to be drawn (byte array) it calls the api 15 times a second and that takes 1204 ms to complete 1000ms coming from c++ and 204 from vb (so virtually 6229 objects per second) the size of the object being drawn is 80 by 80 @ 24 bit am i asking to much? or can c++ do this faster? Here is my main c++ code also i've noticed getting VB to make api calls that have lots of variables in them increases the time it takes to make the call but i feel it shouldn't be this great (note when i get it finished ill be changing it into just 1 call - an array of pointers =D)
long __declspec(dllexport) CALLBACK GetNumberEX(long x,long y,char *TheScreen,long SoWidth,long SoHeight,char *TheObject,long OoWidth,long OoHeight,long *TheXPosition,long *TheYPosition,long XYS)
//LPSAFEARRAY FAR *data)
{
	long bufx;
	long bufy;
	long mx;
	long my;
	long num;
	 long index=0;
	 long mxy;


long x2=x;// = 100;//x;
long y2=y;// = 100;//y;
long x3 = x2;
long y3 = y2;
long output1;
long output2;
long maxx;
long maxy;
maxx = (x2+OoWidth)-1;
maxy = (y2+OoHeight)-1;


for (long mass=1 - 1;mass <= XYS - 1;mass++)
{
for (long tempx=x3;tempx<=maxx;tempx++)
{
for (long tempy=y3;tempy<=maxy;tempy++)
{

	x2=tempx+TheXPosition[mass];
	y2=tempy+TheYPosition[mass];


bufx = x2;
bufy = y2 +1;
mx = SoWidth;
my = bufy * SoHeight;
mxy = (SoWidth * SoHeight) * 3;
bufx = bufx * 3;
num = bufy * mx;
num = num * 3;
num = (mxy - num) + bufx;

num = num + 1;

output1 = num;


bufx = (x2-(x+TheXPosition[mass]));
bufy = (y2-(y+TheYPosition[mass]))+1;
mx = OoWidth;
my = bufy * OoHeight;
mxy = (OoWidth * OoHeight) * 3;
bufx = bufx * 3;
num = bufy * mx;
num = num * 3;
num = (mxy - num) + bufx;

num = num + 1;

output2 = num;



if (TheObject[output2-1] != 0) { TheScreen[output1-1] = TheObject[output2-1]; }
if (TheObject[output2] != 0) { TheScreen[output1] = TheObject[output2]; }
if (TheObject[output2+1] != 0) { TheScreen[output1+1] = TheObject[output2+1]; }


	 }
}
}



	return(0);

}

Ezbez
Ezbez
Quote:
Original post by Lord Chiko
it calls the api 15 times a second and that takes 1204 ms to complete


Something tells me that this is wrong...

(1000 ms in a second, so how can you use 1204 ms every second?)
Lord Chiko
Lord Chiko
Quote:
Original post by Ezbez
Quote:
Original post by Lord Chiko
it calls the api 15 times a second and that takes 1204 ms to complete


Something tells me that this is wrong...

(1000 ms in a second, so how can you use 1204 ms every second?)


well takes 1204ms to draw 15 frames each frame consists of 500 objects so

500*15 = (7500 / 1204) * 1000 = 6229 / 500 = 12.458 frames a second :)

basically what i was getting at was that this needs to run at 15 FPS (minimum) and well its taking over a second ^_^


anyway i've been working on the code i got it to render 10,000 objects and that took 1454 ms and i've managed to optimize that down to 594 ms (still need it to be faster)

heres an update on the code

long __declspec(dllexport) CALLBACK GetNumberEX(long x,long y,char *TheScreen,long SoWidth,long SoHeight,char *TheObject,long OoWidth,long OoHeight,long *TheXPosition,long *TheYPosition,long XYS)//LPSAFEARRAY FAR *data){	long bufx;	long bufy;	long mx;	long my;	long num;	 long index=0;	 long mxy;	long bufx2;	long bufy2;	long mx2;	long my2;	long num2;    long mxy2;long x2=x;// = 100;//x;long y2=y;// = 100;//y;long x3 = x2;long y3 = y2;long output1;long output2;long maxx;long maxy;long XPosBuf = 0;long YPosBuf = 0;long s=0;long e=0;maxx = (x2+OoWidth)-1;maxy = (y2+OoHeight)-1;//Precalculated stuffmx = SoWidth;mxy = (SoWidth * SoHeight) * 3;mx2 = OoWidth;mxy2 = (OoWidth * OoHeight) * 3;s=GetTickCount();for (long mass=1 - 1;mass <= XYS - 1;mass++){XPosBuf = TheXPosition[mass];YPosBuf = TheYPosition[mass];for (long tempx=x3;tempx<=maxx;tempx++){for (long tempy=y3;tempy<=maxy;tempy++){	x2=tempx+XPosBuf;	y2=tempy+YPosBuf;bufx = x2;bufy = y2 +1;//mx = SoWidth;my = bufy * SoHeight;//mxy = (SoWidth * SoHeight) * 3;bufx = bufx * 3;num = bufy * mx;num = num * 3;num = (mxy - num) + bufx;num = num + 1;output1 = num;bufx2 = (x2-(x+XPosBuf));bufy2 = (y2-(y+YPosBuf))+1;//mx2 = OoWidth;my2 = bufy2 * OoHeight;//mxy2 = (OoWidth * OoHeight) * 3;bufx2 = bufx2 * 3;num2 = bufy2 * mx2;num2 = num2 * 3;num2 = (mxy2 - num2) + bufx2;num2 = num2 + 1;output2 = num2;if (TheObject[output2-1] != 0) { TheScreen[output1-1] = TheObject[output2-1]; }if (TheObject[output2] != 0) { TheScreen[output1] = TheObject[output2]; }if (TheObject[output2+1] != 0) { TheScreen[output1+1] = TheObject[output2+1]; }	 }}}e=GetTickCount();return(e-s);	return(0);}
Lord Chiko
Lord Chiko
Sorry for the double post just wanted to keep them a bit seperate

the c++ code that takes up majority of the time is

//if (TheObject[output2-1] != 0) { TheScreen[output1-1] = TheObject[output2-1]; }//if (TheObject[output2] != 0) { TheScreen[output1] = TheObject[output2]; }//if (TheObject[output2+1] != 0) { TheScreen[output1+1] = TheObject[output2+1]; }


it could do 100,000 frames in no time when thats gone...but thats the pointer byte array from visual basic

would it be faster if i copied its contents to a c++ array manipulated it then send it back?

Update-

Ok apparently it doesn't matter who makes the array ^_^ currently it performs at

20,270 objects per second
129,728,000 Pixels per second
389,184,000 Bytes Per second

anyway to further increase this?

[Edited by - Lord Chiko on July 12, 2006 7:50:02 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.