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