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 / Quick way of finding out if a value is in between a range in an array.

Author
Message
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 3rd Nov 2003 00:17
I'm using the following routine to see if an X & Y value is inbetween an x,y-dx,dy range in an array.



It works, but is very slow - is there a way of making this sort of thing much faster ?


Avatar & Logo by Indi. Insert witty comment here...
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 3rd Nov 2003 00:25
Well, first off, remember 'exit' only exits 1 level. So if you do find a match, it will still check all other tX values.

put something like this after Next tY



Boo!
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 3rd Nov 2003 00:29
Yes, thats certainly added 33 extra FPS...


Avatar & Logo by Indi. Insert witty comment here...
The Big Babou
23
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 3rd Nov 2003 04:12 Edited at: 3rd Nov 2003 04:13
instead of using ands, you should check every term with its own if.
every loop all 4 terms are checked whether they are true or not. with the changed code, checking all 4 terms is the worst case, because if the first term is false the others aren't checked any more. you can optimize it even more, if you know which terms are "more often" wrong than others. put these terms above the others

EDIT: source code attached
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 3rd Nov 2003 05:53 Edited at: 3rd Nov 2003 05:55
also,

Depending upon how Type Variables are accessed in DBpro, you'd most likely be better off pulling the players details into LOCAL variables (since the players position isn't changing) rather than constantly checking fields from the type. (which is most likely 2 operations i.e. the first being pop to a temp local anyway)

The only other thing that comes to mind (apart from what is already stated), is that you can remove those calcs on MAXGRID X & Y in the second nest, mostly outside the inner loop. For the Y calc it really depends a lot on whats in the look up table, but anyway.





Kevin Picone
Play Basic - Visible Worlds - Kyruss II
[url]www.underwaredesign.com[/url]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Nov 2003 09:06
You might find it faster to keep the array sorted so that you can do a binary chop on it, rather than potentially having to look at every wntry in the array to find a match
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2003 09:29
That's a good point IanM. TCA, how many elements are in your array?
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 3rd Nov 2003 10:06
256*256 - unfortunately it cant be sorted.


Avatar & Logo by Indi. Insert witty comment here...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Nov 2003 14:22
So create another array of type (integer/integer) that just points to entries in the main array, and sort that instead.
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 3rd Nov 2003 19:56
I was thinking that - the only thing stopping me is the memory requirements


Avatar & Logo by Indi. Insert witty comment here...

Login to post a reply

Server time is: 2026-07-26 16:03:43
Your offset time is: 2026-07-26 16:03:43