| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
- // LICENSE: Atomic Game Engine Editor and Tools EULA
- // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
- // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
- //
- #include <Atomic/Engine/Engine.h>
- #include <Atomic/Input/Input.h>
- #include <Atomic/IPC/IPC.h>
- // Move me to Engine
- #include <Atomic/Environment/Environment.h>
- #include <Atomic/Script/ScriptSystem.h>
- #include <AtomicJS/Javascript/Javascript.h>
- #include <ToolCore/ToolSystem.h>
- #include <ToolCore/ToolEnvironment.h>
- #include <Atomic/Resource/JSONFile.h>
- #ifdef ATOMIC_DOTNET
- #include <AtomicNET/NETCore/NETHost.h>
- #include <AtomicNET/NETCore/NETCore.h>
- #include <AtomicNET/NETScript/NETScript.h>
- #endif
- #include "AEEditorCommon.h"
- namespace Atomic
- {
- void jsapi_init_atomicnet(JSVM* vm);
- }
- using namespace ToolCore;
- namespace ToolCore
- {
- extern void jsapi_init_toolcore(JSVM* vm);
- }
- namespace AtomicEditor
- {
- AEEditorCommon::AEEditorCommon(Context* context) :
- Application(context)
- {
- }
- void AEEditorCommon::Start()
- {
- Input* input = GetSubsystem<Input>();
- input->SetMouseVisible(true);
- Javascript* javascript = GetSubsystem<Javascript>();
- vm_ = javascript->InstantiateVM("MainVM");
- vm_->InitJSContext();
- jsapi_init_toolcore(vm_);
- #ifdef ATOMIC_DOTNET
- jsapi_init_atomicnet(vm_);
- #endif
- }
- void AEEditorCommon::Setup()
- {
- #ifdef ATOMIC_3D
- RegisterEnvironmentLibrary(context_);
- #endif
- #ifdef ATOMIC_DOTNET
- RegisterNETScriptLibrary(context_);
- #endif
- // Register IPC system
- context_->RegisterSubsystem(new IPC(context_));
- context_->RegisterSubsystem(new ScriptSystem(context_));
- // Instantiate and register the Javascript subsystem
- Javascript* javascript = new Javascript(context_);
- context_->RegisterSubsystem(javascript);
- ToolEnvironment* env = new ToolEnvironment(context_);
- context_->RegisterSubsystem(env);
- #ifdef ATOMIC_DEV_BUILD
- if (!env->InitFromJSON())
- {
- ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
- return;
- }
- #else
- env->InitFromPackage();
- #endif
- #ifdef ATOMIC_DOTNET
- // Instantiate and register the AtomicNET subsystem
- SharedPtr<NETCore> netCore (new NETCore(context_));
- context_->RegisterSubsystem(netCore);
- String netCoreErrorMsg;
- NETHost::SetCoreCLRFilesAbsPath(env->GetNETCoreCLRAbsPath());
- NETHost::SetCoreCLRTPAPaths(env->GetNETTPAPaths());
- NETHost::SetCoreCLRAssemblyLoadPaths(env->GetNETAssemblyLoadPaths());
- if (!netCore->Initialize(netCoreErrorMsg))
- {
- LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
- context_->RemoveSubsystem(NETCore::GetTypeStatic());
- }
- else
- {
- }
- #endif
- ToolSystem* system = new ToolSystem(context_);
- context_->RegisterSubsystem(system);
- ReadPreferences();
- }
- void AEEditorCommon::Stop()
- {
- context_->RemoveSubsystem<IPC>();
- vm_ = 0;
- context_->RemoveSubsystem<Javascript>();
- // make sure JSVM is really down and no outstanding refs
- // as if not, will hold on engine subsystems, which is bad
- assert(!JSVM::GetJSVM(0));
- #ifdef ATOMIC_DOTNET
- NETCore* netCore = GetSubsystem<NETCore>();
- if (netCore)
- {
- netCore->Shutdown();
- context_->RemoveSubsystem<NETCore>();
- }
- #endif
- }
- bool AEEditorCommon::ReadPreferences()
- {
- FileSystem* fileSystem = GetSubsystem<FileSystem>();
- String preferencesPath = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
- preferencesPath += "prefs.json";
- SharedPtr<File> file(new File(context_, preferencesPath, FILE_READ));
- SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
- if (!jsonFile->BeginLoad(*file))
- return false;
- JSONValue root = jsonFile->GetRoot();
- JSONValue editorWindow = root.Get("editorWindow");
- if (!editorWindow.IsObject())
- return false;
- engineParameters_["WindowPositionX"] = editorWindow.Get("x").GetUInt();
- engineParameters_["WindowPositionY"] = editorWindow.Get("y").GetUInt();
- engineParameters_["WindowWidth"] = editorWindow.Get("width").GetUInt();
- engineParameters_["WindowHeight"] = editorWindow.Get("height").GetUInt();
- engineParameters_["FullScreen"] = editorWindow.Get("fullscreen").GetBool();
- file->Close();
- return true;
- }
- }
|