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