mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
switch CMapService API to ResourceID
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "NetPacks.h"
|
#include "NetPacks.h"
|
||||||
#include "registerTypes/RegisterTypes.h"
|
#include "registerTypes/RegisterTypes.h"
|
||||||
#include "mapping/CMapInfo.h"
|
|
||||||
#include "BattleInfo.h"
|
#include "BattleInfo.h"
|
||||||
#include "JsonNode.h"
|
#include "JsonNode.h"
|
||||||
#include "filesystem/Filesystem.h"
|
#include "filesystem/Filesystem.h"
|
||||||
@@ -840,7 +839,8 @@ void CGameState::initNewGame(bool allowSavingRandomMap)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
logGlobal->infoStream() << "Open map file: " << scenarioOps->mapname;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CMapInfo.h"
|
#include "CMapInfo.h"
|
||||||
|
|
||||||
|
#include "../filesystem/ResourceID.h"
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../GameConstants.h"
|
#include "../GameConstants.h"
|
||||||
#include "CMapService.h"
|
#include "CMapService.h"
|
||||||
@@ -58,7 +59,7 @@ CMapInfo::~CMapInfo()
|
|||||||
void CMapInfo::mapInit(const std::string & fname)
|
void CMapInfo::mapInit(const std::string & fname)
|
||||||
{
|
{
|
||||||
fileURI = fname;
|
fileURI = fname;
|
||||||
mapHeader = CMapService::loadMapHeader(fname);
|
mapHeader = CMapService::loadMapHeader(ResourceID(fname, EResType::MAP));
|
||||||
countPlayers();
|
countPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,3 +82,4 @@ CMapInfo & CMapInfo::operator=(CMapInfo &&tmp)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef STEAL
|
||||||
|
@@ -13,24 +13,16 @@
|
|||||||
#include "MapFormatJson.h"
|
#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);
|
auto stream = getStreamFromFS(name);
|
||||||
std::unique_ptr<CMap> map(getMapLoader(stream)->loadMap());
|
return getMapLoader(stream)->loadMap();
|
||||||
std::unique_ptr<CMapHeader> header(map.get());
|
|
||||||
|
|
||||||
getMapPatcher(name)->patchMapHeader(header);
|
|
||||||
header.release();
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
|
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ResourceID & name)
|
||||||
{
|
{
|
||||||
auto stream = getStreamFromFS(name);
|
auto stream = getStreamFromFS(name);
|
||||||
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
|
return getMapLoader(stream)->loadMapHeader();
|
||||||
getMapPatcher(name)->patchMapHeader(header);
|
|
||||||
return header;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const std::string & name)
|
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<CMap> map(getMapLoader(stream)->loadMap());
|
||||||
std::unique_ptr<CMapHeader> header(map.get());
|
std::unique_ptr<CMapHeader> header(map.get());
|
||||||
|
|
||||||
|
//might be original campaign and require patch
|
||||||
getMapPatcher(name)->patchMapHeader(header);
|
getMapPatcher(name)->patchMapHeader(header);
|
||||||
header.release();
|
header.release();
|
||||||
|
|
||||||
@@ -49,6 +42,8 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int s
|
|||||||
{
|
{
|
||||||
auto stream = getStreamFromMem(buffer, size);
|
auto stream = getStreamFromMem(buffer, size);
|
||||||
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
|
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
|
||||||
|
|
||||||
|
//might be original campaign and require patch
|
||||||
getMapPatcher(name)->patchMapHeader(header);
|
getMapPatcher(name)->patchMapHeader(header);
|
||||||
return 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)
|
std::unique_ptr<CInputStream> CMapService::getStreamFromMem(const ui8 * buffer, int size)
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
class ResourceID;
|
||||||
|
|
||||||
class CMap;
|
class CMap;
|
||||||
class CMapHeader;
|
class CMapHeader;
|
||||||
class CInputStream;
|
class CInputStream;
|
||||||
@@ -31,7 +33,7 @@ public:
|
|||||||
* @param name the name of the map
|
* @param name the name of the map
|
||||||
* @return a unique ptr to the loaded map class
|
* @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.
|
* Loads the VCMI/H3 map header specified by the name.
|
||||||
@@ -39,7 +41,7 @@ public:
|
|||||||
* @param name the name of the map
|
* @param name the name of the map
|
||||||
* @return a unique ptr to the loaded map header class
|
* @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
|
* 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
|
* @param name the name of the map
|
||||||
* @return a unique ptr to the input stream class
|
* @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.
|
* Gets a map input stream from a buffer.
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CGameState.h"
|
#include "../CGameState.h"
|
||||||
#include "../mapping/CMap.h"
|
#include "../mapping/CMap.h"
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CStack.h"
|
#include "../CStack.h"
|
||||||
#include "../BattleInfo.h"
|
#include "../BattleInfo.h"
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CGameState.h"
|
#include "../CGameState.h"
|
||||||
#include "../mapping/CMap.h"
|
#include "../mapping/CMap.h"
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CStack.h"
|
#include "../CStack.h"
|
||||||
#include "../BattleInfo.h"
|
#include "../BattleInfo.h"
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CGameState.h"
|
#include "../CGameState.h"
|
||||||
#include "../mapping/CMap.h"
|
#include "../mapping/CMap.h"
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
|
|
||||||
#include "../mapping/CMapInfo.h"
|
|
||||||
#include "../StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "../CGameState.h"
|
#include "../CGameState.h"
|
||||||
#include "../mapping/CMap.h"
|
#include "../mapping/CMap.h"
|
||||||
|
@@ -74,7 +74,6 @@ public:
|
|||||||
std::list<CPackForSelectionScreen*> toAnnounce;
|
std::list<CPackForSelectionScreen*> toAnnounce;
|
||||||
boost::recursive_mutex mx;
|
boost::recursive_mutex mx;
|
||||||
|
|
||||||
//std::vector<CMapInfo> maps;
|
|
||||||
TAcceptor *acceptor;
|
TAcceptor *acceptor;
|
||||||
TSocket *upcomingConnection;
|
TSocket *upcomingConnection;
|
||||||
|
|
||||||
|
@@ -115,9 +115,10 @@ BOOST_AUTO_TEST_CASE(CMapEditManager_DrawTerrain_View)
|
|||||||
logGlobal->info("CMapEditManager_DrawTerrain_View start");
|
logGlobal->info("CMapEditManager_DrawTerrain_View start");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const ResourceID testMap("test/TerrainViewTest", EResType::MAP);
|
||||||
// Load maps and json config
|
// Load maps and json config
|
||||||
const auto originalMap = CMapService::loadMap("test/TerrainViewTest");
|
const auto originalMap = CMapService::loadMap(testMap);
|
||||||
auto map = CMapService::loadMap("test/TerrainViewTest");
|
auto map = CMapService::loadMap(testMap);
|
||||||
logGlobal->info("Loaded test map successfully.");
|
logGlobal->info("Loaded test map successfully.");
|
||||||
|
|
||||||
// Validate edit manager
|
// Validate edit manager
|
||||||
|
Reference in New Issue
Block a user