diff options
author | rubidium <rubidium@openttd.org> | 2009-03-11 20:43:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-03-11 20:43:14 +0000 |
commit | b003536ea82e95f75a1ac9d6f557246e4bf4c9f4 (patch) | |
tree | fab12a7368299932db664475d5c9f6318d508de3 | |
parent | 49d6804f97c4717be6c8ebd5d64a7548e2c05c96 (diff) | |
download | openttd-b003536ea82e95f75a1ac9d6f557246e4bf4c9f4.tar.xz |
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
-rw-r--r-- | src/aircraft_cmd.cpp | 22 | ||||
-rw-r--r-- | src/articulated_vehicles.cpp | 2 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 19 | ||||
-rw-r--r-- | src/effectvehicle.cpp | 61 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 14 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 3 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 10 | ||||
-rw-r--r-- | src/train_cmd.cpp | 20 | ||||
-rw-r--r-- | src/vehicle.cpp | 68 | ||||
-rw-r--r-- | src/vehicle_func.h | 4 |
10 files changed, 70 insertions, 153 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 9f03f0d86..c9ffe5ff8 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -397,8 +397,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin UpdateAircraftCache(v); - VehiclePositionChanged(v); - VehiclePositionChanged(u); + VehicleMove(v, false); + VehicleMove(u, false); /* Aircraft with 3 vehicles (chopper)? */ if (v->subtype == AIR_HELICOPTER) { @@ -421,7 +421,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin w->UpdateDeltaXY(INVALID_DIR); u->SetNext(w); - VehiclePositionChanged(w); + VehicleMove(w, false); } InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); @@ -692,9 +692,7 @@ static void HelicopterTickHandler(Vehicle *v) u->cur_image = img; - BeginVehicleMove(u); - VehiclePositionChanged(u); - EndVehicleMove(u); + VehicleMove(u, true); } void SetAircraftPosition(Vehicle *v, int x, int y, int z) @@ -706,9 +704,7 @@ void SetAircraftPosition(Vehicle *v, int x, int y, int z) v->cur_image = v->GetImage(v->direction); if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v); - BeginVehicleMove(v); - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); Vehicle *u = v->Next(); @@ -721,9 +717,7 @@ void SetAircraftPosition(Vehicle *v, int x, int y, int z) u->z_pos = GetSlopeZ(safe_x, safe_y); u->cur_image = v->cur_image; - BeginVehicleMove(u); - VehiclePositionChanged(u); - EndVehicleMove(u); + VehicleMove(u, true); u = u->Next(); if (u != NULL) { @@ -731,9 +725,7 @@ void SetAircraftPosition(Vehicle *v, int x, int y, int z) u->y_pos = y; u->z_pos = z + 5; - BeginVehicleMove(u); - VehiclePositionChanged(u); - EndVehicleMove(u); + VehicleMove(u, true); } } diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 153e0b50f..4729b5a55 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -329,6 +329,6 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type) if (flip_image) u->spritenum++; - VehiclePositionChanged(u); + VehicleMove(u, false); } } diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 8ef01cf95..e328c76e2 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -135,7 +135,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Directio v->current_order.Free(); DisasterVehicleUpdateImage(v); - VehiclePositionChanged(v); + VehicleMove(v, false); MarkSingleVehicleDirty(v); } @@ -143,20 +143,17 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) { Vehicle *u; - BeginVehicleMove(v); v->x_pos = x; v->y_pos = y; v->z_pos = z; v->tile = TileVirtXY(x, y); DisasterVehicleUpdateImage(v); - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); if ((u = v->Next()) != NULL) { int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE); int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE); - BeginVehicleMove(u); u->x_pos = x; u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0U) >> 3); @@ -165,16 +162,13 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z) u->direction = v->direction; DisasterVehicleUpdateImage(u); - VehiclePositionChanged(u); - EndVehicleMove(u); + VehicleMove(u, true); if ((u = u->Next()) != NULL) { - BeginVehicleMove(u); u->x_pos = x; u->y_pos = y; u->z_pos = z + 5; - VehiclePositionChanged(u); - EndVehicleMove(u); + VehicleMove(u, true); } } } @@ -543,8 +537,7 @@ static void DisasterTick_Helicopter_Rotors(Vehicle *v) if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; - VehiclePositionChanged(v); - MarkSingleVehicleDirty(v); + VehicleMove(v, true); } /** @@ -702,8 +695,6 @@ static void DisasterTick_Submarine(Vehicle *v) v->tick_counter++; if (++v->age > 8880) { - VehiclePositionChanged(v); - MarkSingleVehicleDirty(v); delete v; return; } diff --git a/src/effectvehicle.cpp b/src/effectvehicle.cpp index ad73b5664..1b168daec 100644 --- a/src/effectvehicle.cpp +++ b/src/effectvehicle.cpp @@ -25,8 +25,6 @@ static void ChimneySmokeTick(Vehicle *v) if (v->progress > 0) { v->progress--; } else { - BeginVehicleMove(v); - TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); if (!IsTileType(tile, MP_INDUSTRY)) { delete v; @@ -39,8 +37,7 @@ static void ChimneySmokeTick(Vehicle *v) v->cur_image = SPR_CHIMNEY_SMOKE_0; } v->progress = 7; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } } @@ -54,8 +51,6 @@ static void SteamSmokeTick(Vehicle *v) { bool moved = false; - BeginVehicleMove(v); - v->progress++; if ((v->progress & 7) == 0) { @@ -73,10 +68,7 @@ static void SteamSmokeTick(Vehicle *v) moved = true; } - if (moved) { - VehiclePositionChanged(v); - EndVehicleMove(v); - } + if (moved) VehicleMove(v, true); } static void DieselSmokeInit(Vehicle *v) @@ -90,16 +82,12 @@ static void DieselSmokeTick(Vehicle *v) v->progress++; if ((v->progress & 3) == 0) { - BeginVehicleMove(v); v->z_pos++; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } else if ((v->progress & 7) == 1) { - BeginVehicleMove(v); if (v->cur_image != SPR_DIESEL_SMOKE_5) { v->cur_image++; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } else { delete v; } @@ -118,11 +106,9 @@ static void ElectricSparkTick(Vehicle *v) v->progress++; } else { v->progress = 0; - BeginVehicleMove(v); if (v->cur_image != SPR_ELECTRIC_SPARK_5) { v->cur_image++; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } else { delete v; } @@ -139,8 +125,6 @@ static void SmokeTick(Vehicle *v) { bool moved = false; - BeginVehicleMove(v); - v->progress++; if ((v->progress & 3) == 0) { @@ -158,10 +142,7 @@ static void SmokeTick(Vehicle *v) moved = true; } - if (moved) { - VehiclePositionChanged(v); - EndVehicleMove(v); - } + if (moved) VehicleMove(v, true); } static void ExplosionLargeInit(Vehicle *v) @@ -174,11 +155,9 @@ static void ExplosionLargeTick(Vehicle *v) { v->progress++; if ((v->progress & 3) == 0) { - BeginVehicleMove(v); if (v->cur_image != SPR_EXPLOSION_LARGE_F) { v->cur_image++; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } else { delete v; } @@ -195,14 +174,12 @@ static void BreakdownSmokeTick(Vehicle *v) { v->progress++; if ((v->progress & 7) == 0) { - BeginVehicleMove(v); if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) { v->cur_image++; } else { v->cur_image = SPR_BREAKDOWN_SMOKE_0; } - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } v->u.effect.animation_state--; @@ -221,11 +198,9 @@ static void ExplosionSmallTick(Vehicle *v) { v->progress++; if ((v->progress & 3) == 0) { - BeginVehicleMove(v); if (v->cur_image != SPR_EXPLOSION_SMALL_B) { v->cur_image++; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } else { delete v; } @@ -285,8 +260,6 @@ static void BulldozerTick(Vehicle *v) if ((v->progress & 7) == 0) { const BulldozerMovement *b = &_bulldozer_movement[v->u.effect.animation_state]; - BeginVehicleMove(v); - v->cur_image = SPR_BULLDOZER_NE + b->image; v->x_pos += _inc_by_dir[b->direction].x; @@ -301,8 +274,7 @@ static void BulldozerTick(Vehicle *v) return; } } - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } } @@ -470,13 +442,10 @@ static void BubbleTick(Vehicle *v) v->progress++; if ((v->progress & 3) != 0) return; - BeginVehicleMove(v); - if (v->spritenum == 0) { v->cur_image++; if (v->cur_image < SPR_BUBBLE_GENERATE_3) { - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); return; } if (v->u.effect.animation_substate != 0) { @@ -522,8 +491,7 @@ static void BubbleTick(Vehicle *v) v->z_pos += b->z; v->cur_image = SPR_BUBBLE_0 + b->image; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } @@ -572,9 +540,8 @@ Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type) _effect_init_procs[type](v); - VehiclePositionChanged(v); - BeginVehicleMove(v); - EndVehicleMove(v); + VehicleMove(v, false); + MarkSingleVehicleDirty(v); return v; } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 5c7622446..eecf6741f 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -270,7 +270,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap); } - VehiclePositionChanged(v); + VehicleMove(v, false); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); @@ -540,8 +540,7 @@ static byte SetRoadVehPosition(Vehicle *v, int x, int y) old_z = v->z_pos; v->z_pos = new_z; - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); return old_z; } @@ -555,7 +554,6 @@ static void RoadVehSetRandomDirection(Vehicle *v) uint32 r = Random(); v->direction = ChangeDir(v->direction, delta[r & 3]); - BeginVehicleMove(v); v->UpdateDeltaXY(v->direction); v->cur_image = v->GetImage(v->direction); SetRoadVehPosition(v, v->x_pos, v->y_pos); @@ -1246,8 +1244,6 @@ static bool RoadVehLeaveDepot(Vehicle *v, bool first) v->cur_speed = 0; } - BeginVehicleMove(v); - v->vehstatus &= ~VS_HIDDEN; v->u.road.state = tdir; v->u.road.frame = RVC_DEPOT_START_FRAME; @@ -1367,9 +1363,6 @@ static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev) * by the previous vehicle in the chain when it gets to the right place. */ if (v->IsInDepot()) return true; - /* Save old vehicle position to use at end of move to set viewport area dirty */ - BeginVehicleMove(v); - if (v->u.road.state == RVSB_WORMHOLE) { /* Vehicle is entering a depot or is on a bridge or in a tunnel */ GetNewVehiclePosResult gp = GetNewVehiclePos(v); @@ -1392,8 +1385,7 @@ static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev) v->x_pos = gp.x; v->y_pos = gp.y; - VehiclePositionChanged(v); - if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); + VehicleMove(v, !(v->vehstatus & VS_HIDDEN)); return true; } diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 8d614fbbd..a651d06bb 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -359,8 +359,7 @@ void AfterLoadVehicles(bool part_of_load) default: break; } - v->coord.left = INVALID_COORD; - VehiclePositionChanged(v); + VehicleMove(v, false); } } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 40e0a1697..89bd45f1b 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -588,8 +588,6 @@ static void ShipController(Vehicle *v) if (!ShipAccelerate(v)) return; - BeginVehicleMove(v); - GetNewVehiclePosResult gp = GetNewVehiclePos(v); if (v->u.ship.state != TRACK_BIT_WORMHOLE) { /* Not on a bridge */ @@ -683,8 +681,7 @@ static void ShipController(Vehicle *v) if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { v->x_pos = gp.x; v->y_pos = gp.y; - VehiclePositionChanged(v); - if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); + VehicleMove(v, !(v->vehstatus & VS_HIDDEN)); return; } } @@ -698,8 +695,7 @@ static void ShipController(Vehicle *v) getout: v->UpdateDeltaXY(dir); v->cur_image = v->GetImage(dir); - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); return; reverse_direction: @@ -803,7 +799,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity); - VehiclePositionChanged(v); + VehicleMove(v, false); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowClassesData(WC_SHIPS_LIST, 0); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index d327c3f3a..8b268fd31 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -669,7 +669,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF _new_vehicle_id = v->index; - VehiclePositionChanged(v); + VehicleMove(v, false); TrainConsistChanged(v->First(), false); UpdateTrainGroupID(v->First()); @@ -724,7 +724,7 @@ static void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool buildin u->value = v->value; u->cur_image = 0xAC2; u->random_bits = VehicleRandomBits(); - VehiclePositionChanged(u); + VehicleMove(u, false); } /** Build a railroad vehicle. @@ -827,7 +827,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, SetFrontEngine(v); SetTrainEngine(v); - VehiclePositionChanged(v); + VehicleMove(v, false); if (rvi->railveh_type == RAILVEH_MULTIHEAD) { SetMultiheaded(v); @@ -1546,9 +1546,7 @@ static void UpdateVarsAfterSwap(Vehicle *v) { v->UpdateDeltaXY(v->direction); v->cur_image = v->GetImage(v->direction); - BeginVehicleMove(v); - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); } static inline void SetLastSpeed(Vehicle *v, int spd) @@ -2420,7 +2418,7 @@ static bool CheckTrainStayInDepot(Vehicle *v) v->UpdateDeltaXY(v->direction); v->cur_image = v->GetImage(v->direction); - VehiclePositionChanged(v); + VehicleMove(v, false); UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); UpdateTrainAcceleration(v); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); @@ -3366,8 +3364,7 @@ static byte AfterSetTrainPos(Vehicle *v, bool new_tile) } } - VehiclePositionChanged(v); - EndVehicleMove(v); + VehicleMove(v, true); return old_z; } @@ -3650,7 +3647,6 @@ static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image) for (prev = v->Previous(); v != nomove; prev = v, v = v->Next()) { DiagDirection enterdir = DIAGDIR_BEGIN; bool update_signals_crossing = false; // will we update signals or crossing state? - BeginVehicleMove(v); GetNewVehiclePosResult gp = GetNewVehiclePos(v); if (v->u.rail.track != TRACK_BIT_WORMHOLE) { @@ -3838,8 +3834,7 @@ static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image) } else { v->x_pos = gp.x; v->y_pos = gp.y; - VehiclePositionChanged(v); - if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); + VehicleMove(v, !(v->vehstatus & VS_HIDDEN)); continue; } } @@ -4002,7 +3997,6 @@ static void ChangeTrainDirRandomly(Vehicle *v) /* We don't need to twist around vehicles if they're not visible */ if (!(v->vehstatus & VS_HIDDEN)) { v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); - BeginVehicleMove(v); v->UpdateDeltaXY(v->direction); v->cur_image = v->GetImage(v->direction); /* Refrain from updating the z position of the vehicle when on diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2b44950c8..f3a396cdb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -186,23 +186,6 @@ bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle * static void UpdateVehiclePosHash(Vehicle *v, int x, int y); -void VehiclePositionChanged(Vehicle *v) -{ - int img = v->cur_image; - Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); - const Sprite *spr = GetSprite(img, ST_NORMAL); - - pt.x += spr->x_offs; - pt.y += spr->y_offs; - - UpdateVehiclePosHash(v, pt.x, pt.y); - - v->coord.left = pt.x; - v->coord.top = pt.y; - v->coord.right = pt.x + spr->width + 2; - v->coord.bottom = pt.y + spr->height + 2; -} - Vehicle::Vehicle() { this->type = VEH_INVALID; @@ -1631,33 +1614,38 @@ CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, } -static Rect _old_vehicle_coords; ///< coords of vehicle before it has moved - /** - * Stores the vehicle image coords for later call to EndVehicleMove() - * @param v vehicle which image's coords to store - * @see _old_vehicle_coords - * @see EndVehicleMove() + * Move a vehicle in the game state; that is moving it's position in + * the position hashes and marking it's location in the viewport dirty + * if requested. + * @param v vehicle to move + * @param update_viewport whether to dirty the viewport */ -void BeginVehicleMove(const Vehicle *v) +void VehicleMove(Vehicle *v, bool update_viewport) { - _old_vehicle_coords = v->coord; -} + int img = v->cur_image; + Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); + const Sprite *spr = GetSprite(img, ST_NORMAL); -/** - * Marks screen dirty after a vehicle has moved - * @param v vehicle which is marked dirty - * @see _old_vehicle_coords - * @see BeginVehicleMove() - */ -void EndVehicleMove(const Vehicle *v) -{ - MarkAllViewportsDirty( - min(_old_vehicle_coords.left, v->coord.left), - min(_old_vehicle_coords.top, v->coord.top), - max(_old_vehicle_coords.right, v->coord.right) + 1, - max(_old_vehicle_coords.bottom, v->coord.bottom) + 1 - ); + pt.x += spr->x_offs; + pt.y += spr->y_offs; + + UpdateVehiclePosHash(v, pt.x, pt.y); + + Rect old_coord = v->coord; + v->coord.left = pt.x; + v->coord.top = pt.y; + v->coord.right = pt.x + spr->width + 2; + v->coord.bottom = pt.y + spr->height + 2; + + if (update_viewport) { + MarkAllViewportsDirty( + min(old_coord.left, v->coord.left), + min(old_coord.top, v->coord.top), + max(old_coord.right, v->coord.right) + 1, + max(old_coord.bottom, v->coord.bottom) + 1 + ); + } } /** diff --git a/src/vehicle_func.h b/src/vehicle_func.h index 88ac292b4..4bbdb8f6b 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -22,7 +22,6 @@ typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data); void VehicleServiceInDepot(Vehicle *v); -void VehiclePositionChanged(Vehicle *v); Vehicle *GetLastVehicleInChain(Vehicle *v); const Vehicle *GetLastVehicleInChain(const Vehicle *v); uint CountVehiclesInChain(const Vehicle *v); @@ -55,8 +54,7 @@ void CheckVehicleBreakdown(Vehicle *v); void AgeVehicle(Vehicle *v); void VehicleEnteredDepotThisTick(Vehicle *v); -void BeginVehicleMove(const Vehicle *v); -void EndVehicleMove(const Vehicle *v); +void VehicleMove(Vehicle *v, bool update_viewport); void MarkSingleVehicleDirty(const Vehicle *v); UnitID GetFreeUnitNumber(VehicleType type); |