mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Fix map startup
This commit is contained in:
parent
54103813dd
commit
2cc8b5baeb
@ -16,7 +16,7 @@
|
||||
#include "../campaign/CampaignState.h"
|
||||
#include "../mapping/CMapEditManager.h"
|
||||
#include "../mapObjects/CGHeroInstance.h"
|
||||
#include "../registerTypes/RegisterTypes.h"
|
||||
#include "../networkPacks/ArtifactLocation.h"
|
||||
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../StartInfo.h"
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
CFaction * faction;
|
||||
CFaction * faction = nullptr;
|
||||
h & faction;
|
||||
town = faction ? faction->town : nullptr;
|
||||
}
|
||||
|
@ -14,27 +14,16 @@
|
||||
#include "../networkPacks/PacksForServer.h"
|
||||
#include "../networkPacks/PacksForLobby.h"
|
||||
#include "../networkPacks/SetStackEffect.h"
|
||||
#include "../VCMI_Lib.h"
|
||||
#include "../CArtHandler.h"
|
||||
#include "../CCreatureSet.h"
|
||||
#include "../CPlayerState.h"
|
||||
#include "../CHeroHandler.h"
|
||||
#include "../CTownHandler.h"
|
||||
#include "../mapObjectConstructors/CRewardableConstructor.h"
|
||||
#include "../mapObjectConstructors/CommonConstructors.h"
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/DwellingInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/ShipyardInstanceConstructor.h"
|
||||
#include "../mapObjects/MapObjects.h"
|
||||
#include "../mapObjects/CGCreature.h"
|
||||
#include "../mapObjects/CGTownBuilding.h"
|
||||
#include "../mapObjects/ObjectTemplate.h"
|
||||
#include "../battle/CObstacleInstance.h"
|
||||
#include "../bonuses/CBonusSystemNode.h"
|
||||
#include "../bonuses/Limiters.h"
|
||||
#include "../bonuses/Updaters.h"
|
||||
#include "../bonuses/Propagators.h"
|
||||
#include "../CPlayerState.h"
|
||||
#include "../CStack.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
@ -234,6 +234,25 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
loadPointerImpl(data);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void loadPointerImpl(T &data)
|
||||
{
|
||||
using DataType = std::remove_pointer_t<T>;
|
||||
|
||||
typename DataType::IdentifierType index;
|
||||
load(index);
|
||||
|
||||
auto * constEntity = index.toEntity(VLC);
|
||||
auto * constData = dynamic_cast<const DataType *>(constEntity);
|
||||
data = const_cast<DataType *>(constData);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < !std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void loadPointerImpl(T &data)
|
||||
{
|
||||
if(reader->smartVectorMembersSerialization)
|
||||
{
|
||||
typedef typename std::remove_const<typename std::remove_pointer<T>::type>::type TObjectType; //eg: const CGHeroInstance * => CGHeroInstance
|
||||
@ -258,25 +277,6 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
loadPointerImpl(data);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void loadPointerImpl(T &data)
|
||||
{
|
||||
using DataType = std::remove_pointer_t<T>;
|
||||
|
||||
typename DataType::IdentifierType index;
|
||||
load(index);
|
||||
|
||||
auto * constEntity = index.toEntity(VLC);
|
||||
auto * constData = dynamic_cast<const DataType *>(constEntity);
|
||||
data = const_cast<DataType *>(constData);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < !std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void loadPointerImpl(T &data)
|
||||
{
|
||||
ui32 pid = 0xffffffff; //pointer id (or maybe rather pointee id)
|
||||
if(smartPointerSerialization)
|
||||
{
|
||||
@ -502,7 +502,7 @@ public:
|
||||
// use appropriate alternative for result
|
||||
data = table[which];
|
||||
// perform actual load via std::visit dispatch
|
||||
std::visit([this](auto& o) { load(o); }, data);
|
||||
std::visit([&](auto& o) { load(o); }, data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -181,6 +181,19 @@ public:
|
||||
if(!hlp)
|
||||
return;
|
||||
|
||||
savePointerImpl(data);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void savePointerImpl(const T &data)
|
||||
{
|
||||
auto index = data->getId();
|
||||
save(index);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < !std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void savePointerImpl(const T &data)
|
||||
{
|
||||
if(writer->smartVectorMembersSerialization)
|
||||
{
|
||||
typedef typename std::remove_const<typename std::remove_pointer<T>::type>::type TObjectType;
|
||||
@ -203,19 +216,6 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
savePointerImpl(data);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void savePointerImpl(const T &data)
|
||||
{
|
||||
auto index = data->getId();
|
||||
save(index);
|
||||
}
|
||||
|
||||
template < typename T, typename std::enable_if < !std::is_base_of_v<Entity, std::remove_pointer_t<T>>, int >::type = 0 >
|
||||
void savePointerImpl(const T &data)
|
||||
{
|
||||
if(smartPointerSerialization)
|
||||
{
|
||||
// We might have an object that has multiple inheritance and store it via the non-first base pointer.
|
||||
|
Loading…
Reference in New Issue
Block a user