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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "CDefObjInfoHandler.h"
|
|
|
|
#include "CHeroHandler.h"
|
|
|
|
#include "CObjectHandler.h"
|
|
|
|
#include "CTownHandler.h"
|
|
|
|
#include "CBuildingHandler.h"
|
|
|
|
#include "CSpellHandler.h"
|
|
|
|
#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-04-07 13:48:07 +03:00
|
|
|
#include "filesystem/CResourceLoader.h"
|
2013-04-11 18:58:01 +03:00
|
|
|
#include "CConsoleHandler.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;
|
2012-12-12 14:13:57 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
VLC->loadFilesystem();
|
|
|
|
}
|
|
|
|
HANDLE_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_LINKAGE void loadDLLClasses()
|
|
|
|
{
|
2012-08-25 16:29:46 +03:00
|
|
|
try
|
2009-05-22 02:50:45 +03:00
|
|
|
{
|
|
|
|
VLC->init();
|
2011-12-14 00:23:17 +03:00
|
|
|
}
|
2012-08-25 16:29:46 +03:00
|
|
|
HANDLE_EXCEPTION;
|
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();
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->infoStream()<<"\t Initialization: "<<loadTime.getDiff();
|
2012-08-07 14:28:52 +03:00
|
|
|
|
2013-01-16 17:28:49 +03:00
|
|
|
CResourceHandler::loadFileSystem("", "ALL/config/filesystem.json");
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->infoStream()<<"\t Data loading: "<<loadTime.getDiff();
|
2012-08-07 14:28:52 +03:00
|
|
|
|
2012-12-12 14:13:57 +03:00
|
|
|
modh = new CModHandler;
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->infoStream()<<"\tMod handler: "<<loadTime.getDiff();
|
2012-12-12 14:13:57 +03:00
|
|
|
|
|
|
|
modh->initialize(CResourceHandler::getAvailableMods());
|
|
|
|
CResourceHandler::setActiveMods(modh->getActiveMods());
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->infoStream()<<"\t Mod filesystems: "<<loadTime.getDiff();
|
2012-08-01 15:02:54 +03:00
|
|
|
|
2013-04-09 17:31:36 +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);
|
|
|
|
}
|
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-04-28 18:06:14 +03:00
|
|
|
modh->beforeLoad();
|
|
|
|
|
2013-03-06 21:49:56 +03:00
|
|
|
createHandler(bth, "Bonus type", pomtime);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
createHandler(objh, "Object", pomtime);
|
|
|
|
|
|
|
|
createHandler(dobjinfo, "Def 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-05-30 15:14:39 +03:00
|
|
|
logGlobal->infoStream()<<"\tInitializing handlers: "<< totalTime.getDiff();
|
2013-04-21 15:49:26 +03:00
|
|
|
|
|
|
|
modh->loadGameContent();
|
2012-11-13 14:52:23 +03:00
|
|
|
modh->reload();
|
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;
|
|
|
|
delete dobjinfo;
|
|
|
|
delete spellh;
|
2012-08-10 16:07:53 +03:00
|
|
|
delete modh;
|
2013-03-06 21:49:56 +03:00
|
|
|
delete bth;
|
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;
|
|
|
|
dobjinfo = nullptr;
|
|
|
|
spellh = nullptr;
|
|
|
|
modh = nullptr;
|
|
|
|
bth = 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
|
|
|
}
|