4 #define NEWGRF_SPRITEGROUP_H |
4 #define NEWGRF_SPRITEGROUP_H |
5 |
5 |
6 |
6 |
7 typedef struct SpriteGroup SpriteGroup; |
7 typedef struct SpriteGroup SpriteGroup; |
8 |
8 |
|
9 |
|
10 /* 'Real' sprite groups contain a list of other result or callback sprite |
|
11 * groups. */ |
9 typedef struct RealSpriteGroup { |
12 typedef struct RealSpriteGroup { |
10 byte sprites_per_set; // means number of directions - 4 or 8 |
|
11 |
|
12 // Loaded = in motion, loading = not moving |
13 // Loaded = in motion, loading = not moving |
13 // Each group contains several spritesets, for various loading stages |
14 // Each group contains several spritesets, for various loading stages |
14 |
15 |
15 // XXX: For stations the meaning is different - loaded is for stations |
16 // XXX: For stations the meaning is different - loaded is for stations |
16 // with small amount of cargo whilst loading is for stations with a lot |
17 // with small amount of cargo whilst loading is for stations with a lot |
17 // of da stuff. |
18 // of da stuff. |
18 |
19 |
19 byte loaded_count; ///< Number of loaded groups |
20 byte num_loaded; ///< Number of loaded groups |
|
21 byte num_loading; ///< Number of loading groups |
20 SpriteGroup **loaded; ///< List of loaded groups (can be SpriteIDs or Callback results) |
22 SpriteGroup **loaded; ///< List of loaded groups (can be SpriteIDs or Callback results) |
21 byte loading_count; ///< Number of loading groups |
|
22 SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results) |
23 SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results) |
23 } RealSpriteGroup; |
24 } RealSpriteGroup; |
24 |
25 |
25 /* Shared by deterministic and random groups. */ |
26 /* Shared by deterministic and random groups. */ |
26 typedef enum VarSpriteGroupScope { |
27 typedef enum VarSpriteGroupScopes { |
27 VSG_SCOPE_SELF, |
28 VSG_SCOPE_SELF, |
28 // Engine of consists for vehicles, city for stations. |
29 // Engine of consists for vehicles, city for stations. |
29 VSG_SCOPE_PARENT, |
30 VSG_SCOPE_PARENT, |
30 } VarSpriteGroupScope; |
31 } VarSpriteGroupScope; |
31 |
32 |
32 typedef struct DeterministicSpriteGroupRanges DeterministicSpriteGroupRanges; |
33 typedef enum DeterministicSpriteGroupSizes { |
|
34 DSG_SIZE_BYTE, |
|
35 DSG_SIZE_WORD, |
|
36 DSG_SIZE_DWORD, |
|
37 } DeterministicSpriteGroupSize; |
33 |
38 |
34 typedef enum DeterministicSpriteGroupOperation { |
39 typedef enum DeterministicSpriteGroupAdjustTypes { |
35 DSG_OP_NONE, |
40 DSGA_TYPE_NONE, |
36 DSG_OP_DIV, |
41 DSGA_TYPE_DIV, |
37 DSG_OP_MOD, |
42 DSGA_TYPE_MOD, |
38 } DeterministicSpriteGroupOperation; |
43 } DeterministicSpriteGroupAdjustType; |
39 |
44 |
40 typedef struct DeterministicSpriteGroupRange DeterministicSpriteGroupRange; |
45 typedef enum DeterministicSpriteGroupAdjustOperations { |
|
46 DSGA_OP_ADD, // a + b |
|
47 DSGA_OP_SUB, // a - b |
|
48 DSGA_OP_SMIN, // (signed) min(a, b) |
|
49 DSGA_OP_SMAX, // (signed) max(a, b) |
|
50 DSGA_OP_UMIN, // (unsigned) min(a, b) |
|
51 DSGA_OP_UMAX, // (unsigned) max(a, b) |
|
52 DSGA_OP_SDIV, // (signed) a / b |
|
53 DSGA_OP_SMOD, // (signed) a % b |
|
54 DSGA_OP_UDIV, // (unsigned) a / b |
|
55 DSGA_OP_UMOD, // (unsigned) a & b |
|
56 DSGA_OP_MUL, // a * b |
|
57 DSGA_OP_AND, // a & b |
|
58 DSGA_OP_OR, // a | b |
|
59 DSGA_OP_XOR, // a ^ b |
|
60 } DeterministicSpriteGroupAdjustOperation; |
|
61 |
|
62 |
|
63 typedef struct DeterministicSpriteGroupAdjust { |
|
64 DeterministicSpriteGroupAdjustOperation operation; |
|
65 DeterministicSpriteGroupAdjustType type; |
|
66 byte variable; |
|
67 byte parameter; ///< Used for variables between 0x60 and 0x7F inclusive. |
|
68 byte shift_num; |
|
69 uint32 and_mask; |
|
70 uint32 add_val; |
|
71 uint32 divmod_val; |
|
72 } DeterministicSpriteGroupAdjust; |
|
73 |
|
74 |
|
75 typedef struct DeterministicSpriteGroupRange { |
|
76 SpriteGroup *group; |
|
77 uint32 low; |
|
78 uint32 high; |
|
79 } DeterministicSpriteGroupRange; |
|
80 |
41 |
81 |
42 typedef struct DeterministicSpriteGroup { |
82 typedef struct DeterministicSpriteGroup { |
43 // Take this variable: |
|
44 VarSpriteGroupScope var_scope; |
83 VarSpriteGroupScope var_scope; |
45 byte variable; |
84 DeterministicSpriteGroupSize size; |
46 byte parameter; ///< Used for variables between 0x60 and 0x7F inclusive. |
85 byte num_adjusts; |
47 |
|
48 // Do this with it: |
|
49 byte shift_num; |
|
50 byte and_mask; |
|
51 |
|
52 // Then do this with it: |
|
53 DeterministicSpriteGroupOperation operation; |
|
54 byte add_val; |
|
55 byte divmod_val; |
|
56 |
|
57 // And apply it to this: |
|
58 byte num_ranges; |
86 byte num_ranges; |
|
87 DeterministicSpriteGroupAdjust *adjusts; |
59 DeterministicSpriteGroupRange *ranges; // Dynamically allocated |
88 DeterministicSpriteGroupRange *ranges; // Dynamically allocated |
60 |
89 |
61 // Dynamically allocated, this is the sole owner |
90 // Dynamically allocated, this is the sole owner |
62 SpriteGroup *default_group; |
91 SpriteGroup *default_group; |
63 } DeterministicSpriteGroup; |
92 } DeterministicSpriteGroup; |
64 |
93 |
65 typedef enum RandomizedSpriteGroupCompareMode { |
94 typedef enum RandomizedSpriteGroupCompareModes { |
66 RSG_CMP_ANY, |
95 RSG_CMP_ANY, |
67 RSG_CMP_ALL, |
96 RSG_CMP_ALL, |
68 } RandomizedSpriteGroupCompareMode; |
97 } RandomizedSpriteGroupCompareMode; |
69 |
98 |
70 typedef struct RandomizedSpriteGroup { |
99 typedef struct RandomizedSpriteGroup { |
81 |
110 |
82 // Take the group with appropriate index: |
111 // Take the group with appropriate index: |
83 SpriteGroup **groups; |
112 SpriteGroup **groups; |
84 } RandomizedSpriteGroup; |
113 } RandomizedSpriteGroup; |
85 |
114 |
|
115 |
|
116 /* This contains a callback result. A failed callback has a value of |
|
117 * CALLBACK_FAILED */ |
86 typedef struct CallbackResultSpriteGroup { |
118 typedef struct CallbackResultSpriteGroup { |
87 uint16 result; |
119 uint16 result; |
88 } CallbackResultSpriteGroup; |
120 } CallbackResultSpriteGroup; |
89 |
121 |
|
122 |
|
123 /* A result sprite group returns the first SpriteID and the number of |
|
124 * sprites in the set */ |
90 typedef struct ResultSpriteGroup { |
125 typedef struct ResultSpriteGroup { |
91 uint16 result; |
126 SpriteID sprite; |
92 byte sprites; |
127 byte num_sprites; |
93 } ResultSpriteGroup; |
128 } ResultSpriteGroup; |
94 |
129 |
|
130 /* List of different sprite group types */ |
95 typedef enum SpriteGroupType { |
131 typedef enum SpriteGroupType { |
96 SGT_INVALID, |
132 SGT_INVALID, |
97 SGT_REAL, |
133 SGT_REAL, |
98 SGT_DETERMINISTIC, |
134 SGT_DETERMINISTIC, |
99 SGT_RANDOMIZED, |
135 SGT_RANDOMIZED, |
100 SGT_CALLBACK, |
136 SGT_CALLBACK, |
101 SGT_RESULT, |
137 SGT_RESULT, |
102 } SpriteGroupType; |
138 } SpriteGroupType; |
103 |
139 |
|
140 /* Common wrapper for all the different sprite group types */ |
104 struct SpriteGroup { |
141 struct SpriteGroup { |
105 SpriteGroupType type; |
142 SpriteGroupType type; |
106 |
143 |
107 union { |
144 union { |
108 RealSpriteGroup real; |
145 RealSpriteGroup real; |