author | peter1138 |
Fri, 14 Oct 2005 20:10:12 +0000 | |
changeset 2515 | 673474334b9e |
parent 2491 | 15a117630a4f |
child 3593 | 7ec7431c7a94 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1477
diff
changeset
|
4 |
#include "openttd.h" |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
5 |
#include "sprite.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
1891
diff
changeset
|
6 |
#include "variables.h" |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
7 |
#include "debug.h" |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
8 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
9 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2186
diff
changeset
|
10 |
SpriteGroup *EvalDeterministicSpriteGroup(const DeterministicSpriteGroup *dsg, int value) |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
11 |
{ |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
12 |
int i; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
13 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
14 |
value >>= dsg->shift_num; // This should bring us to the byte range. |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
15 |
value &= dsg->and_mask; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
16 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
17 |
if (dsg->operation != DSG_OP_NONE) |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
18 |
value += (signed char) dsg->add_val; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
19 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
20 |
switch (dsg->operation) { |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
21 |
case DSG_OP_DIV: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
22 |
value /= (signed char) dsg->divmod_val; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
23 |
break; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
24 |
case DSG_OP_MOD: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
25 |
value %= (signed char) dsg->divmod_val; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
26 |
break; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
27 |
case DSG_OP_NONE: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
28 |
break; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
29 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
30 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
31 |
for (i = 0; i < dsg->num_ranges; i++) { |
1477 | 32 |
DeterministicSpriteGroupRange *range = &dsg->ranges[i]; |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
33 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
34 |
if (range->low <= value && value <= range->high) |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2282
diff
changeset
|
35 |
return range->group; |
414
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
36 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
37 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
38 |
return dsg->default_group; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
39 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
40 |
|
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
41 |
int GetDeterministicSpriteValue(byte var) |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
42 |
{ |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
43 |
switch (var) { |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
44 |
case 0x00: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
45 |
return _date; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
46 |
case 0x01: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
47 |
return _cur_year; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
48 |
case 0x02: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
49 |
return _cur_month; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
50 |
case 0x03: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
51 |
return _opt.landscape; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
52 |
case 0x09: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
53 |
return _date_fract; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
54 |
case 0x0A: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
55 |
return _tick_counter; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
56 |
case 0x0C: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
57 |
/* If we got here, it means there was no callback or |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
58 |
* callbacks aren't supported on our callpath. */ |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
59 |
return 0; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
60 |
default: |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
61 |
return -1; |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
62 |
} |
4629d4bf7f14
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
413
diff
changeset
|
63 |
} |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
64 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2186
diff
changeset
|
65 |
SpriteGroup *EvalRandomizedSpriteGroup(const RandomizedSpriteGroup *rsg, byte random_bits) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
66 |
{ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
67 |
byte mask; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
68 |
byte index; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
69 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
70 |
/* Noone likes mangling with bits, but you don't get around it here. |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
71 |
* Sorry. --pasky */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
72 |
// rsg->num_groups is always power of 2 |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
73 |
mask = (rsg->num_groups - 1) << rsg->lowest_randbit; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
74 |
index = (random_bits & mask) >> rsg->lowest_randbit; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
75 |
assert(index < rsg->num_groups); |
2488
1e98c71e5f6a
(svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents:
2282
diff
changeset
|
76 |
return rsg->groups[index]; |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
77 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
78 |
|
2242
512eae2cf006
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2186
diff
changeset
|
79 |
byte RandomizedSpriteGroupTriggeredBits(const RandomizedSpriteGroup *rsg, |
1477 | 80 |
byte triggers, byte *waiting_triggers) |
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
81 |
{ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
82 |
byte match = rsg->triggers & (*waiting_triggers | triggers); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
83 |
bool res; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
84 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
85 |
if (rsg->cmp_mode == RSG_CMP_ANY) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
86 |
res = (match != 0); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
87 |
} else { /* RSG_CMP_ALL */ |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
88 |
res = (match == rsg->triggers); |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
89 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
90 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
91 |
if (!res) { |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
92 |
*waiting_triggers |= triggers; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
93 |
return 0; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
94 |
} |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
95 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
96 |
*waiting_triggers &= ~match; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
97 |
|
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
98 |
return (rsg->num_groups - 1) << rsg->lowest_randbit; |
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
414
diff
changeset
|
99 |
} |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
100 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
101 |
/** |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
102 |
* Traverse a sprite group and release its and its child's memory. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
103 |
* A group is only released if its reference count is zero. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
104 |
* We pass a pointer to a pointer so that the original reference can be set to NULL. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
105 |
* @param group_ptr Pointer to sprite group reference. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
106 |
*/ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
107 |
void UnloadSpriteGroup(SpriteGroup **group_ptr) |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
108 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
109 |
SpriteGroup *group; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
110 |
int i; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
111 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
112 |
assert(group_ptr != NULL); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
113 |
assert(*group_ptr != NULL); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
114 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
115 |
group = *group_ptr; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
116 |
*group_ptr = NULL; // Remove this reference. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
117 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
118 |
group->ref_count--; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
119 |
if (group->ref_count > 0) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
120 |
DEBUG(grf, 6)("UnloadSpriteGroup: Group at `%p' (type %d) has %d reference(s) left.", group, group->type, group->ref_count); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
121 |
return; // Still some references left, so don't clear up. |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
122 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
123 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
124 |
DEBUG(grf, 6)("UnloadSpriteGroup: Releasing group at `%p'.", group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
125 |
switch (group->type) { |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
126 |
case SGT_REAL: |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
127 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
128 |
RealSpriteGroup *rsg = &group->g.real; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
129 |
for (i = 0; i < rsg->loading_count; i++) { |
2515
673474334b9e
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents:
2491
diff
changeset
|
130 |
if (rsg->loading[i] != NULL) UnloadSpriteGroup(&rsg->loading[i]); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
131 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
132 |
for (i = 0; i < rsg->loaded_count; i++) { |
2515
673474334b9e
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents:
2491
diff
changeset
|
133 |
if (rsg->loaded[i] != NULL) UnloadSpriteGroup(&rsg->loaded[i]); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
134 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
135 |
free(group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
136 |
return; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
137 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
138 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
139 |
case SGT_DETERMINISTIC: |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
140 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
141 |
DeterministicSpriteGroup *dsg = &group->g.determ; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
142 |
for (i = 0; i < group->g.determ.num_ranges; i++) { |
2515
673474334b9e
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents:
2491
diff
changeset
|
143 |
if (dsg->ranges[i].group != NULL) UnloadSpriteGroup(&dsg->ranges[i].group); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
144 |
} |
2515
673474334b9e
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents:
2491
diff
changeset
|
145 |
if (dsg->default_group != NULL) UnloadSpriteGroup(&dsg->default_group); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
146 |
free(group->g.determ.ranges); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
147 |
free(group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
148 |
return; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
149 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
150 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
151 |
case SGT_RANDOMIZED: |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
152 |
{ |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
153 |
for (i = 0; i < group->g.random.num_groups; i++) { |
2515
673474334b9e
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
peter1138
parents:
2491
diff
changeset
|
154 |
if (group->g.random.groups[i] != NULL) UnloadSpriteGroup(&group->g.random.groups[i]); |
2491
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
155 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
156 |
free(group->g.random.groups); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
157 |
free(group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
158 |
return; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
159 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
160 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
161 |
case SGT_CALLBACK: |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
162 |
case SGT_RESULT: |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
163 |
free(group); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
164 |
return; |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
165 |
} |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
166 |
|
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
167 |
DEBUG(grf, 1)("Unable to remove unknown sprite group type `0x%x'.", group->type); |
15a117630a4f
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents:
2488
diff
changeset
|
168 |
} |