MEM2SPRITE() array access challenge

Previous topic - Next topic

CW

Hi, I've enjoyed reading the posts here in times past, but this is the first time I have needed advice. I hope someone can help.

I am currently well into the writing of an animation spread-sheet program, which treats animation frames and operations on them similarly to how spreadsheet functions operate on data cells. Each row of my spreadsheet contains a different filmstrip, each with a different layer or object for the composite final animation. All rows will be stacked on top of each other, like layers, for the final animation. You get the idea. So far so good.

Needless to say, I have a LOT of frames. I calculate that my memory will allow six filmstrips of 130 frames each, plus the final composite film strip, for a total of 910 frames. So far I have been crunching data using arrays extensively, and then copying individual frames to a workspace one-dimensional array from which to make a sprite to draw onto the spreadsheet cell. That is a lot of copying going on. Can it be avoided?

It occurs to me that the program would run much faster if I can make better use of the native GLbasic sprite handling functions. For example, SPRCOLL() could be used to detect blank frames for the purpose of setting the end pointers or detecting empty film tracks after the user deletes one or more frames. But to use the sprite handling functions, I need to use MEM2SPRITE(). Here we get to the horns of my dilemma.

With so many frames contained within so many filmstrip rows, each with a full sprite of data, it would be very difficult to manage lots and lots of single-dimensional arrays; yet MEM2SPRITE() seems to function only with single dimensional arrays. Is there a way to eat my cake and have it too?

I wrote the following bit of code to show the two approaches I have taken in trying to program around this limitation. Neither approach seems to work, but maybe I am missing something. That is what I would like advice on, please.

For the record, I am just a hobbyist when it comes to programing. I can manage most tasks I set myself with BASIC, but I am a rank amateur at C++, so I would like to stick with basic if at all possible.

Thanks for any advice you can give. Here is my demonstration code. -CW
Code (glbasic) Select

// Attempting MEM2SPRITE() work around.
// (Excuse the mousefont. I am trying to keep things simple. Please add a font for readability if you wish it.)

TYPE Track
GraphicData[10000] //100 X 100 sized frames (or sprites)
ENDTYPE

GLOBAL Filmstrip%[] AS Track
DIM Filmstrip[6]
// Note that for simplicity I have removed an entire hierarchy layer of complication (IE: 6 tracks, each 130 frames long,
// each frame containing an entire sprite worth of pixel data.) The simplified model is sufficient for the problem I am trying to solve.

LOCAL counter% = 0 // Count number of pixels set for later print statement.
FOREACH frame IN Filmstrip[];FOREACH pixel IN frame.GraphicData[];pixel = RGB(255,255,0);counter=counter+1;NEXT;NEXT

PRINT "All Frames in all 6 filmstrips filled with yellow. ",10,30
PRINT counter+" Pixels set.",10,60
PRINT "Attempting to create a sprite using a pointer in MEM2SPRITE(). PRESS KEY.",10,90
SHOWSCREEN;KEYWAIT

//Let's create a comparison sprite from a single-dimensional array to demonstrate that the mechanics are otherwise sound.
GLOBAL CS%[]
DIM CS%[10000]
FOREACH pixel IN CS[];pixel=RGB(0,255,0);NEXT
MEM2SPRITE(CS[],2,100,100)

////////////////////////////////////////////////////////
// This next bit is the point of the program.
// I am trying to get around the single dimensional array limitation of MEM2SPRITE() using a pointer.
// (I know, I know, arrays all pass pointers anyway, so why should MEM2SPRITE be so picky on this?
// Instead of a pointer to a single array, why not a pointer to a single array within a multidimensional array? Can it be done?)

//MEM2SPRITE(Filmstrip[2].GraphicData[],1,100,100) //The direct approach

ALIAS FramePointer AS Filmstrip[2]
// MEM2SPRITE(FramePointer.GraphicData[],1,100,100)   //Using a pointer as stand-in for Filmstrip[2], just in case MEM2SPRITE is syntax sensitive, for some reason.
//
// Neither approach will compile successfully. It seems GLbasic can't handle this, or am I missing something?
////////////////////////////////////////////////////////

CLEARSCREEN
ALPHATESTING 1 // Disable transparency, as I did not set Alpha when I filled the frames with color.
DRAWSPRITE 1,70,10;DRAWSPRITE 2,400,10
PRINT "Multi-Array Sprite",50,120;PRINT "Single-Array Sprite",375,120
PRINT "Press Key to Exit",220,150;SHOWSCREEN;KEYWAIT
END

Marmor


CW

The bank system looks really interesting. (New Toy!) I'll have to give it some study.

Some of what Hello Kitty is doing there, efficiency wise, might come in handy for a very-long-number calculator project I've been thinking on.  (I have a simple Mandelbrot set generator I would like to expand on; and, for kicks, I would like to do a program to calculate lots of digits of pi. Twelve digits of accuracy in calculations can only get you so far, so what I really need to do is to write a very-long-number calculator.)
So many projects, so little time.  =D

Thanks Marmor! You are all right.  :booze:

-CW