mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
Simplify metatile attribute layouts
This commit is contained in:
@@ -30,6 +30,29 @@ enum {
|
||||
NUM_METATILE_TERRAIN_TYPES
|
||||
};
|
||||
|
||||
class MetatileAttr
|
||||
{
|
||||
public:
|
||||
MetatileAttr();
|
||||
MetatileAttr(uint32_t mask, int shift);
|
||||
|
||||
public:
|
||||
uint32_t mask;
|
||||
int shift;
|
||||
|
||||
// Given the raw value for all attributes of a metatile
|
||||
// Returns the extracted value for this attribute
|
||||
uint32_t fromRaw(uint32_t raw) const { return (raw & this->mask) >> this->shift; }
|
||||
|
||||
// Given a value for this attribute
|
||||
// Returns the raw value to OR together with the other attributes
|
||||
uint32_t toRaw(uint32_t value) const { return (value << this->shift) & this->mask; }
|
||||
|
||||
// Given an arbitrary value to set for an attribute
|
||||
// Returns a bounded value for that attribute
|
||||
uint32_t getClamped(int value) const { return static_cast<uint32_t>(value) & (this->mask >> this->shift); }
|
||||
};
|
||||
|
||||
class Metatile
|
||||
{
|
||||
public:
|
||||
@@ -47,30 +70,23 @@ public:
|
||||
uint32_t unusedAttributes;
|
||||
QString label;
|
||||
|
||||
enum Attr {
|
||||
Behavior,
|
||||
TerrainType,
|
||||
EncounterType,
|
||||
LayerType,
|
||||
};
|
||||
|
||||
struct AttrLayout {
|
||||
uint32_t mask;
|
||||
int shift;
|
||||
};
|
||||
|
||||
static const QHash<Metatile::Attr, Metatile::AttrLayout> defaultLayoutFRLG;
|
||||
static const QHash<Metatile::Attr, Metatile::AttrLayout> defaultLayoutRSE;
|
||||
static QHash<Metatile::Attr, Metatile::AttrLayout> customLayout;
|
||||
|
||||
uint32_t getAttributes();
|
||||
void setAttributes(uint32_t data);
|
||||
void convertAttributes(uint32_t data, BaseGameVersion version);
|
||||
void setAttributes(uint32_t data, BaseGameVersion version);
|
||||
|
||||
void setBehavior(uint32_t);
|
||||
void setTerrainType(uint32_t);
|
||||
void setEncounterType(uint32_t);
|
||||
void setLayerType(uint32_t);
|
||||
void setBehavior(int value) { this->behavior = behaviorAttr.getClamped(value); }
|
||||
void setTerrainType(int value) { this->terrainType = terrainTypeAttr.getClamped(value); }
|
||||
void setEncounterType(int value) { this->encounterType = encounterTypeAttr.getClamped(value); }
|
||||
void setLayerType(int value) { this->layerType = layerTypeAttr.getClamped(value); }
|
||||
|
||||
static uint32_t getBehaviorMask() { return behaviorAttr.mask; }
|
||||
static uint32_t getTerrainTypeMask() { return terrainTypeAttr.mask; }
|
||||
static uint32_t getEncounterTypeMask() { return encounterTypeAttr.mask; }
|
||||
static uint32_t getLayerTypeMask() { return layerTypeAttr.mask; }
|
||||
static uint32_t getBehaviorMask(BaseGameVersion version);
|
||||
static uint32_t getTerrainTypeMask(BaseGameVersion version);
|
||||
static uint32_t getEncounterTypeMask(BaseGameVersion version);
|
||||
static uint32_t getLayerTypeMask(BaseGameVersion version);
|
||||
|
||||
static int getIndexInTileset(int);
|
||||
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
||||
@@ -78,11 +94,22 @@ public:
|
||||
static void setCustomLayout();
|
||||
|
||||
private:
|
||||
// Stores how each attribute should be laid out for all metatiles, according to the user's config
|
||||
static MetatileAttr behaviorAttr;
|
||||
static MetatileAttr terrainTypeAttr;
|
||||
static MetatileAttr encounterTypeAttr;
|
||||
static MetatileAttr layerTypeAttr;
|
||||
|
||||
static uint32_t unusedAttrMask;
|
||||
|
||||
void setAttributes(uint32_t, const QHash<Metatile::Attr, Metatile::AttrLayout>*);
|
||||
static void setCustomAttributeLayout(Metatile::AttrLayout *, uint32_t, uint32_t);
|
||||
static bool isMaskTooSmall(Metatile::AttrLayout * layout, int n);
|
||||
// Stores how each attribute should be laid out for all metatiles, according to the vanilla games
|
||||
// Used to set default config values and import maps with AdvanceMap
|
||||
static const QHash<QString, MetatileAttr> defaultLayoutFRLG;
|
||||
static const QHash<QString, MetatileAttr> defaultLayoutRSE;
|
||||
static const QHash<BaseGameVersion, const QHash<QString, MetatileAttr>*> defaultLayouts;
|
||||
|
||||
static void setCustomAttributeLayout(MetatileAttr *, uint32_t, uint32_t);
|
||||
static bool isMaskTooSmall(MetatileAttr *, int);
|
||||
static bool doMasksOverlap(QList<uint32_t>);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user