New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ship cpu hog workaround for #6145 #6784
Changes from all commits
cc3c511
d4d6de1
aeacd42
8aca131
392c518
70346ef
5e4d5f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,6 +319,14 @@ void Ship::UpdateDeltaXY() | |
this->z_extent = 6; | ||
} | ||
|
||
/** | ||
* Test-procedure for HasVehicleOnPos to check for a ship. | ||
*/ | ||
static Vehicle *EnsureNoVisibleShipProc(Vehicle *v, void *data) | ||
{ | ||
return v->type == VEH_SHIP && (v->vehstatus & VS_HIDDEN) == 0 ? v : NULL; | ||
} | ||
|
||
static bool CheckShipLeaveDepot(Ship *v) | ||
{ | ||
if (!v->IsChainInDepot()) return false; | ||
|
@@ -330,6 +338,13 @@ static bool CheckShipLeaveDepot(Ship *v) | |
return true; | ||
} | ||
|
||
/* Don't leave depot if no destination set */ | ||
if (v->dest_tile == 0) return true; | ||
|
||
/* Don't leave depot if another vehicle is already entering/leaving */ | ||
/* This helps avoid CPU load if many ships are set to start at the same time */ | ||
if (HasVehicleOnPos(v->tile, NULL, &EnsureNoVisibleShipProc)) return true; | ||
|
||
TileIndex tile = v->tile; | ||
Axis axis = GetShipDepotAxis(tile); | ||
|
||
|
@@ -443,11 +458,27 @@ static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, Tr | |
|
||
bool path_found = true; | ||
Track track; | ||
switch (_settings_game.pf.pathfinder_for_ships) { | ||
case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
case VPF_NPF: track = NPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
default: NOT_REACHED(); | ||
|
||
if (v->dest_tile == 0 || DistanceManhattan(tile, v->dest_tile) > SHIP_MAX_ORDER_DISTANCE + 5) { | ||
/* No destination or destination too far, don't invoke pathfinder. */ | ||
track = TrackBitsToTrack(v->state); | ||
if (track != TRACK_X && track != TRACK_Y) track = TrackToOppositeTrack(track); | ||
if (!HasBit(tracks, track)) { | ||
/* Can't continue in same direction so pick first available track. */ | ||
if (_settings_game.pf.forbid_90_deg) { | ||
tracks &= ~TrackCrossesTracks(TrackdirToTrack(v->GetVehicleTrackdir())); | ||
if (tracks == TRACK_BIT_NONE) return INVALID_TRACK; | ||
} | ||
track = FindFirstTrack(tracks); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it take into account "forbid 90 degrees turns"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not but 'forbid 90 degree turns' is a bad feature for ships anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't consider 'forbid 90 degree turns' for ships a bad feature and it would be great the PR takes that into account, but you are right about the inconsistency of stopping a lost vehicle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would prefer if ships that had all orders deleted while out of depot just stopped in place, and only lost ships kept moving in a random direction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that YAPF also has a 'forbid 90 degree' for ships; would it be difficult to add it here? I agree that ships are weird anyway, but to keep some consistency would be nice. But it has to be reasonable. So if it is 2 lines of code, I think we should add it. If it is 6 days of work, I don't think it is worth it :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Forbid 90 degree' in YAPF is the cause of routing bugs for ships, they turn the wrong way from dock and get lost in rivers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to keep this conversation clear: good remark, but that shouldn't keep us from trying to keep things consistent; better to have it broken everywhere, than not implemented at some places :) Given YAPF implements it (how ever broken it might be), means we should, given it can be done in a reasonable amount of time, take it into account too :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't look thoroughly, but it seems OPF doesn't take into account "forbid_90_deg_turns". Maybe these lines of code after line 461 or 465 would do the trick:
I haven't checked whether this works or not. And it would need to check if tracks == TRACKBIT_NONE after that. |
||
} | ||
path_found = false; | ||
} else { | ||
switch (_settings_game.pf.pathfinder_for_ships) { | ||
case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
case VPF_NPF: track = NPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found); break; | ||
default: NOT_REACHED(); | ||
} | ||
} | ||
|
||
v->HandlePathfindingResult(path_found); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fentwood Transport, 1954-11-03.zip
This ship becomes lost with this patch applied, but it's not lost in 1.8.0