Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More Speed in Game
#1
I'm working on a top down scroller and am having problems getting enough speed out of it. Currently my code is something like this:

(pseudo-code)
Do
Get Input
Update Positions of everything
Update graphics
Send Graphics to Screen
Loop


So, what I want to do is to only update the graphics everyonce in awhile, and only when I want to send them to the screen, while still having the code for getting the input and updating the postitions of everything run in the background. In addition, I want to limit the speed of the updating and such because I am afraid when the graphics portions are only done when needed, the rest of the code will run too fast.

Basically, what I am wondering, is if anyone has any suggestions for me. (BTW, I'm not using any libraries or assembly, so any suggestions would be greatly appreciated. I would post my code, but right now, it is in fairly early stages, and quite long and uncommented. It is no where near finished, but I still want to try to do what I'm suggesting while it is still early in the process of being coded)
Reply
#2
1) have key/mouse input constantly update.
2) have logic and graphics update either separately or together. (together is best..) Sometimes it's best for some graphics-intensive stuff to update BLA times less than logic with a counter...

Code:
dim shared counter(1 to 10) as integer
t1#=  timer
do
if t1# - timer > .1 then
t1# = timer
bla
do logic stuff
do graphics stuff
end if
loop

sub SampleGFXLoop()
if counter(bla) < bla then counter(bla) = counter(bla) + 1: exit sub
counter(bla) = 0
end sub
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
SETVIDEOSEG. ;*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#4
ok, so I read the faq on setvideoset, and I don't understand it exactly. when you change the video segment, do you just write to you memory segment and then have it appear on the screen? or do you write to the memory after you have changed the video segment, and if so, what good does that do? wouldn't there still be flicker?

Right now, I'm just writing to a buffer, that has previously been defined as an array, and then just PUTting it onto the screen. Will the whole SetVideoSeg work alot better than that, and if so, how?

Thanks for your help
Reply
#5
It works exactly in the same way that your buffer does, but you can also use QB's drawing functions. You just change the video segment (just like in SCREEN 7 and similar you set a non visible page as active), you draw, you set the video segment again to &HA000, then you copy your buffer to screen,.

General explanation here: http://faq.qbasicnews.com/?blast=DoubleB...ngConcepts
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
And way faster the POKEing each pixel. ;*)

here:

http://forum.qbasicnews.com/viewtopic.php?t=3165
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#7
ok, this is the routine I'm currently using to write to my buffer:
Code:
SUB fastput (x%, y%, filename$)
   REDIM img%(MAXSPRITE)
   DEF SEG = VARSEG(img%(0))
   BLOAD filename$, VARPTR(img%(0))
   wimg& = img%(0) \ 8                                'determines width of the image to be put
   himg& = img%(1)                                      'determines height of the image
   wpage& = page(0) \ 8                               'determines width of the page to be written to
   simg& = VARPTR(img%(2))                         'finds the start of the img to be displayed
   spage& = VARPTR(page(2))                        'finds the start of the actual graphics data
   FOR ycnt& = 0 TO himg& - 1                        'loops through the images rows
      FOR xcnt& = 0 TO wimg& - 1                    'loops through the columns of a row in the image
         oimg& = wimg& * ycnt& + xcnt& + simg&         'finds the pixel in the images offset
         DEF SEG = VARSEG(img%(0)) + INT(oimg& \ 16)
         pixeltocopy% = PEEK(oimg& AND 15)
         IF pixeltocopy% AND (y% + ycnt&) > 0 AND (x% + xcnt&) > 0 AND (y% + ycnt&) < 199 AND (x% + xcnt&) < 319 THEN
            opage& = wpage& * (ycnt& + y%) + xcnt& + x% + spage&   'finds offset in screen buffer
            DEF SEG = VARSEG(page(0)) + INT(opage& \ 16) 'sets the segment of the pixel being placed on the page
            POKE opage& AND 15, pixeltocopy%                  'places the pixel in the page buffer
         END IF
      NEXT xcnt&
   NEXT ycnt&
   DEF SEG                                              'returns segment to basic's default
END SUB

will it be much faster to use setvideoseg and then use the native qbasic functions?
and if so, how much faster?

thank you guys for all your help

also, my buffer is already put compatible and all that, should I use put to transfer it to the active memory page?
Reply
#8
Yes, much faster. Try to read the example scroller to see how to use it. ;*)

Also Pre-Clipping your sprite dimensions would be faster than an F then inside your X loop.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)