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