X_WORLD2SCREEN is very slow

Previous topic - Next topic

bigsofty

Ive been trying to optimise this for a few days though but one command is causing me no end of problems.

X_WORLD2SCREEN is very slow, on my quite powerful PC(core i7 4gig quad) it grabs an terrible amount of CPU time. On my tablet (1.2ghz) it kills the frame rate to the unusable stage also.

If I remove X_WORLD2SCREEN in my game then the frame rate is great.

I ripped out a few lines to try and show the problem below.

6000 calls may seem a lot for each frame but when the computer is completely dedicated to this, without any game rendering or game loop updates, you can see how using it, even sparingly has an adverse affect on the frame rate.

I do expect this to have an impact on game loop time(its a complex calculation) but I think the amount of processing time this command is currently taking up is quite unreasonable.

Code (glbasic) Select
test1()

FUNCTION test1:
WHILE 1
LOCAL frametime=GETTIMERALL()
X_MAKE3D 1, 1200, 45
X_CAMERA  0, 0, 80, 0, 0, 0
test2()
X_MAKE2D
PRINT "FPS:"+getfps(),500,0
PRINT "Frame Time > "+(GETTIMERALL()-frametime)+"\n",500,10
SHOWSCREEN
WEND
ENDFUNCTION

FUNCTION test2:
LOCAL i%,x1=1,y1=2,z1=3,mz1
LOCAL x, y, z
FOR i=0 TO 1999
    X_WORLD2SCREEN x1,y1,z1, x1,y1,mz1
    X_WORLD2SCREEN x1,y1,z1, x1,y1,mz1
    X_WORLD2SCREEN x1,y1,z1, x1,y1,mz1
NEXT
ENDFUNCTION


FUNCTION getfps:
STATIC fps_time,fps_counter,fps,fps_temp
    fps_time = GETTIMERALL()
    fps_counter = fps_counter + 1
        IF (fps_time-fps_temp)>1000
                fps_temp = fps_time
                fps = fps_counter
                fps_counter = 0
        ENDIF
    RETURN fps
ENDFUNCTION
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

I get a FPS of around 34, and a frame time of around 30 on my PC

And nothing on my Android :)

Kitty Hello

this command has to do a lot of math. I think the current version also queries the matrix from the driver. Did you try the V11 beta? I think I changed it to system memory already.

mentalthink

Hi I have to use in my last developement, but always I found some trouble... I think this command have to ve very complex internally... (This it´s a base change?¿)

I have a very poor but functional solution:

I make a simple patch and works very fine, practically it´s the same, only if you change the resolution you have to change the parameters, and it´s better works always in the same depth in Z axis...

In my code I have this values:

This it´s the 3D Shot... make reference to 2D Shot, more down....

3d_Shot
X_MOVEMENT       -(((item.x3d)/divider_speed_Shot)+(horizontal_Move/divider_horizontal))+8.2, _
                      -((item.y)/divider_vertical)+4                                             , _
                       0

2d_Shot
//Important the speed_Shot value it´s 10
         INC item.x, speed_Shot

         DRAWSPRITE spr_Shot   + 205          , _
                  item.x               , _
                  item.y

You can see in 3D mode two plus: +8.2, and +4 for Y Axis, this only are offset for adjust the initial pos in 3D for corresponding in the 3d world

This only works for 480x320, but changing to another resolutions only it´s a (3 Rule)(Una regla de 3) I think...  :-[

My game it´s working practically fixed to 45 FPS, but I have some 1024^2 textures and 2D Mixing and 1 real time Light, when you works whit 2D and 3D, it´s too much better down the FPS and don´t leave at 60 FPS, becuase always when you don´t draw something in 3D, you can nottice some increment of speed in the game... sometimes it´s practically Null, but I think it´s something ugly for the player

The point makes drop down the FPS it´s  mixing 2D and put some 2d Image filling the complete screen (like a background), the game goes to 30 or 28 FPS... :(, it´s extrange but if you use like a background a Sphere or another simple Geometry you game runs a lot of quickly than put a 2D image like Background...


bigsofty

V11 offers me little or no improvement I am afraid.

One thing I could suggest is that this command probably could be optimised internally with staticly caching any calculationS that involve the camara matrix. Most times this command will be called, like the test demo above, when the cameras position/angle has not moved between subsequent calls. You may already be doing this of course Gernot.

Thanks Mentalthink not sure that trick would work with my program due to the rotation if the camera between frames.

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

mentalthink

Thanks Bigsofty, well I have my camera rotatin in ZAxis, and works fine, perhaps in my game can works, becuase it´s a horizontal Shotter...

Another thing , I told about 45FPS, this it´s in Mobile Devices, in PC, runs at full 60FPS, all the time, another point it´s, it has the 2dBox implemented

bigsofty

Gernot, quick question, are you using gluProject() for this or something custom?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

Something custom, but it's based on gluProject.