2023-07-10 00:29:21 +00:00
|
|
|
#ifndef BBGE_TILESET_H
|
|
|
|
#define BBGE_TILESET_H
|
|
|
|
|
|
|
|
#include "Vector.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "Texture.h"
|
|
|
|
|
|
|
|
class ElementTemplate
|
|
|
|
{
|
|
|
|
public:
|
2023-07-14 02:25:59 +00:00
|
|
|
ElementTemplate() { w=0; h=0; idx=-1; tu1=tv1=0; tu2=tv2=1; texcoordQuadPtr=NULL; }
|
2023-07-10 00:29:21 +00:00
|
|
|
inline bool operator<(const ElementTemplate& o) const { return idx < o.idx; }
|
|
|
|
|
2023-07-14 02:25:59 +00:00
|
|
|
void finalize(); // call after settings params
|
2023-07-10 00:29:21 +00:00
|
|
|
|
|
|
|
// lazily assigned when tex is loaded
|
2023-07-13 22:19:33 +00:00
|
|
|
CountedPtr<Texture> tex; // NULL if failed to load or not yet loaded
|
2023-07-11 20:30:28 +00:00
|
|
|
float w,h; // custom size if used, otherwise texture size
|
2023-07-14 02:25:59 +00:00
|
|
|
const float *texcoordQuadPtr;
|
|
|
|
float texcoordQuadBuffer[8];
|
2023-07-10 00:29:21 +00:00
|
|
|
|
|
|
|
// fixed
|
|
|
|
float tu1, tu2, tv1, tv2; // texcoords
|
|
|
|
size_t idx;
|
|
|
|
std::string gfx;
|
2023-07-13 22:19:33 +00:00
|
|
|
|
2023-07-14 02:25:59 +00:00
|
|
|
private:
|
|
|
|
ElementTemplate(const ElementTemplate&); // no copy
|
2023-07-10 00:29:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Tileset
|
|
|
|
{
|
|
|
|
public:
|
2023-07-13 22:19:33 +00:00
|
|
|
Tileset();
|
|
|
|
~Tileset();
|
|
|
|
|
2023-07-10 00:29:21 +00:00
|
|
|
// pass usedIdx == NULL to preload all textures from tileset
|
|
|
|
// pass usedIdx != NULL to preload only textures where usedIdx[i] != 0
|
|
|
|
bool loadFile(const char *fn, const unsigned char *usedIdx, size_t usedIdxLen);
|
|
|
|
void clear();
|
|
|
|
|
2023-07-13 22:19:33 +00:00
|
|
|
// return valid ET if found, or creates a dummy if not. never returns NULL.
|
|
|
|
const ElementTemplate *getByIdx(size_t idx);
|
|
|
|
|
|
|
|
// search for non-dummy ET in a given direction. used to cycle through ETs.
|
|
|
|
// never returns dummy ET. May return NULL.
|
|
|
|
const ElementTemplate *getAdjacent(size_t idx, int direction, bool wraparound);
|
2023-07-10 00:29:21 +00:00
|
|
|
|
2023-07-14 02:25:59 +00:00
|
|
|
std::vector<ElementTemplate*> elementTemplates;
|
2023-07-13 22:19:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ElementTemplate *_getAdjacent(size_t idx, int direction, bool wraparound);
|
|
|
|
|
|
|
|
std::vector<ElementTemplate*> dummies;
|
2023-07-10 00:29:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|