sprite.h
changeset 1477 2174a73b11c9
parent 915 013cb2d74800
child 1883 3b02000cfbe0
equal deleted inserted replaced
1476:abbcea18a01c 1477:2174a73b11c9
    25 
    25 
    26 
    26 
    27 /* This is for custom sprites: */
    27 /* This is for custom sprites: */
    28 
    28 
    29 
    29 
    30 struct SpriteGroup;
    30 typedef struct SpriteGroup SpriteGroup;
    31 
    31 
    32 struct RealSpriteGroup {
    32 typedef struct RealSpriteGroup {
    33 	// XXX: Would anyone ever need more than 16 spritesets? Maybe we should
    33 	// XXX: Would anyone ever need more than 16 spritesets? Maybe we should
    34 	// use even less, now we take whole 8kb for custom sprites table, oh my!
    34 	// use even less, now we take whole 8kb for custom sprites table, oh my!
    35 	byte sprites_per_set; // means number of directions - 4 or 8
    35 	byte sprites_per_set; // means number of directions - 4 or 8
    36 
    36 
    37 	// Loaded = in motion, loading = not moving
    37 	// Loaded = in motion, loading = not moving
    43 
    43 
    44 	byte loaded_count;
    44 	byte loaded_count;
    45 	uint16 loaded[16]; // sprite ids
    45 	uint16 loaded[16]; // sprite ids
    46 	byte loading_count;
    46 	byte loading_count;
    47 	uint16 loading[16]; // sprite ids
    47 	uint16 loading[16]; // sprite ids
    48 };
    48 } RealSpriteGroup;
    49 
    49 
    50 /* Shared by deterministic and random groups. */
    50 /* Shared by deterministic and random groups. */
    51 enum VarSpriteGroupScope {
    51 typedef enum VarSpriteGroupScope {
    52 	VSG_SCOPE_SELF,
    52 	VSG_SCOPE_SELF,
    53 	// Engine of consists for vehicles, city for stations.
    53 	// Engine of consists for vehicles, city for stations.
    54 	VSG_SCOPE_PARENT,
    54 	VSG_SCOPE_PARENT,
    55 };
    55 } VarSpriteGroupScope;
    56 
    56 
    57 struct DeterministicSpriteGroupRanges;
    57 typedef struct DeterministicSpriteGroupRanges DeterministicSpriteGroupRanges;
    58 
    58 
    59 struct DeterministicSpriteGroup {
    59 typedef enum DeterministicSpriteGroupOperation {
       
    60 	DSG_OP_NONE,
       
    61 	DSG_OP_DIV,
       
    62 	DSG_OP_MOD,
       
    63 } DeterministicSpriteGroupOperation;
       
    64 
       
    65 typedef struct DeterministicSpriteGroupRange DeterministicSpriteGroupRange;
       
    66 
       
    67 typedef struct DeterministicSpriteGroup {
    60 	// Take this variable:
    68 	// Take this variable:
    61 	enum VarSpriteGroupScope var_scope;
    69 	VarSpriteGroupScope var_scope;
    62 	byte variable;
    70 	byte variable;
    63 
    71 
    64 	// Do this with it:
    72 	// Do this with it:
    65 	byte shift_num;
    73 	byte shift_num;
    66 	byte and_mask;
    74 	byte and_mask;
    67 
    75 
    68 	// Then do this with it:
    76 	// Then do this with it:
    69 	enum DeterministicSpriteGroupOperation {
    77 	DeterministicSpriteGroupOperation operation;
    70 		DSG_OP_NONE,
       
    71 		DSG_OP_DIV,
       
    72 		DSG_OP_MOD,
       
    73 	} operation;
       
    74 	byte add_val;
    78 	byte add_val;
    75 	byte divmod_val;
    79 	byte divmod_val;
    76 
    80 
    77 	// And apply it to this:
    81 	// And apply it to this:
    78 	byte num_ranges;
    82 	byte num_ranges;
    79 	struct DeterministicSpriteGroupRange *ranges; // Dynamically allocated
    83 	DeterministicSpriteGroupRange *ranges; // Dynamically allocated
    80 
    84 
    81 	// Dynamically allocated, this is the sole owner
    85 	// Dynamically allocated, this is the sole owner
    82 	struct SpriteGroup *default_group;
    86 	SpriteGroup *default_group;
    83 };
    87 } DeterministicSpriteGroup;
    84 
    88 
    85 struct RandomizedSpriteGroup {
    89 typedef enum RandomizedSpriteGroupCompareMode {
       
    90 	RSG_CMP_ANY,
       
    91 	RSG_CMP_ALL,
       
    92 } RandomizedSpriteGroupCompareMode;
       
    93 
       
    94 typedef struct RandomizedSpriteGroup {
    86 	// Take this object:
    95 	// Take this object:
    87 	enum VarSpriteGroupScope var_scope;
    96 	VarSpriteGroupScope var_scope;
    88 
    97 
    89 	// Check for these triggers:
    98 	// Check for these triggers:
    90 	enum RandomizedSpriteGroupCompareMode {
    99 	RandomizedSpriteGroupCompareMode cmp_mode;
    91 		RSG_CMP_ANY,
       
    92 		RSG_CMP_ALL,
       
    93 	} cmp_mode;
       
    94 	byte triggers;
   100 	byte triggers;
    95 
   101 
    96 	// Look for this in the per-object randomized bitmask:
   102 	// Look for this in the per-object randomized bitmask:
    97 	byte lowest_randbit;
   103 	byte lowest_randbit;
    98 	byte num_groups; // must be power of 2
   104 	byte num_groups; // must be power of 2
    99 
   105 
   100 	// Take the group with appropriate index:
   106 	// Take the group with appropriate index:
   101 	struct SpriteGroup *groups;
   107 	SpriteGroup *groups;
   102 };
   108 } RandomizedSpriteGroup;
       
   109 
       
   110 typedef enum SpriteGroupType {
       
   111 	SGT_REAL,
       
   112 	SGT_DETERMINISTIC,
       
   113 	SGT_RANDOMIZED,
       
   114 } SpriteGroupType;
   103 
   115 
   104 struct SpriteGroup {
   116 struct SpriteGroup {
   105 	enum SpriteGroupType {
   117 	SpriteGroupType type;
   106 		SGT_REAL,
       
   107 		SGT_DETERMINISTIC,
       
   108 		SGT_RANDOMIZED,
       
   109 	} type;
       
   110 
   118 
   111 	union {
   119 	union {
   112 		struct RealSpriteGroup real;
   120 		RealSpriteGroup real;
   113 		struct DeterministicSpriteGroup determ;
   121 		DeterministicSpriteGroup determ;
   114 		struct RandomizedSpriteGroup random;
   122 		RandomizedSpriteGroup random;
   115 	} g;
   123 	} g;
   116 };
   124 };
   117 
   125 
   118 struct DeterministicSpriteGroupRange {
   126 struct DeterministicSpriteGroupRange {
   119 	struct SpriteGroup group;
   127 	SpriteGroup group;
   120 	byte low;
   128 	byte low;
   121 	byte high;
   129 	byte high;
   122 };
   130 };
   123 
   131 
   124 /* This takes value (probably of the variable specified in the group) and
   132 /* This takes value (probably of the variable specified in the group) and
   129 int GetDeterministicSpriteValue(byte var);
   137 int GetDeterministicSpriteValue(byte var);
   130 
   138 
   131 /* This takes randomized bitmask (probably associated with
   139 /* This takes randomized bitmask (probably associated with
   132  * vehicle/station/whatever) and chooses corresponding SpriteGroup
   140  * vehicle/station/whatever) and chooses corresponding SpriteGroup
   133  * accordingly to the given RandomizedSpriteGroup. */
   141  * accordingly to the given RandomizedSpriteGroup. */
   134 struct SpriteGroup *EvalRandomizedSpriteGroup(struct RandomizedSpriteGroup *rsg, byte random_bits);
   142 SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits);
   135 /* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask
   143 /* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask
   136  * of random bits to be reseeded, or zero if there were no triggers matched
   144  * of random bits to be reseeded, or zero if there were no triggers matched
   137  * (then they are |ed to @waiting_triggers instead). */
   145  * (then they are |ed to @waiting_triggers instead). */
   138 byte RandomizedSpriteGroupTriggeredBits(struct RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);
   146 byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);
   139 
   147 
   140 #endif
   148 #endif