Qbasicnews.com
October 19, 2021, 09:29:11 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: More Speed in Game  (Read 4215 times)
Aaron
Member
*
Posts: 35


« on: July 12, 2003, 08:38:41 PM »

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)
Logged
Agamemnus
x/ \z
*****
Posts: 3491



:
« Reply #1 on: July 12, 2003, 11:17:33 PM »

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
Logged

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.
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #2 on: July 14, 2003, 02:52:01 AM »

SETVIDEOSEG. ;*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Aaron
Member
*
Posts: 35


« Reply #3 on: July 15, 2003, 12:25:37 AM »

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
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #4 on: July 15, 2003, 01:25:15 AM »

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=DoubleBufferingConcepts
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #5 on: July 15, 2003, 04:08:11 AM »

And way faster the POKEing each pixel. ;*)

here:

http://forum.qbasicnews.com/viewtopic.php?t=3165
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Aaron
Member
*
Posts: 35


« Reply #6 on: July 15, 2003, 11:21:10 PM »

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?
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #7 on: July 16, 2003, 12:48:11 AM »

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.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!