Browse Source

Editor Work

Josh Engebretson 10 years ago
parent
commit
4c23272d1c

+ 9 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/main.js

@@ -0,0 +1,9 @@
+
+var ui = require("./ui/ui");
+
+
+( function() {
+
+
+
+}());

+ 0 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/ui/mainframe.js


+ 4 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/javascript/ui/ui.js

@@ -0,0 +1,4 @@
+
+var mainframe = require("./mainframe");
+
+print(mainframe);

+ 1 - 1
Source/AtomicEditor/Source/Player/AEPlayerApplication.cpp

@@ -221,7 +221,7 @@ void AEPlayerApplication::Start()
     vm = javascript->InstantiateVM("MainVM");
     vm->InitJSContext();
 
-    vm->SetModuleSearchPath("Modules");
+    vm->SetModuleSearchPaths("Modules");
 
     if (!vm->ExecuteMain())
     {

+ 133 - 0
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -0,0 +1,133 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#include <Atomic/Core/StringUtils.h>
+#include <Atomic/Engine/Engine.h>
+#include <Atomic/IO/FileSystem.h>
+#include <Atomic/Input/Input.h>
+#include <Atomic/Resource/ResourceCache.h>
+
+#include <Atomic/UI/UI.h>
+
+#include <AtomicJS/Javascript/Javascript.h>
+
+#include <ToolCore/ToolSystem.h>
+#include <ToolCore/ToolEnvironment.h>
+
+#include "AEEditorApp.h"
+
+using namespace ToolCore;
+
+namespace AtomicEditor
+{
+
+AEEditorApp::AEEditorApp(Context* context) :
+    Application(context)
+{
+
+}
+
+void AEEditorApp::Start()
+{
+    Input* input = GetSubsystem<Input>();
+    input->SetMouseVisible(true);
+
+    // move UI initialization to JS
+    UI* ui = GetSubsystem<UI>();
+    ui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
+    ui->LoadSkin("AtomicEditor/resources/default_skin/skin.tb.txt", "AtomicEditor/editor/skin/skin.tb.txt");
+    ui->AddFont("AtomicEditor/resources/vera.ttf", "Vera");
+    ui->AddFont("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
+    ui->SetDefaultFont("Vera", 12);
+
+    Javascript* javascript = new Javascript(context_);
+    context_->RegisterSubsystem(javascript);
+    SubscribeToEvent(E_JSERROR, HANDLER(AEEditorApp, HandleJSError));
+
+    // Instantiate and register the Javascript subsystem
+    vm_ = javascript->InstantiateVM("MainVM");
+    vm_->InitJSContext();
+    vm_->SetModuleSearchPaths("AtomicEditor/javascript");
+
+    SharedPtr<File> file (GetSubsystem<ResourceCache>()->GetFile("AtomicEditor/javascript/main.js"));
+
+    if (file.Null())
+    {
+        ErrorExit("Unable to load AtomicEditor/javascript/main.js");
+        return;
+    }
+
+    if (!vm_->ExecuteFile(file))
+    {
+        ErrorExit("Error executing AtomicEditor/javascript/main.js");
+        return;
+    }
+
+}
+
+void AEEditorApp::Setup()
+{
+    FileSystem* filesystem = GetSubsystem<FileSystem>();
+    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;
+    }
+
+#endif
+
+    // env->Dump();
+
+    engineParameters_["WindowTitle"] = "AtomicEditor";
+    engineParameters_["WindowResizable"] = true;
+    engineParameters_["FullScreen"] = false;
+    engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
+
+#ifdef ATOMIC_PLATFORM_OSX
+    engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
+#endif
+
+#ifdef ATOMIC_DEV_BUILD
+    engineParameters_["ResourcePrefixPath"] = "";
+    String resourcePaths = env->GetCoreDataDir() + ";" +  env->GetEditorDataDir();
+    engineParameters_["ResourcePaths"] = resourcePaths;
+#else
+
+    #error ATOMIC_DEV_BUILD not defined
+
+#endif // ATOMIC_DEV_BUILD
+
+
+}
+
+void AEEditorApp::Stop()
+{
+
+}
+
+void AEEditorApp::HandleJSError(StringHash eventType, VariantMap& eventData)
+{
+    using namespace JSError;
+    //String errName = eventData[P_ERRORNAME].GetString();
+    String errMessage = eventData[P_ERRORMESSAGE].GetString();
+    String errFilename = eventData[P_ERRORFILENAME].GetString();
+    //String errStack = eventData[P_ERRORSTACK].GetString();
+    int errLineNumber = eventData[P_ERRORLINENUMBER].GetInt();
+
+    String errorString = ToString("%s - %s - Line: %i",
+                                  errFilename.CString(), errMessage.CString(), errLineNumber);
+
+    ErrorExit(errorString);
+
+}
+
+
+
+
+}

+ 40 - 0
Source/AtomicEditorWork/Application/AEEditorApp.h

@@ -0,0 +1,40 @@
+
+#pragma once
+
+#include <Atomic/Engine/Application.h>
+
+using namespace Atomic;
+
+namespace Atomic
+{
+    class JSVM;
+}
+
+namespace AtomicEditor
+{
+
+class AEEditorApp : public Application
+{
+    OBJECT(AEEditorApp);
+
+public:
+    /// Construct.
+    AEEditorApp(Context* context);
+
+    /// Setup before engine initialization. Verify that a script file has been specified.
+    virtual void Setup();
+    /// Setup after engine initialization. Load the script and execute its start function.
+    virtual void Start();
+    /// Cleanup after the main loop. Run the script's stop function if it exists.
+    virtual void Stop();
+
+private:
+
+    void HandleJSError(StringHash eventType, VariantMap& eventData);
+
+    SharedPtr<JSVM> vm_;
+
+
+};
+
+}

+ 39 - 0
Source/AtomicEditorWork/Application/AEPlayerApp.cpp

@@ -0,0 +1,39 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#include <Atomic/Engine/Engine.h>
+
+#include <ToolCore/ToolSystem.h>
+#include <ToolCore/ToolEnvironment.h>
+
+#include "AEPlayerApp.h"
+
+using namespace ToolCore;
+
+namespace AtomicEditor
+{
+
+AEPlayerApp::AEPlayerApp(Context* context) :
+    Application(context)
+{
+
+}
+
+void AEPlayerApp::Start()
+{
+
+}
+
+void AEPlayerApp::Setup()
+{
+
+
+}
+
+void AEPlayerApp::Stop()
+{
+
+}
+
+}

+ 30 - 0
Source/AtomicEditorWork/Application/AEPlayerApp.h

@@ -0,0 +1,30 @@
+
+#pragma once
+
+#include <Atomic/Engine/Application.h>
+
+using namespace Atomic;
+
+namespace AtomicEditor
+{
+
+class AEPlayerApp : public Application
+{
+    OBJECT(AEPlayerApp);
+
+public:
+    /// Construct.
+    AEPlayerApp(Context* context);
+
+    /// Setup before engine initialization. Verify that a script file has been specified.
+    virtual void Setup();
+    /// Setup after engine initialization. Load the script and execute its start function.
+    virtual void Start();
+    /// Cleanup after the main loop. Run the script's stop function if it exists.
+    virtual void Stop();
+
+private:
+
+};
+
+}

+ 122 - 0
Source/AtomicEditorWork/Application/Main.cpp

@@ -0,0 +1,122 @@
+
+#if defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
+#include <Atomic/Core/MiniDump.h>
+#include <windows.h>
+#ifdef _MSC_VER
+#include <crtdbg.h>
+#endif
+#endif
+
+#include <Atomic/Core/ProcessUtils.h>
+#include <Atomic/IO/Log.h>
+
+#include "AEEditorApp.h"
+#include "AEPlayerApp.h"
+
+using namespace AtomicEditor;
+
+static int RunEditorApplication()
+{
+    Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
+    Atomic::SharedPtr<AEEditorApp> application(new AEEditorApp(context));
+    return application->Run();
+}
+
+static int RunPlayerApplication()
+{
+    Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
+    Atomic::SharedPtr<AEPlayerApp> application(new AEPlayerApp(context));
+    return application->Run();
+}
+
+
+// Define a platform-specific main function, which in turn executes the user-defined function
+
+// MSVC debug mode: use memory leak reporting
+#if defined(_MSC_VER) && defined(_DEBUG) && !defined(ATOMIC_WIN32_CONSOLE)
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
+{
+    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+    Atomic::ParseArguments(GetCommandLineW());
+
+    const Vector<String>& arguments = GetArguments();
+
+    bool runPlayer = false;
+    for (unsigned i = 0; i < arguments.Size();i++)
+    {
+        if (arguments.At(i) == "--player")
+        {
+            runPlayer = true;
+            break;
+        }
+    }
+
+    if (runPlayer)
+        return RunPlayerApplication();
+
+    return RunEditorApplication();
+
+}
+// MSVC release mode: write minidump on crash
+#elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
+{
+    Atomic::ParseArguments(GetCommandLineW());
+    int exitCode;
+    __try
+    {
+        exitCode = function;
+    }
+    __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
+    {
+    }
+    return exitCode;
+}
+// Other Win32 or minidumps disabled: just execute the function
+#elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
+{
+    Atomic::ParseArguments(GetCommandLineW());
+
+    const Vector<String>& arguments = GetArguments();
+
+    bool runPlayer = false;
+    for (unsigned i = 0; i < arguments.Size();i++)
+    {
+        if (arguments.At(i) == "--player")
+        {
+            runPlayer = true;
+            break;
+        }
+    }
+
+    if (runPlayer)
+        return RunPlayerApplication();
+
+    return RunEditorApplication();
+}
+// Linux or OS X: use main
+#else
+int main(int argc, char** argv)
+{
+    Atomic::ParseArguments(argc, argv);
+
+    const Vector<String>& arguments = GetArguments();
+
+    bool runPlayer = false;
+    for (unsigned i = 0; i < arguments.Size();i++)
+    {
+        if (arguments.At(i) == "--player")
+        {
+            runPlayer = true;
+            break;
+        }
+    }
+
+    if (runPlayer)
+        return RunPlayerApplication();
+
+    return RunEditorApplication();
+}
+#endif

+ 50 - 0
Source/AtomicEditorWork/CMakeLists.txt

@@ -0,0 +1,50 @@
+include_directories (${CMAKE_SOURCE_DIR}/Source/ThirdParty/rapidjson/include
+                     ${CMAKE_SOURCE_DIR}/Source/ThirdParty
+                     ${CMAKE_SOURCE_DIR}/Source/ThirdParty/nativefiledialog)
+
+
+file (GLOB_RECURSE SOURCE_FILES *.cpp *.h)
+
+if (APPLE)
+    set (EXE_TYPE MACOSX_BUNDLE)
+
+    #ICNS
+    set(MACOSX_BUNDLE_ICON_FILE Atomic.icns)
+    set(ATOMIC_EDITOR_ICON ${CMAKE_SOURCE_DIR}/CMake/Modules/Atomic.icns)
+    set_source_files_properties(${ATOMIC_EDITOR_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
+
+elseif(LINUX)
+
+else()
+    include_directories (${CMAKE_SOURCE_DIR}/Source/ThirdParty/libcurl/include)
+    add_definitions(-DCURL_STATICLIB)
+
+    # We want the console for now
+    #set (EXE_TYPE WIN32)
+    add_definitions(-DATOMIC_WIN32_CONSOLE)
+
+    set (SOURCE_FILES ${SOURCE_FILES} ${CMAKE_SOURCE_DIR}/CMake/Modules/Atomic.rc)
+endif(APPLE)
+
+add_executable(AtomicEditorWork ${EXE_TYPE} ${SOURCE_FILES} ${ATOMIC_EDITOR_ICON})
+
+target_link_libraries(AtomicEditorWork ToolCore AtomicJS Poco nativefiledialog ${ATOMIC_LINK_LIBRARIES})
+
+if (APPLE)
+    set (TARGET_PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.template)
+    target_link_libraries(AtomicEditorWork curl)
+elseif(LINUX)
+    target_link_libraries(AtomicEditorWork curl nativefiledialog ${GTK3_LIBRARIES})
+else()
+    target_link_libraries(AtomicEditorWork libcurl Iphlpapi Wldap32)
+
+    # pre-Windows 8 can't count on D3DCompiler_47.dll being on system
+    add_custom_command (TARGET AtomicEditorWork POST_BUILD
+    COMMAND ${CMAKE_COMMAND}
+    ARGS -E copy_if_different \"${D3DCOMPILER_47_DLL}\" \"$<TARGET_FILE_DIR:AtomicEditor>/D3DCompiler_47.dll\")
+
+endif()
+
+if (TARGET_PROPERTIES)
+    set_target_properties (AtomicEditorWork PROPERTIES ${TARGET_PROPERTIES})
+endif ()

+ 13 - 3
Source/AtomicJS/Javascript/JSRequire.cpp

@@ -55,9 +55,19 @@ namespace Atomic
         {
             path += ".js";
 
-            if (!cache->Exists(path) && cache->Exists("Modules/" + path))
-                path = "Modules/" + path;
- 
+            if (!cache->Exists(path))
+            {
+                const Vector<String>& searchPaths = vm->GetModuleSearchPaths();
+                for (unsigned i = 0; i < searchPaths.Size(); i++)
+                {
+                    String search = searchPaths[i] + path;
+                    if (cache->Exists(search))
+                    {
+                        path = search;
+                        break;
+                    }
+                }
+            }
         }
 
         if (cache->Exists(path))

+ 3 - 19
Source/AtomicJS/Javascript/JSVM.cpp

@@ -334,6 +334,7 @@ void JSVM::SendJSErrorEvent(const String& filename)
     assert(duk_is_object(ctx, -1));
 
     duk_get_prop_string(ctx, -1, "fileName");
+
     if (duk_is_string(ctx, -1))
     {
         eventData[P_ERRORFILENAME] = duk_to_string(ctx, -1);
@@ -447,8 +448,7 @@ bool JSVM::ExecuteFile(File *file)
     if (duk_eval_raw(ctx_, source.CString(), 0,
                      DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN) != 0)
     {
-        if (duk_is_object(ctx_, -1))
-            SendJSErrorEvent(file->GetFullPath());
+        SendJSErrorEvent(file->GetFullPath());
 
         duk_pop(ctx_);
         return false;
@@ -475,24 +475,8 @@ bool JSVM::ExecuteMain()
         return false;
     }
 
-    String source;
-
-    file->ReadText(source);
-
-    duk_push_string(ctx_, file->GetFullPath().CString());
-    if (duk_eval_raw(ctx_, source.CString(), 0,
-                     DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN) != 0)
-    {
-        if (duk_is_object(ctx_, -1))
-            SendJSErrorEvent(file->GetFullPath());
-
-        duk_pop(ctx_);
-        return false;
-    }
-
-    duk_pop(ctx_);
+    return ExecuteFile(file);
 
-    return true;
 }
 
 }

+ 14 - 3
Source/AtomicJS/Javascript/JSVM.h

@@ -9,6 +9,7 @@
 #include <Atomic/Container/List.h>
 
 #include <Atomic/IO/Log.h>
+#include <Atomic/IO/FileSystem.h>
 
 #include "JSAPI.h"
 #include "JSEvents.h"
@@ -134,11 +135,21 @@ public:
         return heapToObject_[heapptr];
     }
 
-    void SetModuleSearchPath(const String& searchPath)
+    void SetModuleSearchPaths(const String& searchPath)
     {
-        moduleSearchPath_ = searchPath;
+        moduleSearchPath_ = searchPath.Split(';');
+        for (unsigned i = 0; i < moduleSearchPath_.Size(); i++)
+        {
+            moduleSearchPath_[i] = AddTrailingSlash(moduleSearchPath_[i]);
+        }
+    }
+
+    const Vector<String>& GetModuleSearchPaths()
+    {
+        return moduleSearchPath_;
     }
 
+
     void SetLastModuleSearchFile(const String& fileName) { lastModuleSearchFilename_ = fileName; }
 
     const String& GetLastModuleSearchFile() { return lastModuleSearchFilename_; }
@@ -169,7 +180,7 @@ private:
 
     float gcTime_;
 
-    String moduleSearchPath_;
+    Vector<String> moduleSearchPath_;
     String lastModuleSearchFilename_;
 
     String errorString_;

+ 1 - 1
Source/AtomicPlayer/AtomicPlayer.cpp

@@ -118,7 +118,7 @@ void AtomicPlayer::Start()
     vm = javascript->InstantiateVM("MainVM");
     vm->InitJSContext();
 
-    vm->SetModuleSearchPath("Modules");
+    vm->SetModuleSearchPaths("Modules");
 
     if (!vm->ExecuteMain())
     {

+ 2 - 3
Source/CMakeLists.txt

@@ -4,11 +4,10 @@ add_subdirectory(Atomic)
 add_subdirectory(AtomicJS)
 add_subdirectory(AtomicPlayer)
 
-if (NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN)    
+if (NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN)
     add_subdirectory(ToolCore)
     add_subdirectory(AtomicEditor)
+    add_subdirectory(AtomicEditorWork)
     add_subdirectory(AtomicTool)
     add_subdirectory(Tools)
 endif()
-
-

+ 22 - 0
Source/ToolCore/ToolEnvironment.cpp

@@ -4,6 +4,7 @@
 #include <rapidjson/prettywriter.h>
 #include <rapidjson/filestream.h>
 
+#include <Atomic/IO/Log.h>
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/IO/File.h>
 
@@ -130,4 +131,25 @@ void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPath
 
 }
 
+void ToolEnvironment::Dump()
+{
+    LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
+    LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
+
+    LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
+    LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
+    LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
+
+    LOGINFOF("Editor Binary: %s", editorBinary_.CString());
+    LOGINFOF("Player Binary: %s", playerBinary_.CString());
+    LOGINFOF("Tool Binary: %s", toolBinary_.CString());
+
+    LOGINFOF("Examples Dir: %s", examplesDir_.CString());
+
+    LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
+
+    LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
+
+}
+
 }

+ 2 - 0
Source/ToolCore/ToolEnvironment.h

@@ -48,6 +48,8 @@ public:
 
     const String& GetDevConfigFilename();
 
+    void Dump();
+
 private:
 
     // root source directory (for development builds)