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 / VERY weird problem with fps

Author
Message
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 20:04
ok so i have this program ( 2D freelancer in WIP ) that works fine, but sometimes when i kill more than 5 enemies at the same time the fps unexplainably drops to 30 flat.

In more detail this is what happens.

I have Vsync on so the fps i 60 at normal
then i blow up 20 enemies resulting in 20 explosions @ 100 filled circles each. this gradually drops the fps to about 40 and then back to 60 as the explosions die out... But sometimes the fps drops to a flat 30 AFTER the explosions have stopped, and stays there for about 4 sec and then it goes back to 60... any explanations?

i Use Vsync have sync on, sync rate 0
Fulldesktop @ 1680,1050,32 hide mouse

i use matr1x plugins, Advanced 2d

help?
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Oct 2011 20:46
Any chance of sharing some code? It'll be a bit hard without it...

Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 17th Oct 2011 20:52
im willing to bet its in the code that handles the explosions after they die out. Check for any for/next loops (especially nested ones) or if you are unloading/re-loading redundant media after the "death" of each explosion.

thatd be my guess without seeing any code

Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 17th Oct 2011 21:01
also not sure if you are using the ink command but calling it more than a few times per frame causes noticeable FPS drop along with set object frame and a few others. (sorry I dont recall the full list ATM)

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 21:15 Edited at: 17th Oct 2011 21:16


the explosion code

ai(i).exist is set to -150 when an enemy dies

the ai(i).ex... variables are defined when enmy dies

i use advanced 2d for 2d so no ink commands
thre shouldnt be any extra loops and as said the drop happens AFTER the explosion
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Oct 2011 21:27 Edited at: 17th Oct 2011 21:35
You have an awful lot of floating point math going on. If you could reduce this by setting up your positions and sizes before calling a loop to draw your objects would speed things up.

How big is ai() also? Just within that portion, if your calling it lots of times the mass amount of floating point math could slow it down.

Cast some of the variables to integers before using them if not using float math.

EDIT: Also if you are resizing array whilst handling these explosions then DBP is likely to be doing a random garbage collection. The only real way around this is to increase your array size but never decrease it until a definite pause is going to happen and keep your check to a simple integer check before skipping to the next element.

EDIT2: I forgot to add, 20 x 100 filled circles will take some time to draw too, may be better off pasting images instead.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 17th Oct 2011 21:52
Yeah the FP math would be my guess. Also RANDOMIZE might be one of those commands I referred to earlier but im not sure.

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 22:00 Edited at: 17th Oct 2011 22:05
its not the math im sure, and the problem happens only sometimes and it doesnt happen when im drawing anything... ai(i) is at most 100 large the program takes 46 Mt of memory so its not that... i draw 2600 large circles everyframe for my background and that doesnt bother it at all

i tested its not randomize either

thanks for helping me

EDIT :

okay i have been able to Cause the lag.. if i rotate the ship very much while there are explosion, it ALWAYS lags like that otherwise it only happens sometimes
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 22:10
! ! ! ! F I X E D ! ! ! !



the problem was fulldesktop

changing that to fullscreen fixed the problem...
should i post this in bug reports?
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 17th Oct 2011 22:16
Correct me if I am wrong but I believe FULLDESKTOP is not a native DBP command meaning the bug is probably within your 2D plugin (therefore not a DBP bug)

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 22:17 Edited at: 17th Oct 2011 22:18
its not a command no its a setting in the program settings window next to resolution, name etc. In the IDE
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 17th Oct 2011 22:27
ahh silly me of course. not sure if its a bug per se but might be worth a mention

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 17th Oct 2011 22:53 Edited at: 17th Oct 2011 22:55
I have seen FPS inexplicably drop due to 2D commands, and using the "text" command. So I don't use them unless I need to. Better to use sprites if you can.

[EDIT]
Sorry didn't realize you were using a plugin, maybe it doesn't have the same limiations.


A 3D marble platformer using Newton physics.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Oct 2011 23:11
Quote: "DBP is likely to be doing a random garbage collection"

DBPro memory isn't garbage-collected. Variables are instances, not references, and simply go out of scope taking their contents with them.

Calling RANDOMIZE at all in a program is wasted time (although it is fast) and will generally make your program less random.

The exception to that is when you want to repeat a set of random numbers - that's basically all the command is useful for any more.

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 17th Oct 2011 23:24
that is exaclty what i want to do
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Oct 2011 00:13
Quote: "Calling RANDOMIZE at all in a program is wasted time (although it is fast) and will generally make your program less random.

The exception to that is when you want to repeat a set of random numbers - that's basically all the command is useful for any more."

I'm sure you're right IanM but I use random numbers all the time in my games and do actually get quite random results... I would say it's still got it's uses.

Is there a better way to make 'random' variables? I hope so

I know the results can be repeated using the same seed but if you start off with "randomize timer()" I find the results pretty un-predictable.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Oct 2011 00:32
Compile and run:


You'll get a different number every time - randomize isn't needed.

Compile and run:


You'll get 101 matches *almost* every time.

Now those are the two extremes - genuinely random numbers every time without RANDOMIZE, and repeated random numbers every time with RANDOMIZE. Obviously it's possible to avoid the repeat if you are very careful, but you can't make the numbers more random with RANDOMIZE, only less so.

As I said above, if you want to repeat a set of random numbers then RANDOMIZE is fine, but if you want random numbers that don't repeat stay away from it.

Believe it or not, I have a plug-in full of different types of random number generators so you can generate whole sets of independent random numbers, repeating sequences or not.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Oct 2011 10:36
Quote: "Believe it or not, I have a plug-in full of different types of random number generators so you can generate whole sets of independent random numbers, repeating sequences or not."

Why am I not surprised!

Is there anything your plugins don't do?

I didn't realise "randomize" was so repetative... I'll stay away in future! Thanks yet again IanM!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2011 13:15
Quote: "I didn't realise "randomize" was so repetative"


It isn't. It simply sets the seed value to whatever you specify. If you use



you are merely setting the seed to the value given by timer(). So if you do that several times before timer() has had a chance to change then you are simply resetting the seed to the same value. Which I guess is what IanM's code is doing.

That command is one of the most confusingly named in DBPro. Most sensible languages would have a command like



which makes the purpose clearer.

The wording of the Help file merely adds to the confusion in my opinion:

Quote: "Description

If the random number generator is not reseeded the RND() command can return the same sequence of random numbers. To change the sequence of random number every time the program is run, place a randomize statement with an integer number at the beginning of the program and change the value with each run."
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Oct 2011 13:21
That does seem to say the opposite of what IanM said, which is what confused me... I've always used randomize because when I read that I thought it would be the same sequence of 'random' numbers otherwise.
"If the random number generator is not reseeded the RND() command can return the same sequence of random numbers." is what I read... if I'd read the second part more carefully I may have understood the first part better

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2011 13:28
I had exactly the same problem when I first used the randomize command many moons ago.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Oct 2011 22:29
Quote: "Which I guess is what IanM's code is doing."

Yep, and it's likely to happen if you dot RANDOMIZE commands around at random (if you'll excuse the pun).

Using RANDOMIZE basically sets the seed value to a value that it will become sometime in the future, meaning that you've cut a chunk of random numbers out of the cycle (potentially a very large chunk too) - it is a cycle, because if you call RND enough times, you'll start repeating your initial sequence of numbers.

RND uses a 32 bit seed value, so there are potentially 4+ billion combinations before repeats of sequences. However, RND isn't perfect, so depending on your start seed, it may be possible to have only a small range of random numbers before repeating.

Quote: "The wording of the Help file merely adds to the confusion in my opinion"

That's one of those areas where the help didn't keep up with the code.

Many people were complaining about RND always giving the same sequence of random numbers at program startup, despite the fact that they already had the RANDOMIZE command to fix it, so Lee simply added a call to that function with the timer value at program startup now.

IMO, he should have left it alone (pointing people to the RANDOMIZE command instead), as there are advantages to having a known sequence of random numbers. Many games in the past have used the idea of a seed value to generate levels. They basically use a simple RNG to carry out the generation, knowing that they'll get the same numbers out every time.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 18th Oct 2011 22:56
IanM your randomize code snippet is exact match because of the crappy low-resolution timer() function, so you are seeding with the same value each time. The same wouldn't happen when you use the hitimer() function in your utilities (and enough time passes)?

I didn't know Lee put a randomize timer() in startup code. That is interesting (and a little weird).


A 3D marble platformer using Newton physics.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Oct 2011 23:27 Edited at: 18th Oct 2011 23:44
Quote: "The same wouldn't happen when you use the hitimer() function in your utilities (and enough time passes)?"

Didn't you read the bit I wrote about losing a large chunk of the range of random numbers? It doesn't matter HOW you set the seed, just the fact that you DO set the seed.

My TIMER() example just makes one problem obvious, and people have posted code with that same problem in the past - they add RANDOMIZE to 'make it more random', without realising they are doing exactly the opposite.

[EDIT]
Correction - I can see in the code that the seeding at startup may actually be a side-effect of some of the protection that Lee included in the core plug-in for paid-for third-party plug-ins.

Nevertheless, it's still there and happens at startup whether you are using those third-party plug-ins or not.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Oct 2011 13:39
Quote: "Didn't you read the bit I wrote about losing a large chunk of the range of random numbers? It doesn't matter HOW you set the seed, just the fact that you DO set the seed."


Yes I did (more than twice ) - and I don't really understand the point you are making. Why are you losing numbers?

I'm assuming that the RND() function simply cycles through a long sequence of values behind the scenes and that the RANDOMIZE function simply sets the starting point for that cycle. I've also assumed that those "behind the scenes" values are then processed in some way to get the final values returned to the user's program.

Perhaps those two functions work rather differently from that naive understanding?

I hadn't realised that DBPro now automatically randomizes the sequence on startup - but then I usually use RANDOMIZE to fix the sequence anyway. Thanks for the warning.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Oct 2011 20:42
Let's use a simplified version of your 'naive' view (which isn't really naive), and imagine that you had a table of just 100 random numbers to select from, with the seed being a simple index into that table (from 0 to 99), advancing 1 place every time you grab a number, and resetting to 0 when it gets to the end of the table.

When your program starts, the seed is at zero. Grab a number, now it's at 1. You can grab a further 99 before you get to the end of the table, but as soon as you grab another 1 number you start to repeat the sequence. The periodicity of the random numbers is 100 (ie, they'll repeat every 100 reads).

Now you start setting the seed value. In the extreme case, imagine you've set it back to what it was when you read the last number - the next read will get the same number again. In this extreme case, you've reduced the periodicity to 1.

Less extreme: You choose a seed that jumps the seed forward 20 places. Now you can read 80 values before the numbers start repeating. You've reduced the periodicity to 80.

Another example: You choose a seed that jumps the seed backwards 20 places. Now you can read 20 values before the numbers start repeating. You've reduced the periodicity to 20.

Note that the effect you have whenever you set the seed to any value other than its current value is always to reduce the periodicity, making the numbers you read start repeating earlier than they would if you'd left the seed alone. There's no case where you can increase the periodicity.

Although the random number system used by DBPro does not use an actual table of numbers (it's a calculation), it does conceptually use the same system with a periodicity of 4 billion-ish.

You could set the seed and reduce the periodicity to 4 billion-ish less a few, or you could reduce it to 10. The kicker is that there's no way for you to know, because unlike using a simple index to a table, the seed value is actually a by-product of the previous random number you grabbed.

If you leave the seed alone, you know you aren't reducing the number of random numbers you can use before you start to repeat the sequence. If you change it, you know you are reducing the number, but not how badly.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Oct 2011 13:56 Edited at: 20th Oct 2011 13:57
I think you misunderstand me - or I misunderstood what you meant by

Quote: "Using RANDOMIZE basically sets the seed value to a value that it will become sometime in the future, meaning that you've cut a chunk of random numbers out of the cycle (potentially a very large chunk too) - it is a cycle, because if you call RND enough times, you'll start repeating your initial sequence of numbers."


and

Quote: "I wrote about losing a large chunk of the range of random numbers? It doesn't matter HOW you set the seed, just the fact that you DO set the seed"


I think your last post matches my understanding. It wasn't clear to me that in your earlier posts you were talking about repeated use of the randomize command in the same program using the same value (which would make sense in some situations such as the beginning of a loop where you wanted the same sequence of "random" events to be repeated). Certainly continual resetting the seed to some unpredictable variable value would probably be pointless if not actually counter-productive.

If you use it just once at the start of the program is it not the case that you simply cycle through the same sequence but starting at a different position - i.e. no numbers are lost (admittedly you'd have to run it a long time to see them all )?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Oct 2011 15:12
Yes, that's right. Of course, as DBPro already does that for you, you don't need to call it at all, unless you rely on those repeated numbers (such as using the seed to randomly generate an identical level on repeated runs of your game).

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Oct 2011 15:23
I use pseudo random number generators for a lot of my coding (and over the years) as they are very handy for the same set of numbers every time you need them. ie. Every level number will be the seed value and everything else is generated from the next random numbers, which are the same each time its generated.

It is only when I need something truly random then I'll use the clock or timer to seed the random number generator.

There's tons of different methods of generating random numbers and almost 99% of them use a seed value anyway so for truly random results just set the seed to the clock.

Quite a few of the old 8-bit and 16-bit games use procedurally generated content which is using a seed value to generate the same content. And I've been experimenting with quite a lot lately, textures, terrains and noted down a few others which I will eventually get around to.

I can understand that two loops running one after another as in one of the examples above will give the same results if using the Timer() function as it might not have ticked over by the time the next seed is set. Maybe use the PerfTimer() would be better in that case.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Oct 2011 16:02
Read my explanations again, and see why doing this ...
Quote: "It is only when I need something truly random then I'll use the clock or timer to seed the random number generator."

... may not be such a good idea.

What I'd suggest instead is that you use different RNGs for different purposes - that's why my plug-ins include one dedicated to RNGs so that you can have 1000's of them if you need to. In addition, their periodicity is much higher than the DBPro standard random numbers.

As an example, use one RNG seeded from TIMER() and use it just purely for a general source of random numbers. If you need to have a repeated range of random numbers starting from a known seed in addition to that, create a new RNG and seed that, and leave the first RNG totally alone so you don't affect its periodicity.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Oct 2011 17:15
In cases like that you could just as easy use two random number generators, one for pseudo random numbers that get a seed value before reading you're set values and another for its general randomness. The latter would never need to be seeded and would probably suit such things as random encounters. The user/player wouldn't notice the difference.

Other random generators I've come across but never really found the need to use are those that actually use the clock in its generation algorithm which will therefore return a real random value (ish), but still better because the clock is still turning.

I understand what you've said in the post but I've never actually used it in that form. Most of the time I seed then I know that the next billion will be in the same order every time with the same seed value. 99% of the time a bog-standard random number generator is just 3 or 4 mathematicals to move to the next number from its original seed.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Oct 2011 17:18
Quote: "unless you rely on those repeated numbers (such as using the seed to randomly generate an identical level on repeated runs of your game)"


Very useful for debugging as well.

Quote: "What I'd suggest instead is that you use different RNGs for different purposes"


Good suggestion. DBPro is a bit awkward in that respect. For example, you might want to re-use a random sequence in one part of your code but not in another. If you were switching to and fro between those you'd probably want to continue from where you left off in the second case. That doesn't seem to be easy in DBPro (except by doing something inefficient such as re-running or storing the sequence).
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 20th Oct 2011 21:17
i think this thread should be renamed to : RANDOMIZE debate
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Oct 2011 21:52
lol... Should've either been put in the geek forums or the programming talk.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Oct 2011 22:39
Quote: "If you were switching to and fro between those you'd probably want to continue from where you left off in the second case"

Yes, and it has been dead easy to do that for some years now:


Just as good is that the MT1 RNG has a cycle size of 2^11213-1

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Oct 2011 13:55
Quote: "and it has been dead easy to do that for some years now"


Indeed it has - but only with a certain plug-in.

Quote: "Just as good is that the MT1 RNG has a cycle size of 2^11213-1"


That's bound to be too short for someone.

Login to post a reply

Server time is: 2026-07-10 06:08:08
Your offset time is: 2026-07-10 06:08:08