浏览代码

switch CMapService API to ResourceID

AlexVinS 8 年之前
父节点
当前提交
c82afe7156

+ 2 - 2
lib/CGameState.cpp

@@ -16,7 +16,6 @@
 #include "StartInfo.h"
 #include "NetPacks.h"
 #include "registerTypes/RegisterTypes.h"
-#include "mapping/CMapInfo.h"
 #include "BattleInfo.h"
 #include "JsonNode.h"
 #include "filesystem/Filesystem.h"
@@ -840,7 +839,8 @@ void CGameState::initNewGame(bool allowSavingRandomMap)
 	else
 	{
 		logGlobal->infoStream() << "Open map file: " << scenarioOps->mapname;
-		map = CMapService::loadMap(scenarioOps->mapname).release();
+		const ResourceID mapURI(scenarioOps->mapname, EResType::MAP);
+		map = CMapService::loadMap(mapURI).release();
 	}
 }
 

+ 3 - 1
lib/mapping/CMapInfo.cpp

@@ -1,6 +1,7 @@
 #include "StdInc.h"
 #include "CMapInfo.h"
 
+#include "../filesystem/ResourceID.h"
 #include "../StartInfo.h"
 #include "../GameConstants.h"
 #include "CMapService.h"
@@ -58,7 +59,7 @@ CMapInfo::~CMapInfo()
 void CMapInfo::mapInit(const std::string & fname)
 {
 	fileURI = fname;
-	mapHeader = CMapService::loadMapHeader(fname);
+	mapHeader = CMapService::loadMapHeader(ResourceID(fname, EResType::MAP));
 	countPlayers();
 }
 
@@ -81,3 +82,4 @@ CMapInfo & CMapInfo::operator=(CMapInfo &&tmp)
 	return *this;
 }
 
+#undef STEAL

+ 9 - 14
lib/mapping/CMapService.cpp

@@ -13,24 +13,16 @@
 #include "MapFormatJson.h"
 
 
-std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
+std::unique_ptr<CMap> CMapService::loadMap(const ResourceID & name)
 {
 	auto stream = getStreamFromFS(name);
-	std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
-	std::unique_ptr<CMapHeader> header(map.get());
-
-	getMapPatcher(name)->patchMapHeader(header);
-	header.release();
-
-	return map;
+	return getMapLoader(stream)->loadMap();
 }
 
-std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
+std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ResourceID & name)
 {
 	auto stream = getStreamFromFS(name);
-	std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
-	getMapPatcher(name)->patchMapHeader(header);
-	return header;
+	return getMapLoader(stream)->loadMapHeader();
 }
 
 std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const std::string & name)
@@ -39,6 +31,7 @@ std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const s
 	std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
 	std::unique_ptr<CMapHeader> header(map.get());
 
+	//might be original campaign and require patch
 	getMapPatcher(name)->patchMapHeader(header);
 	header.release();
 
@@ -49,6 +42,8 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int s
 {
 	auto stream = getStreamFromMem(buffer, size);
 	std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
+
+	//might be original campaign and require patch
 	getMapPatcher(name)->patchMapHeader(header);
 	return header;
 }
@@ -70,9 +65,9 @@ void CMapService::saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::
 	}
 }
 
-std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)
+std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const ResourceID & name)
 {
-	return CResourceHandler::get()->load(ResourceID(name, EResType::MAP));
+	return CResourceHandler::get()->load(name);
 }
 
 std::unique_ptr<CInputStream> CMapService::getStreamFromMem(const ui8 * buffer, int size)

+ 5 - 3
lib/mapping/CMapService.h

@@ -11,6 +11,8 @@
 
 #pragma once
 
+class ResourceID;
+
 class CMap;
 class CMapHeader;
 class CInputStream;
@@ -31,7 +33,7 @@ public:
 	 * @param name the name of the map
 	 * @return a unique ptr to the loaded map class
 	 */
-	static std::unique_ptr<CMap> loadMap(const std::string & name);
+	static std::unique_ptr<CMap> loadMap(const ResourceID & name);
 
 	/**
 	 * Loads the VCMI/H3 map header specified by the name.
@@ -39,7 +41,7 @@ public:
 	 * @param name the name of the map
 	 * @return a unique ptr to the loaded map header class
 	 */
-	static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
+	static std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name);
 
 	/**
 	 * Loads the VCMI/H3 map file from a buffer. This method is temporarily
@@ -77,7 +79,7 @@ private:
 	 * @param name the name of the map
 	 * @return a unique ptr to the input stream class
 	 */
-	static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
+	static std::unique_ptr<CInputStream> getStreamFromFS(const ResourceID & name);
 
 	/**
 	 * Gets a map input stream from a buffer.

+ 0 - 1
lib/registerTypes/TypesClientPacks1.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CGameState.h"
 #include "../mapping/CMap.h"

+ 0 - 1
lib/registerTypes/TypesClientPacks2.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CStack.h"
 #include "../BattleInfo.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects1.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CGameState.h"
 #include "../mapping/CMap.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects2.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CStack.h"
 #include "../BattleInfo.h"

+ 0 - 1
lib/registerTypes/TypesMapObjects3.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CGameState.h"
 #include "../mapping/CMap.h"

+ 0 - 1
lib/registerTypes/TypesServerPacks.cpp

@@ -1,7 +1,6 @@
 #include "StdInc.h"
 #include "RegisterTypes.h"
 
-#include "../mapping/CMapInfo.h"
 #include "../StartInfo.h"
 #include "../CGameState.h"
 #include "../mapping/CMap.h"

+ 0 - 1
server/CVCMIServer.h

@@ -74,7 +74,6 @@ public:
 	std::list<CPackForSelectionScreen*> toAnnounce;
 	boost::recursive_mutex mx;
 
-	//std::vector<CMapInfo> maps;
 	TAcceptor *acceptor;
 	TSocket *upcomingConnection;
 

+ 3 - 2
test/CMapEditManagerTest.cpp

@@ -115,9 +115,10 @@ BOOST_AUTO_TEST_CASE(CMapEditManager_DrawTerrain_View)
 	logGlobal->info("CMapEditManager_DrawTerrain_View start");
 	try
 	{
+		const ResourceID testMap("test/TerrainViewTest", EResType::MAP);
 		// Load maps and json config
-		const auto originalMap = CMapService::loadMap("test/TerrainViewTest");
-		auto map = CMapService::loadMap("test/TerrainViewTest");
+		const auto originalMap = CMapService::loadMap(testMap);
+		auto map = CMapService::loadMap(testMap);
 		logGlobal->info("Loaded test map successfully.");
 
 		// Validate edit manager