#include "core/system/Precompiled.h" #include #include "core/serialization/TextSerializer.h" #include "core/DefaultTask.h" #include "core/container/SphereTree.h" #include "resources/ResourceBufferFactory.h" #include "resources/AIResource.h" #include "scene/material/LightingMaterial.h" #include "scene/render/renderEffects/DefaultEffect.h" #include "scene/render/renderEffects/DebugEffect.h" #include "scene/render/renderEffects/DebugPhysics.h" #include "scene/actiontrigger/ActionManager.h" #include "scene/physics/PhysicalWorld.h" #include "gui/GUIManager.h" #include "gui/FXPlayStream.h" #include "ai/agentsystem/AgentManager.h" #include "ai/agentsystem/AIController.h" #include "module/EngineModule.h" #include "gameplay/GameManager.h" #include "resources/SoundResource.h" #include "scene/node/SphereTreeCollector.h" namespace FlowEngine { class A; class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; Vector vector_test; C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; vector_test.push_back(1); vector_test.push_back(1.2f); vector_test.push_back(1.3f); vector_test.push_back(1.4f); } template void Serialize(Archive& ar, const unsigned int version) { ar.template register_type(); ar.Serialize(dasse); ar.Serialize(text); //ar & m_owner); //ar & vector_test); } void Serialize(IArchive& ar, const unsigned int version) { serialize(ar, version); } }; class A: public Serializer { typedef Serializer Parent; public: int dumbi; float dumbf; Vector2f vectorTest; Matrix33 matrix; C* testing; Vector3f* test_void; A():dumbi(12), dumbf(69.69f) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); } A(int dumb1, float dumb2) : dumbi(dumb1), dumbf(dumb2) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); } template void Serialize(Archive& ar, const unsigned int version) { ar.Serialize(dumbi); //ar & vectorTest; //ar & matrix; //ar.Serialize(testing); //ar & (void*)test_void, sizeof(Vector3f); } void Serialize(IArchive& ar, const unsigned int version) { serialize(ar, version); } }; class B : public A { typedef A Parent; private: int dumbBi; float dumbBf; public: B():dumbBi(9), dumbBf(0.9876f) { } template void Serialize(Archive& ar, const unsigned int version) { //ar & boost::serialization::base_object(*this); //ar.Serialize(Parent); ar.Serialize(dumbBi); ar.Serialize(dumbBf); } void Serialize(IArchive& ar, const unsigned int version) { serialize(ar, version); } }; class SilvTask : public DefaultTask { private: typedef DefaultTask Parent; int dumbi; float dumbf; A testA; A* testAPointer; bool m_save, m_xml; std::string m_filename; public: SilvTask():m_save(false), dumbf(69.69f), dumbi(7), m_xml(false),testAPointer(0) { } int SilvTask::ParseArguments(const std::vector& args) { for(uint32 i = 0; i < (uint32)args.size(); i++) { if(args[i].find("-xml") != std::string::npos) m_xml = true; if(args[i].find("-save=") != std::string::npos) { m_filename = args[i].substr(6); m_save = true; } else if(args[i].find("-load=") != std::string::npos) { m_filename = args[i].substr(6); m_save = false; } } return FE_OK; } int SilvTask::LoadData() { //BOOST_CLASS_TRACKING(A, track_never) if(m_save) WriteObject(); else LoadObject(); return FE_OK; } int SilvTask::WriteObject() { const A aux(12356, 8956.69f); testAPointer = new A(987, 123.56987f); testAPointer->vectorTest.Set(123.65f, 69.00000001f); A* testA = new A(); std::ofstream ofs(m_filename.c_str()); // create and open a text archive for output //boost::archive::text_oarchive oa(ofs); TextArchiveO oa(ofs); // create and open a binary archive for output //boost::archive::binary_oarchive oa(ofs); //BinaryArchiveO oa( ofs); // create and open a xml archive for output //boost::archive::xml_oarchive oa(ofs); //XMLArchiveO oa(ofs); //write class instance to archive //oa & BOOST_SERIALIZATION_NVP(testAPointer); oa & BOOST_SERIALIZATION_NVP(testA); return FE_OK; } int SilvTask::LoadObject() { C* testC = 0; B* testB = 0; A* testA = 0; //A aux(0, 0); std::ifstream ifs(m_filename.c_str(), std::ios::binary); //create and open a character archive for input //boost::archive::text_iarchive ia(ifs); TextArchiveI ia(ifs); //create and open a binary archive for input //boost::archive::binary_iarchive ia(ifs); //BinaryArchiveI ia(ifs); //create and open a xml archive for input //boost::archive::xml_iarchive ia(ifs); //XMLArchiveI ia(ifs); // read class state from archive //ia & BOOST_SERIALIZATION_NVP(testAPointer); ia & BOOST_SERIALIZATION_NVP(testA); return FE_OK; } int SilvTask::CreateRenderEffects() { return FE_OK; } int OnStart(Mutex* mutex) { int r; string loadingScreenName; string gammaCorrection; FXPlayStream* loadingScreenMovie = 0; // Initialize rtti objects r = RegisterObjects(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error Registering objects"); goto returnSAFEFAIL; } // Pre-Initialize task. r = OnPreInit(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error OnPreInit()"); goto returnSAFEFAIL; } // Testing the parsing of the dir FlowCore::GetScriptSystem().ProcessScriptDir(); // Register script objects r = RegisterScriptObjects(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error registering script objects."); goto returnSAFEFAIL; } // load preferences r = FlowCore::GetPreferences().Init(GetPreferencesFilename()); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, string("[OnStart()]: Error Initializing Preferences: ") + GetPreferencesFilename()); goto returnSAFEFAIL; } // parse update method Preferences& preferences = FlowCore::GetPreferences(); preferences.GetValue("Scene.UpdateMethod", (uint32*)&m_updateMethod); float v = (float)m_updateInterval; preferences.GetValue("Scene.UpdateInterval", &v); m_updateInterval = (double)v; v = (float)m_deltaUpdate; preferences.GetValue("Scene.DeltaUpdate", &v); m_deltaUpdate = (double)v; // create window m_window = CreateMainWindow(); if (!m_window) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error Initializing window"); goto returnSAFEFAIL; } // Create input device m_inputDevice = CreateInputDevice(); if (!m_inputDevice) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error Initializing input device"); goto returnSAFEFAIL; } // Create render device m_renderDevice = CreateRenderDevice(); if (!m_renderDevice) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error Initializing render device"); goto returnSAFEFAIL; } // We need to set the proper render device to the factory ResourceBufferFactory* rbf = ResourceBufferFactory::GetFactory(); rbf->SetRenderDevice(m_renderDevice); // Create the resource task m_resourceTask = CreateResourceTask(); if (!m_resourceTask) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating the resource task."); goto returnSAFEFAIL; } // TODO: frequency value is hardcoded. Use a preference for that FlowCore::GetScheduler().RegisterTask(m_resourceTask, "ResourceTask", 0, 0.25e6f, .0f); // Init Managers r = InitManagers(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error Initializing managers."); goto returnSAFEFAIL; } // set gamma options if (FE_SUCCEEDED(preferences.GetValue("Video.GammaCorrection", &gammaCorrection))) { SharedTools::StringToVector(gammaCorrection, m_gammaCorrection); } // Loading screen preferences.GetValue("Video.LoadingScreen", &loadingScreenName); if(loadingScreenName != "") { loadingScreenMovie = GetGUIManager()->LoadMovie(loadingScreenName); if(loadingScreenMovie) { loadingScreenMovie->SetViewport(0, 0, m_presentParams.width, m_presentParams.height); GetGUIManager()->RenderTopMovies(0); GetRenderDevice()->Present(); } } // Create global effect macros r = CreateGlobalEffectMacros(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating the global effect macros."); goto returnSAFEFAIL; } // Create global effect parameters table r = CreateGlobalEffectParametersTable(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating the global effect parameters table."); goto returnSAFEFAIL; } // Create the default material r = CreateDefaultMaterial(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating default material."); goto returnSAFEFAIL; } // load materials r = FlowCore::GetMaterialManager()->Load(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error loading materials."); goto returnSAFEFAIL; } // create the render collector m_renderCollector = CreateRenderCollector(); if (!m_renderCollector) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating Render Collector."); goto returnSAFEFAIL; } m_renderCollector->SetSceneManager(m_sceneManager); // Create Shared resources between effects r = CreateEffectSharedResources(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating the effect shared resources."); goto returnSAFEFAIL; } // Create render effects r = CreateRenderEffects(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error creating render effects."); goto returnSAFEFAIL; } // create the render effect m_debugEffect = CreateDebugRenderEffect(); // create the render physics debug effect. By default it's disabled. m_debugPhysicsEffect = CreateDebugPhysicsRenderEffect(); if (m_debugPhysicsEffect) m_debugPhysicsEffect->SetEnable(false); // enable debug physics if (m_debugPhysics) EnableDebugPhysics(m_debugPhysics); // create the script wrapper m_systemScriptWrapper = 0; //CreateSystemScriptWrapper(); // create default's human controller to the camera m_humanController = m_humanControllerManager->CreateController(); // Load user data r = LoadData(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error LoadData()."); goto returnSAFEFAIL; } // check for errors if (m_renderCollector->GetRenderCollection()->GetSceneCamera(0) == 0) FE_LOG_WARNING("[DefaultTask::OnStart()]: Scene Camera isn't set."); // Error on post init r = OnPostInit(); if (FE_FAILED(r)) { FE_LOG_CRITICAL(FE_FAIL, "[OnStart()]: Error OnPostInit()."); goto returnSAFEFAIL; } // TODO: UNCOMMENT THIS!!!!!!!!!!!! /**/ // do an initial update with a very small delta EMFX_ACTORMANAGER.Process(0.01f); UpdateScene(0.01f); UpdateRender(0.01f); /**/ // remove loading screen if(loadingScreenMovie) { GetGUIManager()->UnLoadMovie(loadingScreenName); } SetThreadAffinityMask(GetCurrentThread(), 0x01); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); return FE_OK; returnSAFEFAIL: // remove loading screen if(loadingScreenMovie) { GetGUIManager()->UnLoadMovie(loadingScreenName); } return r; } }; int FlowMain(const std::vector& cmdLine) { if(cmdLine.size() < 1) { FE_LOG_ERROR(FE_INVALIDPARAM, "Please insert the file to read from!"); return FE_INVALIDPARAM; } SilvTask* task = new SilvTask(); int r = task->ParseArguments(cmdLine); if (FE_FAILED(r)) { delete task; return r; } FlowCore::GetScheduler().RegisterTask(task, "silver Task", 0, .0f, .0f); delete task; return FE_OK; } } /* BOOST_CLASS_TYPE_INFO( FlowEngine::A, extended_type_info_no_rtti ) BOOST_CLASS_EXPORT(FlowEngine::A) BOOST_CLASS_TYPE_INFO( FlowEngine::B, extended_type_info_no_rtti ) BOOST_CLASS_EXPORT(FlowEngine::B) //BOOST_CLASS_EXPORT_GUID(FlowEngine::B, "B") */