Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: R@dioman on January 27, 2003, 04:21:28 AM



Title: VPage array...
Post by: R@dioman on January 27, 2003, 04:21:28 AM
How many cells in my array [ex: myarray(*cells*)] should have to make a virtual page of one screen. I always use VPage(31999) but that's for a large scroller. And how do I calculate the space necessary for x number of screens held in the array or the buffer if you like. Oh, and a better word for cell. Thanks :)

P.S. What's going on with all the posts? Spring cleaning? :wink:


Title: VPage array...
Post by: toonski84 on January 27, 2003, 07:43:25 AM
the forum was attacked by some people who knew a bug in phpbb2 and most were deleted.

the number of bytes, bits, whatever is what you need to know.  in mode 13h, or any 256 color mode, each pixel takes up one byte.  since the smallest unit qb has (short of string * 1) is an integer, that takes up two bytes.  so think here:

1 (byte per pixel) * 320 (width of screen) * 200 (height of screen) / 2 (bytes per integer) = 32000

since 0 is an array unit too, 31999 is sufficient.

HOWEVER:  you dont get a lot of memory in pure does.  dos has a 640k memory limit and qb a 64k one (if you dont use $dynamic).  if you need to use more than one off screen buffer, or if your program is graphic-intensive in general look into using ems memory.


Title: VPage array...
Post by: na_th_an on January 27, 2003, 08:23:16 AM
To make a scroller you DONT need a huge offscreen buffer!! (well, you could do it that way, but it would be SLOW AND MEMORY KILLING).

With your vpage%(32001) buffer you have enough. What you should do is only draw the portion of the game map which the player should see. It is easy to do using tiles.

Check out relsoft's scrolling tutorial to find out.


Title: If you're going to be storing a screen's worth of...
Post by: Glenn on January 27, 2003, 11:35:25 AM
data (in mode 13) in an array that you can use with GET and PUT, you need 64,004 bytes.  (There are 4 extra bytes for size information at the front of the array


Title: VPage array...
Post by: ak00ma on January 27, 2003, 02:28:05 PM
...or in QB words:

dim shared buffer(32001)


Title: VPage array...
Post by: toonski84 on January 27, 2003, 08:44:20 PM
true dat, my mistake.  forgot about the width/height specs.


Title: VPage array...
Post by: R@dioman on January 27, 2003, 08:46:37 PM
Suppose I have a map arranged like so where 1 square is one screen and the star is the player, where if he passes the screen the other map loads:

|------|------|
      *
|------|------|

This is a non-scrollable map. If it were scrollable, I understand how to use the screen buffer now. So I would have the left map in memory, then when the player passes the screen boundary, I would clear my map array, reallocate the array to use the second map, then draw the map blah blah blah. Would I have to use $dynamic to reallocate my array which the reallocation would reside in a subroutine? I hear it gets tricky using $dynamic variables. Is there a good tutorial out there which explains proper usage of dynamic array allocation?


Title: VPage array...
Post by: na_th_an on January 28, 2003, 11:57:35 AM
It is not very tricky. Also, if you don't use $DYNAMIC, you will get out of memory very soon.

If the map you are gonna load is the same size as the previous, you don't need to reallocate your arrays, just overwrite the values. If it isn't, ERASE will clear your array and REDIM will give it new dimensions. Not so tricky ;)

About tuts, sorry but I don't know... Maybe another poster could help.