Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Pot Noodle on June 08, 2011

Title: A Better Way
Post by: Pot Noodle on June 08, 2011
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 :-[
Title: Re: A Better Way
Post by: Shockwave on June 08, 2011
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 :)
Title: Re: A Better Way
Post by: Shockwave on June 09, 2011
Sorry, this file in your archive won't compile for me.. There is a missing function :  "DrawSubImageRect"
Title: Re: A Better Way
Post by: Clyde on June 09, 2011
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.
Title: Re: A Better Way
Post by: Hotshot on June 09, 2011
Nice one and Keep going :);) :kewl:
Title: Re: A Better Way
Post by: Pot Noodle on June 09, 2011
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.
Title: Re: A Better Way
Post by: Shockwave on June 10, 2011
It's my fault mate my trial version of blitzmax is out of date
Title: Re: A Better Way
Post by: Storm Trooper on June 10, 2011
I dont think you need to be drawing all of the text message at once.
Title: Re: A Better Way
Post by: Pot Noodle on June 10, 2011
Can you explain for the sake of an old timer please how is it possible not to draw the text all the time?
Thanks
 :-\
Title: Re: A Better Way
Post by: Storm Trooper on June 10, 2011
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.
Title: Re: A Better Way
Post by: Pot Noodle on June 10, 2011
Yes my Friend I know what you mean good point  :goodpost: I will change it and see.
Thanks
Title: Re: A Better Way
Post by: Shockwave on June 10, 2011
I'll bet that's what causes most of the slowdown.
Title: Re: A Better Way
Post by: Pot Noodle on June 10, 2011
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:
Title: Re: A Better Way
Post by: zawran on June 11, 2011
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.
Title: Re: A Better Way
Post by: Pot Noodle on June 11, 2011
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.
Title: Re: A Better Way
Post by: zawran on June 12, 2011
If you post the code then I'll take a look at it to see if I can spot the problem.
Title: Re: A Better Way
Post by: Shockwave on June 12, 2011
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.

Code: [Select]
' *************************************************
' *                                               *
' * 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
Title: Re: A Better Way
Post by: Pot Noodle on June 12, 2011
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
Title: Re: A Better Way
Post by: Shockwave on June 12, 2011
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..
Title: Re: A Better Way
Post by: Shockwave on June 12, 2011
Anyway, there's no need to use drawsubimagerect..

I will quickly adapt the code for you and show you the easy alternative...
Title: Re: A Better Way
Post by: Shockwave on June 12, 2011
Download the attachment attached to this post.

This achieves what you wanted to do without having to use drawsubimagerect.
Title: Re: A Better Way
Post by: Pot Noodle on June 12, 2011
Hi,
I just copy and paste then change the path etc... for some one that doesn't do Blitz you sure press the right keys.
Thanks Shockwave.
Title: Re: A Better Way
Post by: Shockwave on June 12, 2011
:)