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"
|
|
|
|
#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 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"
|
2012-08-01 12:02:54 +00:00
|
|
|
#include "Filesystem/CResourceLoader.h"
|
2009-04-15 14:03:31 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-14 10:20:18 +00:00
|
|
|
LibClasses * VLC = NULL;
|
2009-05-09 16:18:27 +00:00
|
|
|
|
2012-05-25 14:53:56 +00:00
|
|
|
DLL_LINKAGE VCMIDirs GVCMIDirs;
|
2012-05-25 11:49:56 +00:00
|
|
|
|
2010-08-22 07:11:46 +00:00
|
|
|
|
2011-12-13 21:23:17 +00:00
|
|
|
DLL_LINKAGE void initDLL(CConsoleHandler *Console, std::ostream *Logfile)
|
2008-06-14 10:20:18 +00:00
|
|
|
{
|
2008-09-17 10:18:22 +00:00
|
|
|
console = Console;
|
|
|
|
logfile = Logfile;
|
2008-06-14 10:20:18 +00:00
|
|
|
VLC = new LibClasses;
|
2012-08-25 13:29:46 +00:00
|
|
|
try
|
2009-05-21 23:50:45 +00:00
|
|
|
{
|
|
|
|
VLC->init();
|
2011-12-13 21:23:17 +00:00
|
|
|
}
|
2012-08-25 13:29:46 +00:00
|
|
|
HANDLE_EXCEPTION;
|
2008-06-14 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2012-08-07 11:28:52 +00:00
|
|
|
tlog0<<"\t Initialization: "<<loadTime.getDiff()<<std::endl;
|
|
|
|
|
2012-08-01 12:02:54 +00:00
|
|
|
CResourceHandler::loadFileSystem("ALL/config/filesystem.json");
|
2012-08-07 11:28:52 +00:00
|
|
|
tlog0<<"\t Data loading: "<<loadTime.getDiff()<<std::endl;
|
|
|
|
|
2012-08-01 12:02:54 +00:00
|
|
|
CResourceHandler::loadModsFilesystems();
|
2012-08-07 11:28:52 +00:00
|
|
|
tlog0<<"\t Mod filesystems: "<<loadTime.getDiff()<<std::endl;
|
2012-08-01 12:02:54 +00:00
|
|
|
|
2012-08-07 11:28:52 +00:00
|
|
|
tlog0<<"File system handler: "<<totalTime.getDiff()<<std::endl;
|
2012-08-02 11:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::init()
|
|
|
|
{
|
|
|
|
CStopWatch pomtime;
|
2012-08-01 12:02:54 +00:00
|
|
|
|
2012-08-10 13:07:53 +00:00
|
|
|
modh = new CModHandler; //TODO: all handlers should use mod handler to manage objects
|
|
|
|
tlog0<<"\tMod handler: "<<pomtime.getDiff()<<std::endl;
|
|
|
|
|
2009-01-10 22:08:18 +00:00
|
|
|
generaltexth = new CGeneralTextHandler;
|
|
|
|
generaltexth->load();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tGeneral text handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
heroh = new CHeroHandler;
|
|
|
|
heroh->loadHeroes();
|
2009-02-07 16:07:29 +00:00
|
|
|
heroh->loadObstacles();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0 <<"\tHero handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
arth = new CArtHandler;
|
2009-01-12 20:05:56 +00:00
|
|
|
arth->loadArtifacts(false);
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tArtifact handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
creh = new CCreatureHandler();
|
|
|
|
creh->loadCreatures();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tCreature handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
townh = new CTownHandler;
|
2012-09-02 10:33:41 +00:00
|
|
|
townh->load();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tTown handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
objh = new CObjectHandler;
|
|
|
|
objh->loadObjects();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tObject handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
dobjinfo = new CDefObjInfoHandler;
|
|
|
|
dobjinfo->load();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tDef information handler: "<<pomtime.getDiff()<<std::endl;
|
2009-01-10 22:08:18 +00:00
|
|
|
|
|
|
|
spellh = new CSpellHandler;
|
|
|
|
spellh->loadSpells();
|
2011-12-13 21:23:17 +00:00
|
|
|
tlog0<<"\tSpell handler: "<<pomtime.getDiff()<<std::endl;
|
2010-11-28 16:39:13 +00:00
|
|
|
|
2012-09-18 07:36:07 +00:00
|
|
|
modh->recreateHandlers(); //load all new creatures parsed in the meantime.
|
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;
|
|
|
|
delete dobjinfo;
|
|
|
|
delete spellh;
|
2012-08-10 13:07:53 +00:00
|
|
|
delete modh;
|
2009-06-23 08:14:49 +00:00
|
|
|
makeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::makeNull()
|
|
|
|
{
|
2009-01-10 22:08:18 +00:00
|
|
|
generaltexth = NULL;
|
|
|
|
heroh = NULL;
|
|
|
|
arth = NULL;
|
|
|
|
creh = NULL;
|
|
|
|
townh = NULL;
|
|
|
|
objh = NULL;
|
|
|
|
dobjinfo = NULL;
|
|
|
|
spellh = NULL;
|
2012-08-10 13:07:53 +00:00
|
|
|
modh = NULL;
|
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()
|
|
|
|
{
|
|
|
|
generaltexth = new CGeneralTextHandler;
|
|
|
|
generaltexth->load();
|
|
|
|
arth->loadArtifacts(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();
|
|
|
|
}
|