Author Topic: A Better Way  (Read 10709 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
A Better Way
« 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 :-[
« Last Edit: June 08, 2011 by Pot Noodle »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #1 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 :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #2 on: June 09, 2011 »
Sorry, this file in your archive won't compile for me.. There is a missing function :  "DrawSubImageRect"
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: A Better Way
« Reply #3 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: A Better Way
« Reply #4 on: June 09, 2011 »
Nice one and Keep going :);) :kewl:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #5 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.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #6 on: June 10, 2011 »
It's my fault mate my trial version of blitzmax is out of date
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Storm Trooper

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: A Better Way
« Reply #7 on: June 10, 2011 »
I dont think you need to be drawing all of the text message at once.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #8 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
 :-\

Offline Storm Trooper

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: A Better Way
« Reply #9 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.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #10 on: June 10, 2011 »
Yes my Friend I know what you mean good point  :goodpost: I will change it and see.
Thanks

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #11 on: June 10, 2011 »
I'll bet that's what causes most of the slowdown.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #12 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:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: A Better Way
« Reply #13 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.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #14 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.

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: A Better Way
« Reply #15 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.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #16 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
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: A Better Way
« Reply #17 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

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #18 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..
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: A Better Way
« Reply #19 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...
Shockwave ^ Codigos
Challenge Trophies Won: