Files @ r3303:1bae0f5399a4
Branch filter:

Location: cpp/openttd-patchpack/source/sprite.h - annotation

bjarni
(svn r4060) -Codechange: [OSX] made the release target (in os/macosx/Makefile) easier to use since it gives the release disk image the right name automatically
it now uses REV instead of RELEASE, which means RELEASE is not needed to be set manaully anymore
it also automatically adds "-jaguar" when making a build aimed at OSX 10.2 (codenamed jaguar)
r2186:5ee653b1b5e1
r2186:5ee653b1b5e1
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r408:e003dfb10972
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r2548:9570bbbdacab
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r408:e003dfb10972
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r1477:d0fe35adb3c4
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r406:4f7c55e23b9d
r2489:54c5b175f0bf
r406:4f7c55e23b9d
r2489:54c5b175f0bf
r1477:d0fe35adb3c4
r406:4f7c55e23b9d
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r2445:3a017cc5a697
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r408:e003dfb10972
r915:dabba47e3ed1
r408:e003dfb10972
r408:e003dfb10972
r1477:d0fe35adb3c4
r408:e003dfb10972
r408:e003dfb10972
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r408:e003dfb10972
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r445:8bbc3f73289f
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r2488:f9a2e7b1def4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r2489:54c5b175f0bf
r2489:54c5b175f0bf
r2489:54c5b175f0bf
r2489:54c5b175f0bf
r2489:54c5b175f0bf
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1883:9315515934d3
r2489:54c5b175f0bf
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r408:e003dfb10972
r1477:d0fe35adb3c4
r2490:4a9082968d2a
r408:e003dfb10972
r408:e003dfb10972
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r1883:9315515934d3
r2489:54c5b175f0bf
r408:e003dfb10972
r408:e003dfb10972
r408:e003dfb10972
r413:89e9c32c6b72
r2488:f9a2e7b1def4
r413:89e9c32c6b72
r413:89e9c32c6b72
r408:e003dfb10972
r408:e003dfb10972
r413:89e9c32c6b72
r413:89e9c32c6b72
r413:89e9c32c6b72
r2242:397d3342628f
r413:89e9c32c6b72
r413:89e9c32c6b72
r408:e003dfb10972
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r2242:397d3342628f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r2242:397d3342628f
r445:8bbc3f73289f
r2491:13bebed6ca4e
r2491:13bebed6ca4e
r2436:963efe8b84cc
/* $Id$ */

#ifndef SPRITE_H
#define SPRITE_H


/* The following describes bunch of sprites to be drawn together in a single 3D
 * bounding box. Used especially for various multi-sprite buildings (like
 * depots or stations): */

typedef struct DrawTileSeqStruct {
	int8 delta_x; // 0x80 is sequence terminator
	int8 delta_y;
	int8 delta_z;
	byte width,height;
	byte unk; // 'depth', just z-size; TODO: rename
	uint32 image;
} DrawTileSeqStruct;

typedef struct DrawTileSprites {
	SpriteID ground_sprite;
	const DrawTileSeqStruct* 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: */


typedef struct SpriteGroup SpriteGroup;

typedef 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

	// Loaded = in motion, loading = not moving
	// Each group contains several spritesets, for various loading stages

	// XXX: For stations the meaning is different - loaded is for stations
	// with small amount of cargo whilst loading is for stations with a lot
	// of da stuff.

	byte loaded_count;
	SpriteGroup *loaded[16]; // sprite ids
	byte loading_count;
	SpriteGroup *loading[16]; // sprite ids
} RealSpriteGroup;

/* Shared by deterministic and random groups. */
typedef enum VarSpriteGroupScope {
	VSG_SCOPE_SELF,
	// Engine of consists for vehicles, city for stations.
	VSG_SCOPE_PARENT,
} VarSpriteGroupScope;

typedef struct DeterministicSpriteGroupRanges DeterministicSpriteGroupRanges;

typedef enum DeterministicSpriteGroupOperation {
	DSG_OP_NONE,
	DSG_OP_DIV,
	DSG_OP_MOD,
} DeterministicSpriteGroupOperation;

typedef struct DeterministicSpriteGroupRange DeterministicSpriteGroupRange;

typedef struct DeterministicSpriteGroup {
	// Take this variable:
	VarSpriteGroupScope var_scope;
	byte variable;
	byte parameter; ///< Used for variables between 0x60 and 0x7F inclusive.

	// Do this with it:
	byte shift_num;
	byte and_mask;

	// Then do this with it:
	DeterministicSpriteGroupOperation operation;
	byte add_val;
	byte divmod_val;

	// And apply it to this:
	byte num_ranges;
	DeterministicSpriteGroupRange *ranges; // Dynamically allocated

	// Dynamically allocated, this is the sole owner
	SpriteGroup *default_group;
} DeterministicSpriteGroup;

typedef enum RandomizedSpriteGroupCompareMode {
	RSG_CMP_ANY,
	RSG_CMP_ALL,
} RandomizedSpriteGroupCompareMode;

typedef struct RandomizedSpriteGroup {
	// Take this object:
	VarSpriteGroupScope var_scope;

	// Check for these triggers:
	RandomizedSpriteGroupCompareMode cmp_mode;
	byte triggers;

	// Look for this in the per-object randomized bitmask:
	byte lowest_randbit;
	byte num_groups; // must be power of 2

	// Take the group with appropriate index:
	SpriteGroup **groups;
} RandomizedSpriteGroup;

typedef struct CallbackResultSpriteGroup {
	uint16 result;
} CallbackResultSpriteGroup;

typedef struct ResultSpriteGroup {
	uint16 result;
	byte sprites;
} ResultSpriteGroup;

typedef enum SpriteGroupType {
	SGT_REAL,
	SGT_DETERMINISTIC,
	SGT_RANDOMIZED,
	SGT_CALLBACK,
	SGT_RESULT,
} SpriteGroupType;

struct SpriteGroup {
	SpriteGroupType type;
	byte ref_count;

	union {
		RealSpriteGroup real;
		DeterministicSpriteGroup determ;
		RandomizedSpriteGroup random;
		CallbackResultSpriteGroup callback;
		ResultSpriteGroup result;
	} g;
};

struct DeterministicSpriteGroupRange {
	SpriteGroup *group;
	byte low;
	byte high;
};

/* This takes value (probably of the variable specified in the group) and
 * chooses corresponding SpriteGroup accordingly to the given
 * DeterministicSpriteGroup. */
SpriteGroup *EvalDeterministicSpriteGroup(const DeterministicSpriteGroup *dsg, int value);
/* Get value of a common deterministic SpriteGroup variable. */
int GetDeterministicSpriteValue(byte var);

/* This takes randomized bitmask (probably associated with
 * vehicle/station/whatever) and chooses corresponding SpriteGroup
 * accordingly to the given RandomizedSpriteGroup. */
SpriteGroup *EvalRandomizedSpriteGroup(const RandomizedSpriteGroup *rsg, byte random_bits);
/* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask
 * of random bits to be reseeded, or zero if there were no triggers matched
 * (then they are |ed to @waiting_triggers instead). */
byte RandomizedSpriteGroupTriggeredBits(const RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);

void UnloadSpriteGroup(SpriteGroup **group_ptr);

#endif /* SPRITE_H */