summaryrefslogtreecommitdiff
path: root/sprite.h
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-11-14 18:18:28 +0000
committerdarkvater <darkvater@openttd.org>2004-11-14 18:18:28 +0000
commit183c33931d95f13c95882cd7a9300678efef97cb (patch)
tree1ea88e661641af45692ac47a290cc8e5ec186630 /sprite.h
parenta348f74c65495651424975bb8ad0ffe1704b7013 (diff)
downloadopenttd-183c33931d95f13c95882cd7a9300678efef97cb.tar.xz
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
Diffstat (limited to 'sprite.h')
-rw-r--r--sprite.h78
1 files changed, 76 insertions, 2 deletions
diff --git a/sprite.h b/sprite.h
index 5310d3bcb..13660a7d8 100644
--- a/sprite.h
+++ b/sprite.h
@@ -7,7 +7,7 @@
* depots or stations): */
typedef struct DrawTileSeqStruct {
- int8 delta_x;
+ int8 delta_x; // 0x80 is sequence terminator
int8 delta_y;
int8 delta_z;
byte width,height;
@@ -20,12 +20,16 @@ typedef struct DrawTileSprites {
DrawTileSeqStruct const *seq;
} DrawTileSprites;
+// Iterate through all DrawTileSeqStructs in DrawTileSprites.
#define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++)
/* This is for custom sprites: */
-struct SpriteGroup {
+
+struct SpriteGroup;
+
+struct RealSpriteGroup {
// XXX: Would anyone ever need more than 16 spritesets? Maybe we should
// use even less, now we take whole 8kb for custom sprites table, oh my!
byte sprites_per_set; // means number of directions - 4 or 8
@@ -43,4 +47,74 @@ struct SpriteGroup {
uint16 loading[16]; // sprite ids
};
+/* Shared by deterministic and random groups. */
+enum VarSpriteGroupScope {
+ VSG_SCOPE_SELF,
+ // Engine of consists for vehicles, city for stations.
+ VSG_SCOPE_PARENT,
+};
+
+struct DeterministicSpriteGroupRanges;
+
+struct DeterministicSpriteGroup {
+ // Take this variable:
+ enum VarSpriteGroupScope var_scope;
+ byte variable;
+
+ // Do this with it:
+ byte shift_num;
+ byte and_mask;
+
+ // Then do this with it:
+ enum DeterministicSpriteGroupOperation {
+ DSG_OP_NONE,
+ DSG_OP_DIV,
+ DSG_OP_MOD,
+ } operation;
+ byte add_val;
+ byte divmod_val;
+
+ // And apply it to this:
+ byte num_ranges;
+ struct DeterministicSpriteGroupRanges *ranges; // Dynamically allocated
+
+ // Dynamically allocated, this is the sole owner
+ struct SpriteGroup *default_group;
+};
+
+struct SpriteGroup {
+ enum SpriteGroupType {
+ SGT_REAL,
+ SGT_DETERMINISTIC,
+ SGT_RANDOM, /* TODO */
+ } type;
+
+ union {
+ struct RealSpriteGroup real;
+ struct DeterministicSpriteGroup determ;
+ } g;
+};
+
+struct DeterministicSpriteGroupRanges {
+ struct SpriteGroup group;
+ byte range_low;
+ byte range_high;
+};
+
+/* This is a temporary helper for SpriteGroup users not supporting variational
+ * sprite groups yet - it just traverses those cowardly, always taking the
+ * default choice until it hits a real sprite group, returning it. */
+static struct RealSpriteGroup *TriviallyGetRSG(struct SpriteGroup *sg);
+
+
+
+/**** Inline functions ****/
+
+static INLINE struct RealSpriteGroup *TriviallyGetRSG(struct SpriteGroup *sg)
+{
+ if (sg->type == SGT_REAL)
+ return &sg->g.real;
+ return TriviallyGetRSG(sg->g.determ.default_group);
+}
+
#endif