Cache whether vehicle is currently drawn: Vehicle::IsDrawn()
This commit is contained in:
@@ -577,9 +577,11 @@ void HandleAircraftEnterHangar(Aircraft *v)
|
|||||||
|
|
||||||
Aircraft *u = v->Next();
|
Aircraft *u = v->Next();
|
||||||
u->vehstatus |= VS_HIDDEN;
|
u->vehstatus |= VS_HIDDEN;
|
||||||
|
u->UpdateIsDrawn();
|
||||||
u = u->Next();
|
u = u->Next();
|
||||||
if (u != nullptr) {
|
if (u != nullptr) {
|
||||||
u->vehstatus |= VS_HIDDEN;
|
u->vehstatus |= VS_HIDDEN;
|
||||||
|
u->UpdateIsDrawn();
|
||||||
u->cur_speed = 0;
|
u->cur_speed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1493,14 +1495,17 @@ void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
|
|||||||
v->progress = 0;
|
v->progress = 0;
|
||||||
v->direction = exit_dir;
|
v->direction = exit_dir;
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
v->UpdateIsDrawn();
|
||||||
{
|
{
|
||||||
Vehicle *u = v->Next();
|
Vehicle *u = v->Next();
|
||||||
u->vehstatus &= ~VS_HIDDEN;
|
u->vehstatus &= ~VS_HIDDEN;
|
||||||
|
u->UpdateIsDrawn();
|
||||||
|
|
||||||
/* Rotor blades */
|
/* Rotor blades */
|
||||||
u = u->Next();
|
u = u->Next();
|
||||||
if (u != nullptr) {
|
if (u != nullptr) {
|
||||||
u->vehstatus &= ~VS_HIDDEN;
|
u->vehstatus &= ~VS_HIDDEN;
|
||||||
|
u->UpdateIsDrawn();
|
||||||
u->cur_speed = 80;
|
u->cur_speed = 80;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -180,6 +180,7 @@ DisasterVehicle::DisasterVehicle(int x, int y, Direction direction, DisasterSubT
|
|||||||
this->owner = OWNER_NONE;
|
this->owner = OWNER_NONE;
|
||||||
this->image_override = 0;
|
this->image_override = 0;
|
||||||
this->current_order.Free();
|
this->current_order.Free();
|
||||||
|
this->UpdateIsDrawn();
|
||||||
|
|
||||||
this->UpdateImage();
|
this->UpdateImage();
|
||||||
this->UpdatePositionAndViewport();
|
this->UpdatePositionAndViewport();
|
||||||
|
@@ -632,6 +632,8 @@ EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
|
|||||||
|
|
||||||
_effect_init_procs[type](v);
|
_effect_init_procs[type](v);
|
||||||
|
|
||||||
|
v->UpdateIsDrawn();
|
||||||
|
|
||||||
v->UpdatePositionAndViewport();
|
v->UpdatePositionAndViewport();
|
||||||
|
|
||||||
v->AddEffectVehicleToTickCache();
|
v->AddEffectVehicleToTickCache();
|
||||||
|
@@ -3671,6 +3671,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
|||||||
|
|
||||||
v->track = TRACK_BIT_DEPOT,
|
v->track = TRACK_BIT_DEPOT,
|
||||||
v->vehstatus |= VS_HIDDEN; // hide it
|
v->vehstatus |= VS_HIDDEN; // hide it
|
||||||
|
v->UpdateIsDrawn();
|
||||||
v->direction = ReverseDir(v->direction);
|
v->direction = ReverseDir(v->direction);
|
||||||
if (v->Next() == nullptr) VehicleEnterDepot(v->First());
|
if (v->Next() == nullptr) VehicleEnterDepot(v->First());
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
@@ -3684,6 +3685,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
|||||||
if ((v = v->Next()) != nullptr) {
|
if ((v = v->Next()) != nullptr) {
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
v->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
v->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
||||||
|
v->UpdateIsDrawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2362,6 +2362,7 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int
|
|||||||
rv->direction = ReverseDir(rv->direction);
|
rv->direction = ReverseDir(rv->direction);
|
||||||
if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
|
if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
|
||||||
rv->tile = tile;
|
rv->tile = tile;
|
||||||
|
rv->UpdateIsDrawn();
|
||||||
|
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
|
InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
|
@@ -1119,6 +1119,7 @@ static bool RoadVehLeaveDepot(RoadVehicle *v, bool first)
|
|||||||
v->cur_image_valid_dir = INVALID_DIR;
|
v->cur_image_valid_dir = INVALID_DIR;
|
||||||
v->state = tdir;
|
v->state = tdir;
|
||||||
v->frame = RVC_DEPOT_START_FRAME;
|
v->frame = RVC_DEPOT_START_FRAME;
|
||||||
|
v->UpdateIsDrawn();
|
||||||
|
|
||||||
v->x_pos = x;
|
v->x_pos = x;
|
||||||
v->y_pos = y;
|
v->y_pos = y;
|
||||||
|
@@ -3795,6 +3795,8 @@ bool AfterLoadGame()
|
|||||||
InvalidateVehicleTickCaches();
|
InvalidateVehicleTickCaches();
|
||||||
ClearVehicleTickCaches();
|
ClearVehicleTickCaches();
|
||||||
|
|
||||||
|
UpdateAllVehiclesIsDrawn();
|
||||||
|
|
||||||
extern void YapfCheckRailSignalPenalties();
|
extern void YapfCheckRailSignalPenalties();
|
||||||
YapfCheckRailSignalPenalties();
|
YapfCheckRailSignalPenalties();
|
||||||
|
|
||||||
|
@@ -405,6 +405,7 @@ static bool CheckShipLeaveDepot(Ship *v)
|
|||||||
|
|
||||||
v->state = AxisToTrackBits(axis);
|
v->state = AxisToTrackBits(axis);
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
v->UpdateIsDrawn();
|
||||||
|
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
v->UpdateViewport(true, true);
|
v->UpdateViewport(true, true);
|
||||||
|
@@ -1835,6 +1835,8 @@ static void UpdateStatusAfterSwap(Train *v)
|
|||||||
/* Reverse the direction. */
|
/* Reverse the direction. */
|
||||||
if (v->track != TRACK_BIT_DEPOT) v->direction = ReverseDir(v->direction);
|
if (v->track != TRACK_BIT_DEPOT) v->direction = ReverseDir(v->direction);
|
||||||
|
|
||||||
|
v->UpdateIsDrawn();
|
||||||
|
|
||||||
/* Call the proper EnterTile function unless we are in a wormhole. */
|
/* Call the proper EnterTile function unless we are in a wormhole. */
|
||||||
if (!(v->track & TRACK_BIT_WORMHOLE)) {
|
if (!(v->track & TRACK_BIT_WORMHOLE)) {
|
||||||
VehicleEnterTile(v, v->tile, v->x_pos, v->y_pos);
|
VehicleEnterTile(v, v->tile, v->x_pos, v->y_pos);
|
||||||
@@ -2642,6 +2644,7 @@ static bool CheckTrainStayInDepot(Train *v)
|
|||||||
if (v->direction & 2) v->track = TRACK_BIT_Y;
|
if (v->direction & 2) v->track = TRACK_BIT_Y;
|
||||||
|
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
|
v->UpdateIsDrawn();
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
|
|
||||||
v->UpdateViewport(true, true);
|
v->UpdateViewport(true, true);
|
||||||
|
@@ -70,6 +70,9 @@ static inline bool IsInvisibilitySet(TransparencyOption to)
|
|||||||
static inline void ToggleTransparency(TransparencyOption to)
|
static inline void ToggleTransparency(TransparencyOption to)
|
||||||
{
|
{
|
||||||
ToggleBit(_transparency_opt, to);
|
ToggleBit(_transparency_opt, to);
|
||||||
|
|
||||||
|
extern void UpdateAllVehiclesIsDrawn();
|
||||||
|
if (to == TO_TUNNELS) UpdateAllVehiclesIsDrawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2566,6 +2566,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
|||||||
t->track = TRACK_BIT_WORMHOLE;
|
t->track = TRACK_BIT_WORMHOLE;
|
||||||
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(t->gv_flags, GVF_CHUNNEL_BIT);
|
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(t->gv_flags, GVF_CHUNNEL_BIT);
|
||||||
t->vehstatus |= VS_HIDDEN;
|
t->vehstatus |= VS_HIDDEN;
|
||||||
|
t->UpdateIsDrawn();
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2577,6 +2578,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
|||||||
t->track = DiagDirToDiagTrackBits(vdir);
|
t->track = DiagDirToDiagTrackBits(vdir);
|
||||||
assert(t->track);
|
assert(t->track);
|
||||||
t->vehstatus &= ~VS_HIDDEN;
|
t->vehstatus &= ~VS_HIDDEN;
|
||||||
|
t->UpdateIsDrawn();
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
}
|
}
|
||||||
} else if (v->type == VEH_ROAD) {
|
} else if (v->type == VEH_ROAD) {
|
||||||
@@ -2593,6 +2595,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
|||||||
rv->state = RVSB_WORMHOLE;
|
rv->state = RVSB_WORMHOLE;
|
||||||
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(rv->gv_flags, GVF_CHUNNEL_BIT);
|
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(rv->gv_flags, GVF_CHUNNEL_BIT);
|
||||||
rv->vehstatus |= VS_HIDDEN;
|
rv->vehstatus |= VS_HIDDEN;
|
||||||
|
rv->UpdateIsDrawn();
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
} else {
|
} else {
|
||||||
return VETSB_CONTINUE;
|
return VETSB_CONTINUE;
|
||||||
@@ -2607,6 +2610,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
|||||||
rv->state = DiagDirToDiagTrackdir(vdir);
|
rv->state = DiagDirToDiagTrackdir(vdir);
|
||||||
rv->frame = TILE_SIZE - (frame + 1);
|
rv->frame = TILE_SIZE - (frame + 1);
|
||||||
rv->vehstatus &= ~VS_HIDDEN;
|
rv->vehstatus &= ~VS_HIDDEN;
|
||||||
|
rv->UpdateIsDrawn();
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -358,15 +358,22 @@ uint Vehicle::Crash(bool flooded)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether a the vehicle should be drawn (i.e. if it isn't hidden, or it is in a tunnel but being shown transparently)
|
* Update cache of whether the vehicle should be drawn (i.e. if it isn't hidden, or it is in a tunnel but being shown transparently)
|
||||||
* @return whether to show vehicle
|
* @return whether to show vehicle
|
||||||
*/
|
*/
|
||||||
bool Vehicle::IsDrawn() const
|
void Vehicle::UpdateIsDrawn()
|
||||||
{
|
{
|
||||||
return !(HasBit(this->subtype, GVSF_VIRTUAL)) && (!(this->vehstatus & VS_HIDDEN) ||
|
bool drawn = !(HasBit(this->subtype, GVSF_VIRTUAL)) && (!(this->vehstatus & VS_HIDDEN) ||
|
||||||
(IsTransparencySet(TO_TUNNELS) &&
|
(IsTransparencySet(TO_TUNNELS) &&
|
||||||
((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) ||
|
((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) ||
|
||||||
(this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE))));
|
(this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE))));
|
||||||
|
|
||||||
|
SB(this->vcache.cached_veh_flags, VCF_IS_DRAWN, 1, drawn ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateAllVehiclesIsDrawn()
|
||||||
|
{
|
||||||
|
for (Vehicle *v : Vehicle::Iterate()) { v->UpdateIsDrawn(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2240,6 +2247,7 @@ void VehicleEnterDepot(Vehicle *v)
|
|||||||
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
|
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
|
||||||
|
|
||||||
v->vehstatus |= VS_HIDDEN;
|
v->vehstatus |= VS_HIDDEN;
|
||||||
|
v->UpdateIsDrawn();
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
|
|
||||||
VehicleServiceInDepot(v);
|
VehicleServiceInDepot(v);
|
||||||
@@ -3847,6 +3855,7 @@ char *Vehicle::DumpVehicleFlags(char *b, const char *last) const
|
|||||||
b += seprintf(b, last, ", vcf:");
|
b += seprintf(b, last, ", vcf:");
|
||||||
dump('l', HasBit(this->vcache.cached_veh_flags, VCF_LAST_VISUAL_EFFECT));
|
dump('l', HasBit(this->vcache.cached_veh_flags, VCF_LAST_VISUAL_EFFECT));
|
||||||
dump('z', HasBit(this->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST));
|
dump('z', HasBit(this->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST));
|
||||||
|
dump('d', HasBit(this->vcache.cached_veh_flags, VCF_IS_DRAWN));
|
||||||
if (this->IsGroundVehicle()) {
|
if (this->IsGroundVehicle()) {
|
||||||
uint16 gv_flags = this->GetGroundVehicleFlags();
|
uint16 gv_flags = this->GetGroundVehicleFlags();
|
||||||
b += seprintf(b, last, ", gvf:");
|
b += seprintf(b, last, ", gvf:");
|
||||||
|
@@ -134,7 +134,8 @@ enum GroundVehicleSubtypeFlags {
|
|||||||
*/
|
*/
|
||||||
enum VehicleCacheFlags {
|
enum VehicleCacheFlags {
|
||||||
VCF_LAST_VISUAL_EFFECT = 0, ///< Last vehicle in the consist with a visual effect.
|
VCF_LAST_VISUAL_EFFECT = 0, ///< Last vehicle in the consist with a visual effect.
|
||||||
VCF_GV_ZERO_SLOPE_RESIST = 1, ///< GrounVehicle: Consist has zero slope resistance (valid only for the first engine), may be false negative.
|
VCF_GV_ZERO_SLOPE_RESIST = 1, ///< GroundVehicle: Consist has zero slope resistance (valid only for the first engine), may be false negative.
|
||||||
|
VCF_IS_DRAWN = 2, ///< Vehicle is currently drawn
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Cached often queried values common to all vehicles. */
|
/** Cached often queried values common to all vehicles. */
|
||||||
@@ -1093,7 +1094,12 @@ public:
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDrawn() const;
|
bool IsDrawn() const
|
||||||
|
{
|
||||||
|
return HasBit(this->vcache.cached_veh_flags, VCF_IS_DRAWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateIsDrawn();
|
||||||
|
|
||||||
inline void UpdateSpriteSeqBound()
|
inline void UpdateSpriteSeqBound()
|
||||||
{
|
{
|
||||||
@@ -1311,5 +1317,6 @@ inline void InvalidateVehicleTickCaches()
|
|||||||
|
|
||||||
void ClearVehicleTickCaches();
|
void ClearVehicleTickCaches();
|
||||||
void RemoveFromOtherVehicleTickCache(const Vehicle *v);
|
void RemoveFromOtherVehicleTickCache(const Vehicle *v);
|
||||||
|
void UpdateAllVehiclesIsDrawn();
|
||||||
|
|
||||||
#endif /* VEHICLE_BASE_H */
|
#endif /* VEHICLE_BASE_H */
|
||||||
|
Reference in New Issue
Block a user