From d9c112cc9eb86dffdad1d8a073fbb566a15f9031 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 27 Aug 2019 17:03:18 +0100 Subject: [PATCH 1/5] Fix #97: Desync when moving newly built wagon --- src/train_cmd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 3a623312da..e80a27af0e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -869,6 +869,8 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const break; } } + + InvalidateVehicleTickCaches(); } return CommandCost(); From ce130bc18159396b2e88c601cfa7eca7e8847782 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 27 Aug 2019 17:14:49 +0100 Subject: [PATCH 2/5] Update order destination refcount in RemoveVehicleOrdersIf --- src/order_cmd.cpp | 12 +----------- src/order_cmd.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 86a533452e..05c0e03f2c 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -80,23 +80,13 @@ void ClearOrderDestinationRefcountMap() _order_destination_refcount_map_valid = false; } -static void UpdateOrderDestinationRefcount(const Order *order, VehicleType type, Owner owner, int delta) +void UpdateOrderDestinationRefcount(const Order *order, VehicleType type, Owner owner, int delta) { if (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) { _order_destination_refcount_map[OrderDestinationRefcountMapKey(order->GetDestination(), owner, order->GetType(), type)] += delta; } } -inline void RegisterOrderDestination(const Order *order, VehicleType type, Owner owner) -{ - if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, 1); -} - -inline void UnregisterOrderDestination(const Order *order, VehicleType type, Owner owner) -{ - if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, -1); -} - /** Clean everything up. */ Order::~Order() { diff --git a/src/order_cmd.h b/src/order_cmd.h index 5dc0f40784..aae22e1be6 100644 --- a/src/order_cmd.h +++ b/src/order_cmd.h @@ -16,6 +16,18 @@ #include "order_func.h" #include "vehicle_base.h" +void UpdateOrderDestinationRefcount(const Order *order, VehicleType type, Owner owner, int delta); + +inline void RegisterOrderDestination(const Order *order, VehicleType type, Owner owner) +{ + if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, 1); +} + +inline void UnregisterOrderDestination(const Order *order, VehicleType type, Owner owner) +{ + if (_order_destination_refcount_map_valid) UpdateOrderDestinationRefcount(order, type, owner, -1); +} + /** * Removes all orders from a vehicle for which order_predicate returns true. * Handles timetable updating, removing implicit orders correctly, etc. @@ -41,6 +53,8 @@ restart: break; } + UnregisterOrderDestination(order, v->type, v->owner); + /* Clear wait time */ if (!order->IsType(OT_CONDITIONAL)) v->orders.list->UpdateTotalDuration(-order->GetWaitTime()); if (order->IsWaitTimetabled()) { From eef1f52f930d46084b2c8fb99909085eeb64eb5a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 28 Aug 2019 18:24:50 +0100 Subject: [PATCH 3/5] Update project files --- projects/openttd_vs140.vcxproj | 1 + projects/openttd_vs140.vcxproj.filters | 3 +++ projects/openttd_vs141.vcxproj | 1 + projects/openttd_vs141.vcxproj.filters | 3 +++ projects/openttd_vs142.vcxproj | 1 + projects/openttd_vs142.vcxproj.filters | 3 +++ 6 files changed, 12 insertions(+) diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index dbd1e67191..6023a7f410 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -754,6 +754,7 @@ + diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 187ef0e7c0..7d1398c0ed 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -1356,6 +1356,9 @@ Core Source Code + + Core Source Code + Core Source Code diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj index 2bd1670b37..6c68d06807 100644 --- a/projects/openttd_vs141.vcxproj +++ b/projects/openttd_vs141.vcxproj @@ -754,6 +754,7 @@ + diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters index 187ef0e7c0..7d1398c0ed 100644 --- a/projects/openttd_vs141.vcxproj.filters +++ b/projects/openttd_vs141.vcxproj.filters @@ -1356,6 +1356,9 @@ Core Source Code + + Core Source Code + Core Source Code diff --git a/projects/openttd_vs142.vcxproj b/projects/openttd_vs142.vcxproj index cffc03b69d..81bc2758f5 100644 --- a/projects/openttd_vs142.vcxproj +++ b/projects/openttd_vs142.vcxproj @@ -754,6 +754,7 @@ + diff --git a/projects/openttd_vs142.vcxproj.filters b/projects/openttd_vs142.vcxproj.filters index 187ef0e7c0..7d1398c0ed 100644 --- a/projects/openttd_vs142.vcxproj.filters +++ b/projects/openttd_vs142.vcxproj.filters @@ -1356,6 +1356,9 @@ Core Source Code + + Core Source Code + Core Source Code From 9a05ea67d5406c6348dbb5fe9b87dbc8b8592be6 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 28 Aug 2019 19:10:34 +0100 Subject: [PATCH 4/5] Add chicken bits setting 2 bits so far --- projects/openttd_vs140.vcxproj | 1 + projects/openttd_vs140.vcxproj.filters | 3 +++ projects/openttd_vs141.vcxproj | 1 + projects/openttd_vs141.vcxproj.filters | 3 +++ projects/openttd_vs142.vcxproj | 1 + projects/openttd_vs142.vcxproj.filters | 3 +++ source.list | 1 + src/crashlog.cpp | 4 ++++ src/debug_settings.h | 28 ++++++++++++++++++++++++++ src/network/network_client.cpp | 5 +++-- src/settings_type.h | 6 ++++++ src/table/settings.ini | 12 +++++++++++ src/vehicle.cpp | 3 ++- 13 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/debug_settings.h diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index 6023a7f410..9ef40e1e04 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -493,6 +493,7 @@ + diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 7d1398c0ed..a25db71dcc 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -573,6 +573,9 @@ Header Files + + Header Files + Header Files diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj index 6c68d06807..98e5a127e6 100644 --- a/projects/openttd_vs141.vcxproj +++ b/projects/openttd_vs141.vcxproj @@ -493,6 +493,7 @@ + diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters index 7d1398c0ed..a25db71dcc 100644 --- a/projects/openttd_vs141.vcxproj.filters +++ b/projects/openttd_vs141.vcxproj.filters @@ -573,6 +573,9 @@ Header Files + + Header Files + Header Files diff --git a/projects/openttd_vs142.vcxproj b/projects/openttd_vs142.vcxproj index 81bc2758f5..ce0c2b4116 100644 --- a/projects/openttd_vs142.vcxproj +++ b/projects/openttd_vs142.vcxproj @@ -493,6 +493,7 @@ + diff --git a/projects/openttd_vs142.vcxproj.filters b/projects/openttd_vs142.vcxproj.filters index 7d1398c0ed..a25db71dcc 100644 --- a/projects/openttd_vs142.vcxproj.filters +++ b/projects/openttd_vs142.vcxproj.filters @@ -573,6 +573,9 @@ Header Files + + Header Files + Header Files diff --git a/source.list b/source.list index a530151757..18b6b9f509 100644 --- a/source.list +++ b/source.list @@ -181,6 +181,7 @@ date_func.h date_gui.h date_type.h debug.h +debug_settings.h video/dedicated_v.h departures_func.h departures_gui.h diff --git a/src/crashlog.cpp b/src/crashlog.cpp index b95a26ab1c..02d349f5d3 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -227,6 +227,10 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const buffer += seprintf(buffer, last, "Map size: 0x%X (%u x %u)%s\n\n", MapSize(), MapSizeX(), MapSizeY(), (!_m || !_me) ? ", NO MAP ALLOCATED" : ""); + if (_settings_game.debug.chicken_bits != 0) { + buffer += seprintf(buffer, last, "Chicken bits: 0x%08X\n\n", _settings_game.debug.chicken_bits); + } + buffer += seprintf(buffer, last, "AI Configuration (local: %i) (current: %i):\n", (int)_local_company, (int)_current_company); const Company *c; FOR_ALL_COMPANIES(c) { diff --git a/src/debug_settings.h b/src/debug_settings.h new file mode 100644 index 0000000000..4b197b4504 --- /dev/null +++ b/src/debug_settings.h @@ -0,0 +1,28 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file debug_settings.h Debug settings. */ + +#ifndef DEBUG_SETTINGS_H +#define DEBUG_SETTINGS_H + +#include "settings_type.h" +#include "core/bitmath_func.hpp" + +enum ChickenBitFlags { + DCBF_VEH_TICK_CACHE = 0, + DCBF_MP_NO_STATE_CSUM_CHECK = 1, +}; + +inline bool HasChickenBit(ChickenBitFlags flag) +{ + return HasBit(_settings_game.debug.chicken_bits, flag); +} + +#endif /* DEBUG_SETTINGS_H */ diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 319f9c5277..31e1f26c68 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -34,6 +34,7 @@ #include "../crashlog.h" #include "../core/checksum_func.hpp" #include "../fileio_func.h" +#include "../debug_settings.h" #include "table/strings.h" @@ -302,9 +303,9 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res) if (_sync_frame != 0) { if (_sync_frame == _frame_counter) { #ifdef NETWORK_SEND_DOUBLE_SEED - if (_sync_seed_1 != _random.state[0] || _sync_seed_2 != _random.state[1] || _sync_state_checksum != _state_checksum.state) { + if (_sync_seed_1 != _random.state[0] || _sync_seed_2 != _random.state[1] || (_sync_state_checksum != _state_checksum.state && !HasChickenBit(DCBF_MP_NO_STATE_CSUM_CHECK))) { #else - if (_sync_seed_1 != _random.state[0] || _sync_state_checksum != _state_checksum.state) { + if (_sync_seed_1 != _random.state[0] || (_sync_state_checksum != _state_checksum.state && !HasChickenBit(DCBF_MP_NO_STATE_CSUM_CHECK))) { #endif DesyncExtraInfo info; if (_sync_seed_1 != _random.state[0]) info.flags |= DesyncExtraInfo::DEIF_RAND1; diff --git a/src/settings_type.h b/src/settings_type.h index f8181a461f..6978284479 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -642,6 +642,11 @@ struct CompanySettings { bool advance_order_on_clone; ///< when cloning a vehicle or copying/sharing an order list, advance the current order to a suitable point }; +/** Debug settings. */ +struct DebugSettings { + uint32 chicken_bits; ///< chicken bits +}; + /** All settings together for the game. */ struct GameSettings { DifficultySettings difficulty; ///< settings related to the difficulty @@ -658,6 +663,7 @@ struct GameSettings { LinkGraphSettings linkgraph; ///< settings for link graph calculations StationSettings station; ///< settings related to station management LocaleSettings locale; ///< settings related to used currency/unit system in the current game + DebugSettings debug; ///< debug settings }; /** All settings that are only important for the local client. */ diff --git a/src/table/settings.ini b/src/table/settings.ini index e5b49c429d..e1bd7c79be 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -5283,5 +5283,17 @@ cat = SC_EXPERT extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_VEHICLE_REPAIR_COST) patxname = ""vehicle_repair_cost.vehicle.repair_cost"" +[SDT_VAR] +base = GameSettings +var = debug.chicken_bits +type = SLE_UINT32 +flags = SLF_NOT_IN_CONFIG +guiflags = SGF_NO_NEWGAME +def = 0 +min = 0 +max = 0xFFFFFFFF +cat = SC_EXPERT +patxname = ""debug.chicken_bits"" + [SDT_END] diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 1c2fedd63b..39c7048405 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -59,6 +59,7 @@ #include "tbtr_template_vehicle_func.h" #include "string_func.h" #include "scope_info.h" +#include "debug_settings.h" #include "3rdparty/cpp-btree/btree_set.h" #include "table/strings.h" @@ -1273,7 +1274,7 @@ void CallVehicleTicks() FOR_ALL_STATIONS(st) LoadUnloadStation(st); } - if (!_tick_caches_valid) RebuildVehicleTickCaches(); + if (!_tick_caches_valid || HasChickenBit(DCBF_VEH_TICK_CACHE)) RebuildVehicleTickCaches(); Vehicle *v = nullptr; SCOPE_INFO_FMT([&v], "CallVehicleTicks: %s", scope_dumper().VehicleInfo(v)); From df2c6d48a8dd11fbfbaaaafc5f98079169b6ceb8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 29 Aug 2019 00:42:21 +0100 Subject: [PATCH 5/5] Version: Committing version data for tag: jgrpp-0.31.5 --- .ottdrev-vc | 4 ++-- README.md | 2 +- jgrpp-changelog.md | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.ottdrev-vc b/.ottdrev-vc index 70ea975518..1c99d0bdb6 100644 --- a/.ottdrev-vc +++ b/.ottdrev-vc @@ -1,2 +1,2 @@ -jgrpp-0.31.4 20190824 0 62713ad106c15af7b422161f09e9efe39be37990 1 0 -2c60c3d02c7646220ce330c28881b0b0b0d8d9bb5c573483b24d387cfe8179bb - +jgrpp-0.31.5 20190828 0 9a05ea67d5406c6348dbb5fe9b87dbc8b8592be6 1 0 +64287d47e45db8e96adc2f039f99db305724ff58cc3caaaa140fad259cec49d3 - diff --git a/README.md b/README.md index 7cfe4c18c6..ce7f163d7a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## JGR's Patchpack version 0.31.4 +## JGR's Patchpack version 0.31.5 This is a collection of patches applied to [OpenTTD](http://www.openttd.org/) diff --git a/jgrpp-changelog.md b/jgrpp-changelog.md index 5ce89a83f0..ec9a7bc567 100644 --- a/jgrpp-changelog.md +++ b/jgrpp-changelog.md @@ -2,6 +2,9 @@ * * * +### v0.31.5 (2019-08-29) +* Fix multiplayer desync when when moving newly built wagon + ### v0.31.4 (2019-08-24) * Fix crash when removing signals from tunnel/bridge with trainless reservation. * Fix various cases where reversing a train inside a signalled tunnel/bridge handled PBS reservations incorrectly.