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 / Pasting images is not faster than using the text command...

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd May 2011 04:19 Edited at: 22nd May 2011 04:47
I was creating a set of font effect functions when I noticed this. Using images is slightly slower on my system than just using the built in DBP font commands.

This program benchmarks them:



I'm using an Advent 8117
Dual core 1.73Ghz / 1Gb ram / Intel 943GML/950 graphics

The program simply prints the same text to the screen, one using the image font and the other using the standard font functions.

Does anyone get better results on their system? What I mean by better results, is the image version faster on yours than the standard font functions. My final results are built in font function-293, my image functions - 289. Not much of a difference now but when I come to expand on the functions they will be slower again.

I want to expand on these functions to allow pasting textured fonts.

zip file attached of the DBP project.

NB: It will create a .txt file with the results.

Warning! May contain Nuts!
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd May 2011 10:01
The times are identical for me (2821). I changed your function slightly, to be more efficient:



Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 22nd May 2011 10:09
Howdy,

Haven't tested the code, but it looks like you could rearrange the FONT_DRAW_STRING function to remove some redundant operations from inside the loop.


(untested)


There's a couple more tweaks, but you get the idea. If you can get rid of calling the mid$() function inside the loop, you'll probably get win back a bit more time, I suspect mid has a string length test in it (counts the characters), occurring each time a char is grabbed. So if you can get a pointer to the first character, then peek the rest out, then that should remove that over head. It might even be quicker to copy the string to a bank, then peek the bank.

However, you might find better results changing the method a little. An approach i've used before (on retro hardware mainly) is character pairing. But it could work here also. The font size can potentially blow out a bit, but we're halving the number of blits.

Another common approach is caching the words (or entire string) to an image. Which works well if you have lots of text to draw. It does mean splitting the source text (or paragraphs) into unique word list. Which can be done on demand or up front.

A combo of unique words and paired of grouped characters might even work also. Depends on how much text you want to throw around real time.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd May 2011 12:50 Edited at: 22nd May 2011 12:51
You can save memory by putting all the characters into a single image, making a sprite from it, and using "set sprite texture coord" to select individual letters from the image. You can use "paste sprite" to draw it to the screen.

Doing it this way you also get the benefit of being able to scale/rotate/colour/fade the text when you draw it without having to create a new set of images.

As for speed:
The main benefit of using images over the built in text commands is changing font. With the text commands you can only have one font active at a time, and changing the font is INCREDIBLY slow. With images you can create all the fonts you'll need at the start and then switch between them at no speed cost.

[b]
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd May 2011 14:50 Edited at: 22nd May 2011 15:08
Scaling, rotating, colouring and fading I'll be looking into if I can get it to work with sprites. I just hope that sprite sizes aren't restricted to their size.

I've tried both your function optimisations. I was surprised at the slight speed increase. It was definitely higher in Kevins alteration but I realise that's because there's less array grabs inside the loop. It actually worked out faster than using the built in font functions too.

I'll be back once I've played about with a sprite version though. This'll be the first time using the Sprite commands...

(Wow! I get a measly 303 benchmark while BatVink gets 2821, I need a new computer)

EDIT: SET SPRITE TEXTURE COORD Sprite Number, Vertex Index, UValue, VValue
I'm assuming the UV values and vertex index from 0.0 to 1.0 would be an offset within the sprites image data. Is there anywhere that may point out how this would work. I've got an idea for now...

Warning! May contain Nuts!
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd May 2011 19:46
Using the first example posted by WLGfx, here are my results:

Using FONT_UTIL FPS = 0
Using NORMAL FONTS FPS = 0
Using FONT_UTIL FPS = 2045.65625
Using NORMAL FONTS FPS = 3130

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd May 2011 20:17
Awww... lol... I'm getting 10% of everyones results.
All I can say is this is a great benchmarking laptop...

Cheers Phaelax!

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 23rd May 2011 02:17 Edited at: 23rd May 2011 02:29
I've added a bit to use sprite pasting but for some reason, the screen goes blue and images and sprites are not being drawn to the screen.

Can anyone figure out what's wrong with it please?



Once I've got this bit sussed then I'm going to add scale and rotation to it... Fingers crossed I can get this sussed out soon.

EDIT: Fixed... Typo... Should've been StringSize not StingSize...

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 23:13:40
Your offset time is: 2026-07-10 23:13:40