1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-30 08:57:00 +02:00
vcmi/lib/VCMI_Lib.cpp

185 lines
4.0 KiB
C++
Raw Normal View History

/*
* 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"
2008-06-14 13:20:18 +03:00
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CBonusTypeHandler.h"
#include "CCreatureHandler.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CHeroHandler.h"
#include "mapObjects/CObjectHandler.h"
#include "CTownHandler.h"
#include "CBuildingHandler.h"
#include "spells/CSpellHandler.h"
#include "CGeneralTextHandler.h"
#include "CModHandler.h"
#include "IGameEventsReceiver.h"
#include "CStopWatch.h"
#include "VCMIDirs.h"
#include "filesystem/Filesystem.h"
#include "CConsoleHandler.h"
#include "rmg/CRmgTemplateStorage.h"
#include "mapping/CMapEditManager.h"
LibClasses * VLC = nullptr;
DLL_LINKAGE void preinitDLL(CConsoleHandler *Console)
2008-06-14 13:20:18 +03:00
{
console = Console;
2008-06-14 13:20:18 +03:00
VLC = new LibClasses;
try
{
VLC->loadFilesystem();
}
2015-02-14 21:42:47 +02:00
catch(...)
{
handleException();
throw;
}
}
DLL_LINKAGE void loadDLLClasses()
{
2015-02-14 21:42:47 +02:00
VLC->init();
2008-06-14 13:20:18 +03:00
}
const IBonusTypeHandler * LibClasses::getBth() const
{
return bth;
}
void LibClasses::loadFilesystem()
{
CStopWatch totalTime;
CStopWatch loadTime;
CResourceHandler::initialize();
logGlobal->infoStream()<<"\tInitialization: "<<loadTime.getDiff();
CResourceHandler::load("config/filesystem.json");
logGlobal->infoStream()<<"\tData loading: "<<loadTime.getDiff();
2016-08-30 10:45:05 +02:00
modh = new CModHandler();
logGlobal->infoStream()<<"\tMod handler: "<<loadTime.getDiff();
modh->loadMods();
modh->loadModFilesystems();
logGlobal->infoStream()<<"\tMod filesystems: "<<loadTime.getDiff();
logGlobal->infoStream()<<"Basic initialization: "<<totalTime.getDiff();
}
static void logHandlerLoaded(const std::string& name, CStopWatch &timer)
{
logGlobal->infoStream()<<"\t\t" << name << " handler: "<<timer.getDiff();
};
template <class Handler> void createHandler(Handler *&handler, const std::string &name, CStopWatch &timer)
{
handler = new Handler();
logHandlerLoaded(name, timer);
}
void LibClasses::init()
{
CStopWatch pomtime, totalTime;
modh->initializeConfig();
createHandler(bth, "Bonus type", pomtime);
createHandler(generaltexth, "General text", pomtime);
createHandler(heroh, "Hero", pomtime);
createHandler(arth, "Artifact", pomtime);
createHandler(creh, "Creature", pomtime);
createHandler(townh, "Town", pomtime);
createHandler(objh, "Object", pomtime);
createHandler(objtypeh, "Object types information", pomtime);
createHandler(spellh, "Spell", pomtime);
createHandler(terviewh, "Terrain view pattern", pomtime);
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
2013-05-30 15:14:39 +03:00
logGlobal->infoStream()<<"\tInitializing handlers: "<< totalTime.getDiff();
modh->load();
modh->afterLoad();
//FIXME: make sure that everything is ok after game restart
//TODO: This should be done every time mod config changes
2010-12-29 23:04:22 +02:00
IS_AI_ENABLED = false;
}
void LibClasses::clear()
{
delete generaltexth;
delete heroh;
delete arth;
delete creh;
delete townh;
delete objh;
delete objtypeh;
delete spellh;
delete modh;
delete bth;
delete tplh;
delete terviewh;
makeNull();
}
void LibClasses::makeNull()
{
generaltexth = nullptr;
heroh = nullptr;
arth = nullptr;
creh = nullptr;
townh = nullptr;
objh = nullptr;
objtypeh = nullptr;
spellh = nullptr;
modh = nullptr;
bth = nullptr;
tplh = nullptr;
terviewh = nullptr;
}
LibClasses::LibClasses()
{
//init pointers to handlers
makeNull();
}
void LibClasses::callWhenDeserializing()
{
// FIXME: check if any of these are needed
//generaltexth = new CGeneralTextHandler;
//generaltexth->load();
//arth->load(true);
//modh->recreateHandlers();
2012-08-24 12:37:52 +03:00
//modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
}
LibClasses::~LibClasses()
{
clear();
}