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 / Can anyone make this faster?

Author
Message
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Feb 2011 03:04
I made a simple window box function thingy and I've been trying to make it as fast as possible. I learned an interesting thing; it is quicker to draw two small boxes than one large one. I assumed that the box command was slow but it seems to be the turning on of pixels that is slow, so I took out the code that draws on top of each other and it doubled the speed!
Here is the code:

On my machine I'm getting 10,000 panels drawn in just under 2 seconds.



Everything worthwhile requires effort.
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 21st Feb 2011 22:09
By removing a little redundancy and checking for a border width of at least 1, with a border of 20 I get about a 60% speed increase. With a border < 1 the speed increase is about 25 times as fast:



Enjoy your day.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Feb 2011 23:18
Interesting. I originally did the light and shade the same way as two boxes overlapping, but I found this to be slower than drawing four smaller boxes. Is this the case for you too or is drawing two boxes really faster?

I also wonder whether drawing the entire edge including bevelled corners in strips of boxes would be faster than drawing boxes and then corners separately.

This is a good example of the infinite ways to solve a programming problem.


Everything worthwhile requires effort.
29 games
14
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 21st Feb 2011 23:25
I just ran your code and it took just under 13 seconds to draw 10,000 panels but then my computer's not all that good.

I managed to speed this up to just over 12 seconds by changing how the function draws the bevel edge. Rather than drawing the white borders top and to the left then adding the bevel edge, I changed it so that the light border is drawn one line at a time (using the box command) and just shortening the line each loop to create the bevel.



I tried to the same idea for the dark border, thinking that drawing less pixels would be quicker, but this slowed the function up.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Feb 2011 00:18
Ah very interesting 29Games, thanks.


Everything worthwhile requires effort.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 22nd Feb 2011 17:28
hi,

why you do not use (get image / paste image)?

AMD Athlon(tm)XP 3200+ (2.2GHz) / DDR pc3200 (3x1024Mo) / Nvidia 6800GT (driver 197.45 WHQL)/ XP Pro SP3 / DirectX 9.0c (February 2010)/ DBClassic v1.2 / DBPro v7.4
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2011 00:09
@Silverman
Good idea. That is what Latch did but he used bitmaps instead. I suppose the reason he chose bitmaps is because the drawing can be done off-screen and one can copy to another bitmap in one command, whereas with images you'd have to draw the image, then grab it, then paste it, which involves an extra step.

There is a draw-back to using bitmaps though; you can only use 32 bitmaps, so what if I wanted 33 panels? You can't guarantee that every corner will look the same because of the variable border size. <- my thinking pipe...

A solution to this problem would be to make one bitmap storing a corner with the largest possible border size, then copying only the appropriate sized section from this bitmap when drawing the corners of a panel.


Everything worthwhile requires effort.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 24th Feb 2011 17:20 Edited at: 24th Feb 2011 17:25
Using "image" is easier to manage. You can separate the creation and display. It's very fast.

On my computer, only 7 milliseconds(instead of 8000 with your code) to display the 10000 panels. Try this:


AMD Athlon(tm)XP 3200+ (2.2GHz) / DDR pc3200 (3x1024Mo) / Nvidia 6800GT (driver 197.45 WHQL)/ XP Pro SP3 / DirectX 9.0c (February 2010)/ DBClassic v1.2 / DBPro v7.4
Ashingda 27
12
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 25th Feb 2011 05:32 Edited at: 25th Feb 2011 06:06
You know PRINT and SET CURSOR are such slow commands, using it slows your program down so much and you won't be getting a very accurate fps reading.

Silverman's snippet, replaced PRINT with TEXT:


[edit]

Another method to minimize even the TEXT statement further using bitmap for the graphical interface instead of TEXTing everything.
Obese's original with method:


Obease + Latch with method:


Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Feb 2011 20:27 Edited at: 25th Feb 2011 20:30
Quote: " That is what Latch did but he used bitmaps instead. I suppose the reason he chose bitmaps is because the drawing can be done off-screen and one can copy to another bitmap in one command"

That's not quite what I did. One of the huge slowdowns in building the window panel is the beveling of the corners. If the border is 20, that's 20 additional iterations for each corner. In Obese's original code, 2 beveled corners are drawn:



With a border of 20 units, that's 40 (maybe 42 because of starting the loop at 0) additional boxes being drawn per function call. The fastest graphical blitting in DBC (from what I've tested), is copying from one location to another all on bitmap 0. So, to cut the beveling drawing in half, I copy the top corner, to the bottom corner using the COPY BITMAP command on bitmap 0, after the top corner is drawn.



Also, I added a conditional to test if there is a border at all. If there's isn't, the assignments and the border drawing is skipped all together speeding things up dramatically.

@Silverman
Quote: "Using "image" is easier to manage. You can separate the creation and display. It's very fast."

That is key to your solution. In your code, you only actually draw (build) the window panel once. Your test isn't the time it takes to draw or create a panel, but rather to paste an already created image. Your solution is sound and vert fast if one never has to create new panels of different sizes and colors. If you reuse a window panel, there's no reason to redraw it; but if you need to draw 10,000 different panels, what's the quickest way to achieve this?

So, here's the question, can an image be used to more quickly create the panel?

Enjoy your day.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 26th Feb 2011 18:47
@Latch
I think it depends on what you want to do. Use the images to separate creation/display and display on the screen ~100 different panels seems a good choice, but to view more, maybe memblock + bitmap is a better option.(I did not test this possibility.)

AMD Athlon(tm)XP 3200+ (2.2GHz) / DDR pc3200 (3x1024Mo) / Nvidia 6800GT (driver 197.45 WHQL)/ XP Pro SP3 / DirectX 9.0c (February 2010)/ DBClassic v1.2 / DBPro v7.4

Login to post a reply

Server time is: 2020-08-06 08:20:59
Your offset time is: 2020-08-06 08:20:59