• Welcome to Dark Bit Factory & Gravity.
 

A Better Way

Started by Pot Noodle, June 08, 2011

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Pot Noodle

Hi Guys just wondering if anyone could make this faster? it's BM code and the setAlpha Setscale bit's slows it down.
Sorry about  that :-[

Shockwave

You could take the setalpha and setscale and place them outside the loops, also you could declare your variables before your loops.

It would be a lot easier to debug if you posted the complete project.
Just put it all in a zipfile and attach it to your post :)
Shockwave ^ Codigos
Challenge Trophies Won:

Shockwave

Sorry, this file in your archive won't compile for me.. There is a missing function :  "DrawSubImageRect"
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

It compiles with version 1.42. And welldone a nice start!
Another tip as well as Shockwaves, try a lower resolution to begin with. You can work on enhancing later.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Hotshot

Nice one and Keep going :);) :kewl:

Pot Noodle

That's strange it was you who wrote it, I will try a lower res and see what that does, Thanks for taking a look and thanks guys for your support.

Shockwave

It's my fault mate my trial version of blitzmax is out of date
Shockwave ^ Codigos
Challenge Trophies Won:

Storm Trooper

I dont think you need to be drawing all of the text message at once.

Pot Noodle

Can you explain for the sake of an old timer please how is it possible not to draw the text all the time?
Thanks
:-\

Storm Trooper

what I meant by that is, if letters are off the screen I don't think you need to worry about drawing them. I don't have an example as I haven't gotten round to writting one myself yet. the peeps in the know can probably put you in the picture, if my thinking was ok.

Pot Noodle

Yes my Friend I know what you mean good point  :goodpost: I will change it and see.
Thanks

Shockwave

I'll bet that's what causes most of the slowdown.
Shockwave ^ Codigos
Challenge Trophies Won:

Pot Noodle

Hi guys,
I have been trying to adjust my code so that the fonts on screen get drawn and not the ones off screen
If you know what I mean, the problem I have is there are two loops one for the mid$ and one for the vertical slice's
of the font, the first one loops through the hole text$ so it draws it all on and off screen.

Any help with would great
Thanks.
:suicide:

zawran

Your font is 32 pixels wide and all characters has the same width. So you should be changing the x value sent to the sinewave function from 0 to -31 and then only send the function the part of the scroll text that will fit onto the screen. Your screen is 1024 pixels wide, so that makes it 32 characters wide, but you need one more to allow for the scrolling, so you should be picking 33 characters from the scroll text string and sending those to the sinewave function.

So you need a text pointer which points to the current position within your scroll text and a x pointer which is used to determine where on the screen the first character is drawn. Then you change that x pointer until it reaches -31 where you then reset it to 0 and move the text pointer one forward.

I hope the above made any sense.

Pot Noodle

Hi zawran,
I have done what you said and all made good seance to me, But I still have a problem with the font it keeps drawing over itself
as it moves across the screen.

Thanks for your help.

zawran

If you post the code then I'll take a look at it to see if I can spot the problem.

Shockwave

I am definitely not the best person to look at this for you as I have no intention of learning Bmax but I threw an example together that does what Zawran has suggested.

It's not a sine scroll, it's a simple text scrolling routine that just draws a section of the scroll text string to screen.
I will be unable to provide any more help than this but hopefully it will get you on the right track.


' *************************************************
' *                                               *
' * BlitzMax Sine Scroll                          *
' * ====================                          *
' *                                               *
' * By Shockwave - www.dbfinteractive.com         *
' *                                               *
' *************************************************

' *********************************************************************
' * Open Screen                                                       *
' *********************************************************************

SetGraphicsDriver GLMax2DDriver()

Const xRes = 800
Const yRes = 600

Graphics xRes,yRes,32,60,GRAPHICS_BACKBUFFER


Global Font = LoadAnimImage("sfont16.bmp",16,16,0,59)

Global ScrollText : String ' String to store the text
Global Tpos:Int' Position in text string.
Global ScrlPos:Int' Scroll Offset.

ScrollText ="                                                      "
ScrollText=ScrollText+"Just a small example of how to make a scroll routine without drawing every letter in the string...      "
ScrollText=ScrollText+"This was written for Pot Noodle on the DBF forum by shockwave..       Wrap!       "
ScrollText=ScrollText+"                                                     "

ScrollText=Upper(ScrollText)' Convert to uppercase
Tpos=1' Position in string
ScrlPos=0' ScrollOffset

' *********************************************************************
' * Main Loop                                                         *
' *********************************************************************

Repeat


Do_Scroller()

Flip(-1)
Cls

Until KeyDown(KEY_ESCAPE)




EndGraphics
End

' *********************************************************************
' * The Scroller                                                      *
' *********************************************************************

Function Do_Scroller()

ScrlPos=ScrlPos+2' Move the scroll offset.

If ScrlPos>16 Then ' If the text has scrolled more than the char width, reset scroll pointer and advance text pointer
ScrlPos=ScrlPos-16
Tpos=Tpos+1
If Tpos>Len(ScrollText)-52 Then Tpos = 1' Check to make sure that the text pointer hasn't gone out of bounds
End If

Local DrawPos: Int
Local TextAdd: Int
Local Letter:  Int

TextAdd=0' This is added to in the draw loop to step to different letters
DrawPos=(-16)-ScrlPos' This is the current drawing position


'
' Draw letters all across the screen until we go off the screen.

Repeat

Letter=Asc(Mid(ScrollText,(Tpos+TextAdd),1))-32

DrawImage Font,DrawPos,50,Letter

TextAdd=TextAdd+1
DrawPos=DrawPos+16

Until DrawPos>=Xres

End Function

Shockwave ^ Codigos
Challenge Trophies Won:

Pot Noodle

Thanks Zawran for your offer, I have looked at Shockwave's code and have tried to implament it but the problem is
I go through each vertical line of each character and then use DrawSubImageRect but I was using x = x + 1 to move across the screen which is ok for drawing vertical lines but using DrawPos = DrawPos + 32 draws the hole font so I have uploaded my code for you to look at.
Thank you very much for your time and thanks Shockwave for the code it all makes seance just can't get it together  ;D

Shockwave

Have you tried compiling the example I posted?

I only ask because I posted the project as a post attachment which includes the font and it hasn't been downloaded yet..
Shockwave ^ Codigos
Challenge Trophies Won:

Shockwave

Anyway, there's no need to use drawsubimagerect..

I will quickly adapt the code for you and show you the easy alternative...
Shockwave ^ Codigos
Challenge Trophies Won: