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 Discussion / Amazed at the slowness of the Point command.

Author
Message
Zaxtor99
12
Years of Service
User Offline
Joined: 27th Jul 2011
Location: Boise, Idaho, USA
Posted: 1st Aug 2011 09:21
Okay, I am playing around making a few programs in DB (classic).

I just put together a classic style snake game that works pretty good in just a few hours time. Basically you have to eat 10 apples in each room and then a door opens up on a random outside wall you need to get through to exit to the next room and your worm grows in length a lot with each apple eaten. With each new room you advance to, it gets tougher because of more walls you have to work around (and apples appear only one at a time in a random screen location)

Anyhow, on to my question. Right now, I have the program checking the players X and Y location on the screen against where the walla are drawn in the room, which is a lot of checks in each room. The speed of the game is VERY fast... almost too fast. A good challenge. But to make the game even more efficient, I took out the checks for x and y location against where each rooms walls were drawn and tried using the point() command to see if the location equaled the color that the walls were drawn in. So one check vs hundreds. And to my surprise this check slowed the game down to about half the speed, when I expected it to actually speed up the loop and game speed.

I am just using all CHR$ drawn graphics which doesn't actually look too bad. But I am in shock that using the point command at one x y location slowed the game down over my initial checking the x y coords over every spot on the screen that walls were drawn.

While I am not exactly new to basic programming, I am new to DarkBasic. Anyone have any reasoning for this??


- Zaxx
Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 1st Aug 2011 17:01
Yes, the POINT command in DBC is agonizingly slow. You would do well to use another method, as the POINT command will only slow things down.

I'm not sure of the actual method you used, but an array could be used very effectively to tell where the walls are and should give you good FPS. You would create an array to divide the screen up into squares of a certain size (say 8 pix by 8 pix). (i.e. using a 640 X 480 screen would require a 80 X 60 array). Where you want a wall, you place a number in the array to represent a particular color. Say, a value of 1 = red, 2 = green, etc. You check the worm's head and segments against this array to see if there is a collision before it is actually moved. You could use this array to draw the screen initally also.
Zaxtor99
12
Years of Service
User Offline
Joined: 27th Jul 2011
Location: Boise, Idaho, USA
Posted: 2nd Aug 2011 00:47 Edited at: 2nd Aug 2011 00:57
wow, I get what you are saying, but that sounds like a good way to get me, the programmer confused trying to program all those 8x8 segments in. Let me ask though, why not just use a multi-dimension array for the screen as in Wall(640X480) and have the walls of each room give values to each block of a single array? Or even two arrays such as WallX(640) and WallY(480). Would your way be that much faster dividing the screen up? (as to be worth confusing me trying to program like that, heh)

Right now, I guess there isn't actually "hundreds of checks" as I posted in my OP. I simply check the snake head position before it is updated on screen as such: if Xchek<20 or Xchek>620 then gosub krash and if Ychek<40 or Ychek>460 then gosub krash Those lines check the outside wall crashes, and then I use similar checks to check for crashing into the particular walls drawn in each room starting with room 2.

My point is that my game is already running almost TOO fast with a sync rate of 30. If I pump it up to sync rate of 60, it is twice that fast, and a sync rate of 0 would be insane.

Besides programming for efficiency and pride to make the code look "snazzier", is there really an advantage of going with comparing the player position against array data over simply checking the player position over hard wall X and Y coordinate numbers for each room?

Now I tried the "point" command because I saw that it checked for a color at a given X,Y position on the screen.. and that DID look much easier, but it turned out to slow down the main loop speed big time and not at all worth even using.I fact, I'd love to know when the point command would even be practical to use in ANY game as slow as it seems, heh.

Anyhow, thanks for your help.. I appreciate the discussions, especially since I haven't programmed in Basic for almost 30 years now since I was a young kid on my old Commodore 64, and I am new to DarkBasic as well.


- Zaxx
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 2nd Aug 2011 02:44
The only practical use for the point oommand in DBC is probably for a cheap/quick/"not so great" menu box check. Other than that it shouldn't be used because of it's speed problem and there are better alternatives.

As for collision checking I'd stick to the way you had it before using the point statement. It may seem like a lot of process at first glance but if you sum it up it's really just a few boolean checks, it really is the fastest you can get from my experience.

Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 2nd Aug 2011 02:45
Quote: "why not just use a multi-dimension array for the screen as in Wall(640X480) and have the walls of each room give values to each block of a single array? "

It would be easier to explain with code, so here goes:


This code creates an 80 * 60 array and then makes red, green and blue wall pieces, that form an 'L'. Click the mouse to exit

Quote: "Besides programming for efficiency and pride to make the code look "snazzier", is there really an advantage of going with comparing the player position against array data over simply checking the player position over hard wall X and Y coordinate numbers for each room?"

With this particular program, speed is not an issue. However, as you write more complex programs, speed will likely come into play (no pun intended). Arrays work well for me and I use them in every program to some degree or another. They are a fast way to check for 2D collisions.

Quote: "I'd love to know when the point command would even be practical to use in ANY game as slow as it seems, heh."

I can't say I remember a program that I have written that uses it. Pretty much alternative methods are being used.

Quote: "Commodore 64"
Wow, how old ARE you? (just kidding!) Great that you're back in it. You can make games pretty quickly with DBC. I wish you well.
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 2nd Aug 2011 11:13
Sorry, why would you need a screen resolution sized array?...

And yes, there is an advantage over using pixel detection: the array detection will never have bugs, while pixel detecting is bound to cause some stupid problems sooner or later.

You absolutely don't have to rely on the FPS, make delays pal.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Aug 2011 11:43
@Zaxtor99

point() isn't as slow as it seems. It really depends on how it is used. What makes point() seem like it's slow is that it calls an automatic SYNC when it is used. If you iterate through a loop using point(), it'll take forever because a SYNC is called after each iteration. But, if you use point() in place of SYNC in your main loop, there will be virtually no speed difference.

For example, the following program will return the color under the mouse. It uses point() to SYNC while at the same time retrieving the color:



Now here's the same code using SYNC without point(). Notice that the FPS is the same (at least on my machine):



Enjoy your day.
Zaxtor99
12
Years of Service
User Offline
Joined: 27th Jul 2011
Location: Boise, Idaho, USA
Posted: 2nd Aug 2011 14:26
Wow Latch, thanks... that is awesome information.

Now that makes sense... I was wondering why DarkBasic would have such a worthless command, but now that we know that using the point can include your main loop SYNC and get the same FPS, it makes sense. Thanks for adding that here!! ..Good stuff.

I also am learning a LOT about arrays now, lol. I think that when I wrote my own BASIC programs on the Commodore 64 as a kid, I only used basic variables, print statements, and ten thousand if-then statements, heh.

I tried using a huge screen array in my snake game for the position of the X and Y coords or the walls, and it slowed the game down considerably. So I went with an array 1/10th the size for that wall array 'dim wall(64,48)' vs the 'dim wall (640,480)' and the speed is now smoother then ever. Since my snake moves in 10 pixel increments, this made sense anyhow, but I answered my own question!

Now with Latch's new info vs the point command, I might experiment with that and get rid of the wall array and simply use a point check at the end of my main loop to check for the X and Y coords of the player snake position vs my wall color given via point(). If I remove the SYNC in that main loop, and use the point check instead, perhaps it will run as smooth or even better.

I am uploading a short video of my snake game to Youtube to see how bad my graphics get trashed, lol. You can watch it here:

http://www.youtube.com/watch?v=kXh0vN3U5TE

This is really my first successful attempt at making anything with any sort of graphics at all in DarkBasic... so please be gentle!


- Zaxx
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Aug 2011 05:07
Quote: "n. But, if you use point() in place of SYNC in your main loop, there will be virtually no speed difference."


Wow.... I figured that out about point() back in the day but it never occured to me to use it in place of my sync command. Bravo sir, bravo!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Aug 2011 18:16
Even I didn't know that about point()

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Aug 2011 21:32
Quote: "Even I didn't know that about point()"

WHAT!? The almighty Phaelax's knowledge is incomplete!?

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Aug 2011 05:15
Quote: " WHAT!? The almighty Phaelax's knowledge is incomplete!? "


Well not anymore.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Zaxtor99
12
Years of Service
User Offline
Joined: 27th Jul 2011
Location: Boise, Idaho, USA
Posted: 5th Aug 2011 09:12 Edited at: 5th Aug 2011 09:13
Sometimes, it isn't so much that someones knowledge is "incomplete" as much as it is that they have forgotten more then some of us will ever know. If I ever know half as much about this coding and programming as a lot of you guys have forgotten just since you got DarkBasic, Heck I'll be happy. lol.

Think of our brains as a huge 10 Terabyte hard drive or something. At SOME point, it will be full given enough life experiences, and some data has to be let go in order to store more data. I'm "sure" that's exactly what happened with Phaelax here, right Phaelax? {grins}


- Zaxx
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 5th Aug 2011 13:19 Edited at: 5th Aug 2011 13:21
Hi,

snippet made ​​by latch:
[DBC] POINT command substitute using GDI
http://forum.thegamecreators.com/?m=forum_view&t=128229&b=6

@+

DirectX 9.0c (February 2010)/ DBClassic v1.13
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Aug 2011 16:41
I started work on some custom drawing functions a while back, using memblocks.

That might be a bit advanced for you to understand just yet but the functions are pretty easy to use and much faster than the default drawing commands, if I remember correctly.

Login to post a reply

Server time is: 2024-04-19 23:31:32
Your offset time is: 2024-04-19 23:31:32