2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* VCMI_Lib.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
|
|
|
|
#include "CArtHandler.h"
|
|
|
|
#include "CBonusTypeHandler.h"
|
|
|
|
#include "CCreatureHandler.h"
|
|
|
|
#include "CConfigHandler.h"
|
|
|
|
#include "RoadHandler.h"
|
|
|
|
#include "RiverHandler.h"
|
|
|
|
#include "TerrainHandler.h"
|
|
|
|
#include "spells/CSpellHandler.h"
|
|
|
|
#include "spells/effects/Registry.h"
|
|
|
|
#include "CSkillHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "entities/faction/CTownHandler.h"
|
2024-10-11 18:30:16 +02:00
|
|
|
#include "entities/hero/CHeroClassHandler.h"
|
|
|
|
#include "entities/hero/CHeroHandler.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "texts/CGeneralTextHandler.h"
|
2023-10-19 16:19:09 +02:00
|
|
|
#include "modding/CModHandler.h"
|
|
|
|
#include "modding/IdentifierStorage.h"
|
|
|
|
#include "modding/CModVersion.h"
|
|
|
|
#include "IGameEventsReceiver.h"
|
|
|
|
#include "CStopWatch.h"
|
|
|
|
#include "VCMIDirs.h"
|
|
|
|
#include "filesystem/Filesystem.h"
|
|
|
|
#include "CConsoleHandler.h"
|
|
|
|
#include "rmg/CRmgTemplateStorage.h"
|
|
|
|
#include "mapObjectConstructors/CObjectClassesHandler.h"
|
|
|
|
#include "mapObjects/CObjectHandler.h"
|
2024-04-04 21:39:01 +02:00
|
|
|
#include "mapObjects/ObstacleSetHandler.h"
|
2023-10-19 16:19:09 +02:00
|
|
|
#include "mapping/CMapEditManager.h"
|
|
|
|
#include "ScriptHandler.h"
|
|
|
|
#include "BattleFieldHandler.h"
|
|
|
|
#include "ObstacleHandler.h"
|
|
|
|
#include "GameSettings.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
LibClasses * VLC = nullptr;
|
|
|
|
|
2024-01-04 23:48:58 +02:00
|
|
|
DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool extractArchives)
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
console = Console;
|
|
|
|
VLC = new LibClasses();
|
|
|
|
VLC->loadFilesystem(extractArchives);
|
|
|
|
settings.init("config/settings.json", "vcmi:settings");
|
|
|
|
persistentStorage.init("config/persistentStorage.json", "");
|
2024-01-04 23:48:58 +02:00
|
|
|
VLC->loadModFilesystem();
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_LINKAGE void loadDLLClasses(bool onlyEssential)
|
|
|
|
{
|
|
|
|
VLC->init(onlyEssential);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArtifactService * LibClasses::artifacts() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return arth.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CreatureService * LibClasses::creatures() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return creh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const FactionService * LibClasses::factions() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return townh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const HeroClassService * LibClasses::heroClasses() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return heroclassesh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const HeroTypeService * LibClasses::heroTypes() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return heroh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if SCRIPTING_ENABLED
|
|
|
|
const scripting::Service * LibClasses::scripts() const
|
|
|
|
{
|
2024-01-10 21:30:12 +02:00
|
|
|
return scriptHandler.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const spells::Service * LibClasses::spells() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return spellh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const SkillService * LibClasses::skills() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return skillh.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const IBonusTypeHandler * LibClasses::getBth() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return bth.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CIdentifierStorage * LibClasses::identifiers() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return identifiersHandler.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const spells::effects::Registry * LibClasses::spellEffects() const
|
|
|
|
{
|
|
|
|
return spells::effects::GlobalRegistry::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
spells::effects::Registry * LibClasses::spellEffects()
|
|
|
|
{
|
|
|
|
return spells::effects::GlobalRegistry::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const BattleFieldService * LibClasses::battlefields() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return battlefieldsHandler.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const ObstacleService * LibClasses::obstacles() const
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return obstacleHandler.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
2024-08-31 13:00:36 +02:00
|
|
|
const IGameSettings * LibClasses::engineSettings() const
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
return settingsHandler.get();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::loadFilesystem(bool extractArchives)
|
|
|
|
{
|
|
|
|
CStopWatch loadTime;
|
|
|
|
|
|
|
|
CResourceHandler::initialize();
|
|
|
|
logGlobal->info("\tInitialization: %d ms", loadTime.getDiff());
|
|
|
|
|
|
|
|
CResourceHandler::load("config/filesystem.json", extractArchives);
|
|
|
|
logGlobal->info("\tData loading: %d ms", loadTime.getDiff());
|
|
|
|
}
|
|
|
|
|
2024-01-04 23:48:58 +02:00
|
|
|
void LibClasses::loadModFilesystem()
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
CStopWatch loadTime;
|
2023-12-31 23:43:35 +02:00
|
|
|
modh = std::make_unique<CModHandler>();
|
|
|
|
identifiersHandler = std::make_unique<CIdentifierStorage>();
|
2023-10-19 16:19:09 +02:00
|
|
|
logGlobal->info("\tMod handler: %d ms", loadTime.getDiff());
|
|
|
|
|
|
|
|
modh->loadModFilesystems();
|
|
|
|
logGlobal->info("\tMod filesystems: %d ms", loadTime.getDiff());
|
|
|
|
}
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
template <class Handler> void createHandler(std::shared_ptr<Handler> & handler)
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
handler = std::make_shared<Handler>();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::init(bool onlyEssential)
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
createHandler(settingsHandler);
|
2023-10-19 16:19:09 +02:00
|
|
|
modh->initializeConfig();
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
createHandler(generaltexth);
|
|
|
|
createHandler(bth);
|
|
|
|
createHandler(roadTypeHandler);
|
|
|
|
createHandler(riverTypeHandler);
|
|
|
|
createHandler(terrainTypeHandler);
|
|
|
|
createHandler(heroh);
|
|
|
|
createHandler(heroclassesh);
|
|
|
|
createHandler(arth);
|
|
|
|
createHandler(creh);
|
|
|
|
createHandler(townh);
|
|
|
|
createHandler(biomeHandler);
|
|
|
|
createHandler(objh);
|
|
|
|
createHandler(objtypeh);
|
|
|
|
createHandler(spellh);
|
|
|
|
createHandler(skillh);
|
|
|
|
createHandler(terviewh);
|
|
|
|
createHandler(tplh); //templates need already resolved identifiers (refactor?)
|
2023-10-19 16:19:09 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
2024-11-12 22:00:21 +02:00
|
|
|
createHandler(scriptHandler);
|
2023-10-19 16:19:09 +02:00
|
|
|
#endif
|
2024-11-12 22:00:21 +02:00
|
|
|
createHandler(battlefieldsHandler);
|
|
|
|
createHandler(obstacleHandler);
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
modh->load();
|
|
|
|
modh->afterLoad(onlyEssential);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SCRIPTING_ENABLED
|
|
|
|
void LibClasses::scriptsLoaded()
|
|
|
|
{
|
|
|
|
scriptHandler->performRegistration(this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-12-31 23:43:35 +02:00
|
|
|
LibClasses::LibClasses() = default;
|
|
|
|
LibClasses::~LibClasses() = default;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CContentHandler> LibClasses::getContent() const
|
|
|
|
{
|
|
|
|
return modh->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::setContent(std::shared_ptr<CContentHandler> content)
|
|
|
|
{
|
|
|
|
modh->content = std::move(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|