mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r4714) - NewGRF: simplify evaluation of 'real' sprite groups.
This commit is contained in:
parent
9cd88e7153
commit
4ef1033287
|
@ -636,24 +636,22 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint32 VehicleResolveReal(const ResolverObject *object, uint num_loaded, uint num_loading, bool *in_motion)
|
static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const SpriteGroup *group)
|
||||||
{
|
{
|
||||||
const Vehicle *v = object->u.vehicle.self;
|
const Vehicle *v = object->u.vehicle.self;
|
||||||
uint totalsets;
|
uint totalsets;
|
||||||
uint set;
|
uint set;
|
||||||
|
bool in_motion;
|
||||||
|
|
||||||
if (v == NULL) {
|
if (v == NULL) return group->g.real.loaded[0];
|
||||||
*in_motion = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
*in_motion = GetFirstVehicleInChain(v)->current_order.type != OT_LOADING;
|
in_motion = GetFirstVehicleInChain(v)->current_order.type != OT_LOADING;
|
||||||
} else {
|
} else {
|
||||||
*in_motion = v->current_order.type != OT_LOADING;
|
in_motion = v->current_order.type != OT_LOADING;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalsets = *in_motion ? num_loaded : num_loading;
|
totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
|
||||||
|
|
||||||
if (v->cargo_count == v->cargo_cap || totalsets == 1) {
|
if (v->cargo_count == v->cargo_cap || totalsets == 1) {
|
||||||
set = totalsets - 1;
|
set = totalsets - 1;
|
||||||
|
@ -663,7 +661,7 @@ static uint32 VehicleResolveReal(const ResolverObject *object, uint num_loaded,
|
||||||
set = v->cargo_count * (totalsets - 2) / max(1, v->cargo_cap) + 1;
|
set = v->cargo_count * (totalsets - 2) / max(1, v->cargo_cap) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return set;
|
return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -71,19 +71,6 @@ void InitializeSpriteGroupPool(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline const SpriteGroup *ResolveReal(const SpriteGroup *group, ResolverObject *object)
|
|
||||||
{
|
|
||||||
bool in_motion;
|
|
||||||
uint set;
|
|
||||||
|
|
||||||
set = object->ResolveReal(object, group->g.real.num_loaded, group->g.real.num_loading, &in_motion);
|
|
||||||
|
|
||||||
assert((in_motion && set < group->g.real.num_loaded) || (!in_motion && set < group->g.real.num_loading));
|
|
||||||
|
|
||||||
return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline uint32 GetVariable(const ResolverObject *object, byte variable, byte parameter)
|
static inline uint32 GetVariable(const ResolverObject *object, byte variable, byte parameter)
|
||||||
{
|
{
|
||||||
/* Return common variables */
|
/* Return common variables */
|
||||||
|
@ -240,7 +227,7 @@ const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object)
|
||||||
if (group == NULL) return NULL;
|
if (group == NULL) return NULL;
|
||||||
|
|
||||||
switch (group->type) {
|
switch (group->type) {
|
||||||
case SGT_REAL: return ResolveReal(group, object);
|
case SGT_REAL: return object->ResolveReal(object, group);
|
||||||
case SGT_DETERMINISTIC: return ResolveVariable(group, object);
|
case SGT_DETERMINISTIC: return ResolveVariable(group, object);
|
||||||
case SGT_RANDOMIZED: return ResolveRandom(group, object);
|
case SGT_RANDOMIZED: return ResolveRandom(group, object);
|
||||||
default: return group;
|
default: return group;
|
||||||
|
|
|
@ -181,7 +181,7 @@ typedef struct ResolverObject {
|
||||||
uint32 (*GetTriggers)(const struct ResolverObject*);
|
uint32 (*GetTriggers)(const struct ResolverObject*);
|
||||||
void (*SetTriggers)(const struct ResolverObject*, int);
|
void (*SetTriggers)(const struct ResolverObject*, int);
|
||||||
uint32 (*GetVariable)(const struct ResolverObject*, byte, byte);
|
uint32 (*GetVariable)(const struct ResolverObject*, byte, byte);
|
||||||
uint32 (*ResolveReal)(const struct ResolverObject*, uint, uint, bool*);
|
const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const SpriteGroup*);
|
||||||
} ResolverObject;
|
} ResolverObject;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue