Mail Archives: djgpp/1998/04/22/21:05:48
well, I got a great suggestion which is to implement a vector class as
follows (assuming your data is of integer type):
typedef struct BaseType
{
//base layer of tiles
int tileno; //which tile number to load from the datafile
int opaque; //can you see past the tile? For line of sight algorithm
int collision; //for collision detection, see #defines
int flag; //misc flag
};
class vector
{
public:
vector (void)
{
width = 20; //arbitrary starting map size of 20x15
height = 15;
data = new int[width * height];
}
~vector (void)
{
delete[] data;
}
int resize (const int _width, const int _height)
{
if ((_width <= 0) || (_height <= 0))
return -1;
width = _width;
height = _height;
delete[] data;
data = new int[width * height];
return 0;
}
int* operator[] (const int _y)
{
/* FIXME: test for index out of range. */
return &data[_y * width];
}
private:
int width;
int height;
int* data;
};
however, my data type is not an INT, it's a struct containing 4
structs as follows:
typedef struct FringeType
//non-pickupable objects
{
int tileno;
int flag;
};
typedef struct ObjType
//normal objects
{
int tileno;
int active; //shouldit be blitted???
int flag;
};
typedef struct RoofType
//for the roof of buildings/etc
{
int tileno;
int flag;
};
typedef struct MapStruct
//just contains all the other structures into 1
{
BaseType base;
FringeType fringe;
ObjType obj;
RoofType roof;
};
NOTE: MapStruct is the main structure, i.e. instead of having DATA as
type int, it should be type MapStruct. Sooooo, the problem becomes
this: When you use the [] operator, how can I make it so that I know
what field to access?? I.e. what I would ideally like to be able to
do is to say:
AMap[40][2].base.tileno = 5; or something similar.
--Jeff W.
"The finding of DMT in normal human body fluids
opens up interesting moral and legal questions.
Since DMT is illegal, as is 'any substance, compound
or mixture' containing DMT, it would seem that we
are all guilty of possesion of a controlled substance"
-Jonathon Ott
My weird, trippy page:
http://www.geocities.com/SunsetStrip/Alley/3450/index.html
- Raw text -