Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to solve massive slowdown using textured plane for an explosion?

Author
Message
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 29th Aug 2010 04:45
Hello,
I have used planes orientated to the camera's position and textured, in sequence, with an animation of an explosion. This does work, but there's a crash in frame rate from 80FPS down to around 2FPS. Has anyone got any ideas that could help?

Here's the code:

This basically just switches the object's texture to the next frame of the animation, the for-loop is so that I can have more than one explosion going off at a time.

Thanks,
Broken_Code
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 29th Aug 2010 17:42 Edited at: 29th Aug 2010 17:46
This:

is three function calls that you are calling every loop. The values returned will always be the same, so I suggest replacing them with variables that you declare before the loop.
Something like this:

That will certainly save you some time but I doubt very much it will get you the missing 78 fps.

Another thing that will save you some time is to replace the GrenadeExpObj floats with integers. You only seem to be using them as integers so it shouldn't be an issue. It will also save you all of the float to int conversions you are doing.



Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Aug 2010 17:55
Who knows if it is really a coding problem, how big are those plains? How many of them? Big, ghosted plains, especially many, are the most killer things to the FPS...

Also don't use a sequence of let's say 100 frames, each of them at 512*512... you get the idea, try to experience with this stuff to make it still look good, but only uses a megabyte or two in the memory, not the whole capacity.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2010 18:20
You could try the sprite commands especially create animated sprite.
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 29th Aug 2010 19:48 Edited at: 29th Aug 2010 20:32
"for t=1 to NumberOfGranades", looks like typo, it may not be of course but as you don't include your variable definitions can't say.
"if total_time#>GrenadeExpObj#(t,3)+0.0167", that line is the only reason I can see for using a float for the array. What are you doing there exactly? Why are you adding that odd number at the end? It is always the same so I cannot see why you are adding it at all. You could simply define grenadeExpObj# to have that number included.
I don't really see why you would use a time variable at all, just use your frame count.

Here is something I have cooked up to test speed. Runs fine on my system, 60fps smooth as silk.

This animates them at the same frame all the time but adding in a random is easy enough. Just demonstrates speed isn't an issue at least on my computer. Takes 2000+ objects to start slowing down here, and that is only by around 2 fps at that point.

http://s6.bitefight.org/c.php?uid=103081
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 1st Sep 2010 19:50
Thanks for all the replies, I've been away for a bit and didn't get a chance to check the forum, so excuse the late reply.

@Scraggle:
I only really called that array a float array because it holds 2 time related floats (now that I know about types, I'll probably change this to a custom type array). Also, good call on the camera position functions, I already have these stored in variables elsewhere in the code, I'll re-jig it use those instead, thanks.

@Quel:
There are 30 planes at 100x100 with textures 100x100 to match, the planes have transparency turned on but nothing else, is that still too big? Any smaller and it starts looking quite bad.

@GreenGandalf:
I tried it with sprites but it didn't give quite the look I was after (looked a bit too "cartooney", if you know what I mean).

@DVader:
Well spotted "NumberOfGranades" is indeed a typo, as grenades is spelt with an e not an a, but I'd already coded loads with this misspelt, so I thought I'd go back and change it at the end.
The +0.0167 is 1/60 th of a second as I wanted the explosion animation to be time based (I'm not sure how else to make sure it plays at a constant rate no matter the fps otherwise) but still play at 60fps.

I have downloaded DVader's code, I'll take a look at it later tonight (hopefully) and tell you all how it's going.

Thanks a lot for the help!
Broken_Code
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 2nd Sep 2010 02:31
Hmm, that 100*100px texture to match the 100*100 sized plain grabbed my attention a bit.

Sorry not in the speed topic, but the look of it. If you have the kind of video card, texture sizes not like for example 32*32 , 64*64 , 128*128 , 256*256 , 512*512... and so on (sorry i'm not an English man right now i can't recall that word to explain it with without listing some examples...) may cause ugly results, even at very high resolutions, so stick to those i told you above.

As for the speed, no this is not extreme at all even on an old computer. I should know, i have one.

For making events going at constant rate i guess you should calculate with the actual 'screen fps()' and not a pre-calculated number like that "+0.0167"...

FOR - NEXT's can be funny in a synced DO LOOP sequence since it can take up quite a bit of processing power if for some reason the program leaves it later then you expected. I'm trying to say that you should make sure that the variable 'NumberOfGranades' doesn't become too high at some point, so your function may runs that FOR NEXT a hundred times more than should... just an idea, did this to myself a couple of times before...
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 2nd Sep 2010 13:29
@Quel:
Thanks for the input. You think changing the textures (and planes) size to a power of 2 will help? I'm a bit sceptical but it's worth a try, I'll change the textures (and planes) to 128x128 and see if there's any difference. I thought that getting the frame rate using "screen fps()" was a resource-hungry function? I may be wrong, but if anyone else could shed some light on this I'd be grateful.

The "NumberOfGranades" variable is set to 4x the max number of players at the beginning of the game (as 4 is the number of grenades that each player can hold) and will not change throughout the game, I was just trying to make the code nice and general so that I could claim back some fps if there were less players in the game. In my "test game" there are 4 players, so this loop is run 16 times (and "GrenadeExpObj#(t,4)=1" is a flag that tells the code "this grenade is exploding", if you see what I mean). I hope this helps clarify up any un-clearness in the code.

Thanks again for the help,
Broken_Code
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 2nd Sep 2010 14:11
Alright, I finally got round to looking at DVader's code and doing a pretty much ground-up reworking of my original code and ended up with something that worked great (yay!).

However, when I compared the working code to my original code, the only notable difference was one line: "disable object zwrite GrenadeExpObj#(i,1)" which was in the creating planes/loading textures part of the code. I rem'ed it out of the original code and got an instant result, the slowdown was only 15fps.

I switched the plane and texture sizes to 64x64 too, and it turns out Quel was right, (sorry for doubting you!) there is an increase in texture quality over sizes that aren't a power of 2 and being that much smaller it claimed back another 3fps. So now the overall slowdown is 12fps when a single grenade is exploding.

When more than one grenade is exploding, however, the fps crashes to 10fps, how come it's not just twice the hit of one explosion?

Sorry about the noob error,
Broken_Code
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 2nd Sep 2010 17:20
Finally! I've got it working much better now, the slowdown of a single grenade exploding is now just 2fps and for two (or more, the slowdown doesn't seem to get any worse after a second grenade) is 10fps, which I can live with.

I've added a screenshot so you can see the final product of your help. I should say that these pictures don't really do justice to the effect and it looks pretty cool when you see it exploding. Also, don't pay any attention to the "fps" in the corner, the frame rate sucks because I'm using "get image" to get the screen shot.

Thanks for the help
Broken_Code
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 2nd Sep 2010 20:45
Hmm the theory that screen fps() would cause slowdown pretty much defeats the sense of its existence

Anyway if this may be correct in any way / amount, still you shouldn't use it all the time, just save its value into a variable at one point of the main loop, and from then use that variable.

Interesting that rem-ing out disabling zwrite solved your problem... for me actually without that command all the ghosted elements are quite useless since they are constantly erasing each other from the screen.

I'm happy i meant some use to you.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Sep 2010 20:47
Quote: "Hmm the theory that screen fps() would cause slowdown pretty much defeats the sense of its existence"

it's not the Screen FPS() command which causes slowdown, but rather displaying it on screen every loop using the native DBP text commands which are notoriously slow.

My signature is NOT a moderator plaything! Stop changing it!
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Sep 2010 23:40
Yah, anytime I put up diagnostics in text on the 3D screen, like mousex, etc. I get a really big slowdown in the 3D environment.

I believe (and feel free to correct me if I'm wrong) that the size of the plane object makes no difference in the quality of the image displayed on it. Only the image size needs to be a power-of-two. The plane need not match the size of the image. You can make it whatever size is convienent for your world. If it's a 64x64 image on a 1000x1000 plane, it won't get any better or worse than on a 1x1 plane. What you see depends on how far or near the camera is to the plane.

At least that's the way I believe it to be.

Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 2nd Sep 2010 23:59
Totally, Rich.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 4th Sep 2010 02:33
Something that would really speed things up would be instancing objects.

Instanced objects share animation, texture, and appearance data, they're just rendered multiple times in different places (i think it works like that...) So everything doesn't look synchronized, you could have like 5 different objects, and instance other planes from those five objects.

Login to post a reply

Server time is: 2026-07-23 12:10:50
Your offset time is: 2026-07-23 12:10:50