#include <iostream>
#include <Ogre.h>
#include <OgreCodec.h>
#include <OgreFileSystem.h>
#include <OgreFileSystemLayer.h>
#include <OgreMaterialManager.h>
#include <OgreShaderGenerator.h>

int main()
{
	Ogre::LogManager logMgr;
	logMgr.createLog("messages.log", true, true, true);
	Ogre::DefaultHardwareBufferManager
		bufferManager; // needed because we don't have a rendersystem
	Ogre::Root *ogre = new Ogre::Root("", "", "");
	Ogre::ConfigFile pluginsCfg;
	Ogre::FileSystemLayer fsLayer("Ogre3D");
	pluginsCfg.load(fsLayer.getConfigFilePath("plugins.cfg"));

	auto pluginDir = Ogre::FileSystemLayer::resolveBundlePath(
		pluginsCfg.getSetting("PluginFolder") + "/");
	ogre->loadPlugin(pluginDir + "/Codec_Assimp");
	ogre->loadPlugin(pluginDir + "/Plugin_DotScene");
	Ogre::MaterialManager::getSingleton().initialise();
	Ogre::RTShader::ShaderGenerator::initialize();
	Ogre::DefaultTextureManager texMgr;

	auto &shadergen = Ogre::RTShader::ShaderGenerator::getSingleton();
	shadergen.setTargetLanguage(
		"glsl"); // must be valid, but otherwise arbitrary
	shadergen.getRenderState(Ogre::MSN_SHADERGEN)
		->setLightCountAutoUpdate(false);
	shadergen.validateScheme(Ogre::MSN_SHADERGEN);
	Ogre::SceneManager *sceneManager =
		ogre->createSceneManager("DefaultSceneManager");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resources/vehicles", "FileSystem", "Generic", true, true);
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"../resources/vehicles", "FileSystem", "Generic", true, true);
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"../../resources/vehicles", "FileSystem", "Generic", true,
		true);
	std::map<Ogre::String, Ogre::Any> options;
	options["prefix"] = Ogre::String("0/");
	Ogre::SceneNode *p1 =
		sceneManager->getRootSceneNode()->createChildSceneNode();
	Ogre::Any optionsAny1 = options;
	p1->getUserObjectBindings().setUserAny("_DotSceneLoaderOptions",
					       optionsAny1);
	p1->loadChildren("boat.scene");
	options["prefix"] = Ogre::String("1/");
	Ogre::SceneNode *p2 =
		sceneManager->getRootSceneNode()->createChildSceneNode();
	Ogre::Any optionsAny2 = options;
	p2->getUserObjectBindings().setUserAny("_DotSceneLoaderOptions",
					       optionsAny2);
	p2->loadChildren("boat.scene");
	//	Ogre::DataStreamPtr sceneData =
	//		Ogre::ResourceGroupManager::getSingleton().openResource(
	//			"boat.scene", "General");
	//	auto codec = Ogre::Codec::getCodec("scene");
	//	codec->decode(sceneData, sceneManager->getRootSceneNode());
	return 0;
}
