changeset 19532:6f7e0a9a9229 draft consist

WIP
author Michael Lutz <michi@icosahedron.de>
date Sun, 29 Jul 2012 03:26:52 +0200
parents ad9227a0aeab
children
files projects/openttd_vs100.vcxproj projects/openttd_vs100.vcxproj.filters projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/consist_func.h src/openttd.cpp src/saveload/consist_sl.cpp
diffstat 8 files changed, 116 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/projects/openttd_vs100.vcxproj
+++ b/projects/openttd_vs100.vcxproj
@@ -407,6 +407,7 @@
     <ClInclude Include="..\src\company_manager_face.h" />
     <ClInclude Include="..\src\company_type.h" />
     <ClInclude Include="..\src\consist_base.h" />
+    <ClInclude Include="..\src\consist_func.h" />
     <ClInclude Include="..\src\consist_type.h" />
     <ClInclude Include="..\src\console_func.h" />
     <ClInclude Include="..\src\console_gui.h" />
@@ -797,6 +798,7 @@
     <ClCompile Include="..\src\saveload\cargopacket_sl.cpp" />
     <ClCompile Include="..\src\saveload\cheat_sl.cpp" />
     <ClCompile Include="..\src\saveload\company_sl.cpp" />
+    <ClCompile Include="..\src\saveload\consist_sl.cpp" />
     <ClCompile Include="..\src\saveload\depot_sl.cpp" />
     <ClCompile Include="..\src\saveload\economy_sl.cpp" />
     <ClCompile Include="..\src\saveload\engine_sl.cpp" />
--- a/projects/openttd_vs100.vcxproj.filters
+++ b/projects/openttd_vs100.vcxproj.filters
@@ -450,6 +450,9 @@
     <ClInclude Include="..\src\consist_base.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\consist_func.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\consist_type.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -1620,6 +1623,9 @@
     <ClCompile Include="..\src\saveload\company_sl.cpp">
       <Filter>Save/Load handlers</Filter>
     </ClCompile>
+    <ClCompile Include="..\src\saveload\consist_sl.cpp">
+      <Filter>Save/Load handlers</Filter>
+    </ClCompile>
     <ClCompile Include="..\src\saveload\depot_sl.cpp">
       <Filter>Save/Load handlers</Filter>
     </ClCompile>
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -903,6 +903,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\consist_func.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\consist_type.h"
 				>
 			</File>
@@ -2483,6 +2487,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\saveload\consist_sl.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\saveload\depot_sl.cpp"
 				>
 			</File>
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -900,6 +900,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\consist_func.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\consist_type.h"
 				>
 			</File>
@@ -2480,6 +2484,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\saveload\consist_sl.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\saveload\depot_sl.cpp"
 				>
 			</File>
--- a/source.list
+++ b/source.list
@@ -140,6 +140,7 @@
 company_manager_face.h
 company_type.h
 consist_base.h
+consist_func.h
 consist_type.h
 console_func.h
 console_gui.h
@@ -555,6 +556,7 @@
 saveload/cargopacket_sl.cpp
 saveload/cheat_sl.cpp
 saveload/company_sl.cpp
+saveload/consist_sl.cpp
 saveload/depot_sl.cpp
 saveload/economy_sl.cpp
 saveload/engine_sl.cpp
new file mode 100644
--- /dev/null
+++ b/src/consist_func.h
@@ -0,0 +1,15 @@
+/* $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 <http://www.gnu.org/licenses/>.
+ */
+
+/** @file consist_func.h Functions related to consists. */
+
+#ifndef CONSIST_FUNC_H
+#define CONSIST_FUNC_H
+
+#endif /* CONSIST_FUNC_H */
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -60,6 +60,7 @@
 #include "game/game.hpp"
 #include "game/game_config.hpp"
 #include "town.h"
+#include "consist_base.h"
 
 
 
@@ -1145,6 +1146,23 @@
  */
 static void CheckCaches()
 {
+	Consist *cs;
+	FOR_ALL_CONSISTS(cs) {
+		if (cs->Front() != NULL) {
+			int part = 0;
+			for (const Vehicle *v = cs->Front(); v != NULL; v = v->Next(), part++) {
+				if (v->GetConsist() != cs) DEBUG(misc, 0, "Part %i of consist %i has wrong pointer", part, (int)cs->index);
+			}
+		} else {
+			DEBUG(misc, 0, "Consist %i is empty", (int)cs->index);
+		}
+	}
+	Vehicle *v2;
+	FOR_ALL_VEHICLES(v2) {
+		if (v2->IsPrimaryVehicle() && v2->GetConsist() == NULL) DEBUG(misc, 0, "Unit %i (vehicle %i) has NULL consist", v2->unitnumber, (int)v2->index);
+		if (v2->GetConsist() != NULL && v2->GetConsist()->Front() != v2->First()) DEBUG(misc, 0, "Vehicle %i wrongly references consist %i", (int)v2->index, (int)v2->GetConsist()->index);
+	}
+
 	/* Return here so it is easy to add checks that are run
 	 * always to aid testing of caches. */
 	if (_debug_desync_level <= 1) return;
new file mode 100644
--- /dev/null
+++ b/src/saveload/consist_sl.cpp
@@ -0,0 +1,57 @@
+/* $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 <http://www.gnu.org/licenses/>.
+ */
+
+/** @file vehicle_sl.cpp Code handling saving and loading of vehicles */
+
+#include "../stdafx.h"
+#include "../consist_base.h"
+
+#include "saveload.h"
+
+const SaveLoad *GetConsistDescription()
+{
+	static const SaveLoad _common_consist_desc[] = {
+		SLE_VAR(Consist, type,        SLE_UINT8),
+		SLE_END(),
+	};
+
+	return _common_consist_desc;
+}
+
+/** Will be called when the consists need to be saved. */
+static void Save_CNST()
+{
+	Consist *c;
+	FOR_ALL_CONSISTS(c) {
+		SlSetArrayIndex(c->index);
+		SlObject(c, GetConsistDescription());
+	}
+}
+
+/** Will be called when the consists need to be loaded. */
+static void Load_CNST()
+{
+	Consist *c;
+	FOR_ALL_CONSISTS(c) {
+		SlObject(c, GetConsistDescription());
+	}
+}
+
+/** Will be called after loading to fix up pointers in the consists.  */
+static void Ptrs_CNTS()
+{
+	Consist *c;
+	FOR_ALL_CONSISTS(c) {
+		SlObject(c, GetConsistDescription());
+	}
+}
+
+extern const ChunkHandler _consist_chunk_handlers[] = {
+	{ 'CNST', Save_CNST, Load_CNST, Ptrs_CNTS, NULL, CH_SPARSE_ARRAY | CH_LAST},
+};