Browse Source

Adding ToolCore to AtomicEditor, added ToolEnvironment

Josh Engebretson 10 years ago
parent
commit
a44a75ec72

+ 2 - 0
CMakeLists.txt

@@ -7,6 +7,8 @@ set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
 
 add_definitions( -DATOMIC_API= -DATOMIC_STATIC_DEFINE -DATOMIC_ATOMIC2D -DATOMIC_LOGGING)
 
+add_definitions( -DATOMIC_DEV_BUILD )
+
 # this is here as QtCreator is having trouble picking up #include <Atomic/*> without it
 include_directories(${CMAKE_SOURCE_DIR}/Source ${CMAKE_SOURCE_DIR}/Source/AtomicEditor/Source)
 

+ 1 - 1
Source/AtomicEditor/CMakeLists.txt

@@ -24,7 +24,7 @@ endif(APPLE)
 
 add_executable(AtomicEditor ${EXE_TYPE} ${SOURCE_FILES} ${ATOMIC_EDITOR_ICON})
 
-target_link_libraries(AtomicEditor AtomicJS Poco nativefiledialog ${ATOMIC_LINK_LIBRARIES})
+target_link_libraries(AtomicEditor ToolCore AtomicJS Poco nativefiledialog ${ATOMIC_LINK_LIBRARIES})
 
 if (APPLE)
     set (TARGET_PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.template)

+ 28 - 50
Source/AtomicEditor/Source/AEApplication.cpp

@@ -45,8 +45,13 @@
 
 #include <AtomicJS/Javascript/Javascript.h>
 
+#include <ToolCore/ToolSystem.h>
+#include <ToolCore/ToolEnvironment.h>
+
 DEFINE_APPLICATION_MAIN(AtomicEditor::AEApplication);
 
+using namespace ToolCore;
+
 namespace AtomicEditor
 {
 
@@ -61,6 +66,9 @@ void AEApplication::Start()
     // refactor this
     RegisterEnvironmentLibrary(context_);
 
+    ToolSystem* tsystem = new ToolSystem(context_);
+    context_->RegisterSubsystem(tsystem);
+
     Engine* engine = GetSubsystem<Engine>();
     engine->SetAutoExit(false);
 
@@ -68,16 +76,21 @@ void AEApplication::Start()
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     cache->SetAutoReloadResources(true);
 
+#ifndef ATOMIC_DEV_BUILD
+
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
 #ifdef __APPLE__    
     String editorResources = fileSystem->GetAppBundleResourceFolder() + "EditorData.pak";
 #else
     String editorResources = fileSystem->GetProgramDir() + "EditorData.pak";
-#endif    
+#endif
+
     assert(fileSystem->FileExists(editorResources));
     cache->AddPackageFile(editorResources);
 
+#endif
+
     // initialize after EditorResources set
     UI* tbui = GetSubsystem<UI>();
     tbui->Initialize();
@@ -141,6 +154,20 @@ void AEApplication::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
+
+
     const Vector<String>& arguments = GetArguments();
 
     for (unsigned i = 0; i < arguments.Size(); ++i)
@@ -190,55 +217,6 @@ void AEApplication::Setup()
 
     engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
 
-    // Show usage if not found
-    if (false)//scriptFileName_.Empty())
-    {
-        ErrorExit("Usage: AtomicEditor <scriptfile> [options]\n\n"
-            "The script file should implement the function void Start() for initializing the "
-            "application and subscribing to all necessary events, such as the frame update.\n"
-            #ifndef WIN32
-            "\nCommand line options:\n"
-            "-x <res>     Horizontal resolution\n"
-            "-y <res>     Vertical resolution\n"
-            "-m <level>   Enable hardware multisampling\n"
-            "-v           Enable vertical sync\n"
-            "-t           Enable triple buffering\n"
-            "-w           Start in windowed mode\n"
-            "-s           Enable resizing when in windowed mode\n"
-            "-q           Enable quiet mode which does not log to standard output stream\n"
-            "-b <length>  Sound buffer length in milliseconds\n"
-            "-r <freq>    Sound mixing frequency in Hz\n"
-            "-p <paths>   Resource path(s) to use, separated by semicolons\n"
-            "-ap <paths>  Autoload resource path(s) to use, seperated by semicolons\n"
-            "-log <level> Change the log level, valid 'level' values are 'debug', 'info', 'warning', 'error'\n"
-            "-ds <file>   Dump used shader variations to a file for precaching\n"
-            "-mq <level>  Material quality level, default 2 (high)\n"
-            "-tq <level>  Texture quality level, default 2 (high)\n"
-            "-tf <level>  Texture filter mode, default 2 (trilinear)\n"
-            "-af <level>  Texture anisotropy level, default 4. Also sets anisotropic filter mode\n"
-            "-flushgpu    Flush GPU command queue each frame. Effective only on Direct3D9\n"
-            "-borderless  Borderless window mode\n"
-            "-headless    Headless mode. No application window will be created\n"
-            "-landscape   Use landscape orientations (iOS only, default)\n"
-            "-portrait    Use portrait orientations (iOS only)\n"
-            "-prepass     Use light pre-pass rendering\n"
-            "-deferred    Use deferred rendering\n"
-            "-lqshadows   Use low-quality (1-sample) shadow filtering\n"
-            "-noshadows   Disable shadow rendering\n"
-            "-nolimit     Disable frame limiter\n"
-            "-nothreads   Disable worker threads\n"
-            "-nosound     Disable sound output\n"
-            "-noip        Disable sound mixing interpolation\n"
-            "-sm2         Force SM2.0 rendering\n"
-            "-touch       Touch emulation on desktop platform\n"
-            #endif
-        );
-    }
-    else
-    {
-        // Use the script file name as the base name for the log file
-
-    }
 }
 
 void AEApplication::Stop()

+ 15 - 8
Source/AtomicEditor/Source/Player/AEPlayer.cpp

@@ -15,6 +15,7 @@
 #include <AtomicJS/Javascript/JSVM.h>
 #include <AtomicJS/Javascript/JSEvents.h>
 
+#include <ToolCore/ToolEnvironment.h>
 
 #include "AEPlayer.h"
 #include "AEEvents.h"
@@ -24,9 +25,6 @@
 #include "UIPlayer.h"
 #include "UI/Modal/UIModalOps.h"
 
-// TODO: Remove dependency
-#include <Duktape/duktape.h>
-
 namespace AtomicEditor
 {
 
@@ -61,15 +59,24 @@ void AEPlayer::HandleJSError(StringHash eventType, VariantMap& eventData)
 
 bool AEPlayer::Play(AEPlayerMode mode, const IntRect &rect)
 {
+    ToolCore::ToolEnvironment* env = GetSubsystem<ToolCore::ToolEnvironment>();
+    const String& playerBinary = env->GetPlayerBinary();
+
     SubprocessSystem* system = GetSubsystem<SubprocessSystem>();
 
+    Vector<String> paths;
+    paths.Push(env->GetCoreDataDir());
+    paths.Push("/Users/josh/Dev/atomic/AtomicExamples/Basic2D/Resources");
+
+    String resourcePaths;
+    resourcePaths.Join(paths, "!");
+
     Vector<String> vargs;
-    String args = \
-    "--editor-resource-paths \"/Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicPlayer/Resources/CoreData!/Users/josh/Dev/atomic/AtomicExamples/Basic2D/Resources\"";
-    if (args.Length())
-        vargs = args.Split(' ');
 
-    system->Launch("/Users/josh/Dev/atomic/AtomicGameEngine-build/Source/AtomicPlayer/AtomicPlayer.app/Contents/MacOS/AtomicPlayer", vargs);
+    String args = ToString("--editor-resource-paths \"%s\"", resourcePaths.CString());
+    vargs = args.Split(' ');
+
+    system->Launch(playerBinary, vargs);
 
     return false;
 }

+ 103 - 0
Source/ToolCore/ToolEnvironment.cpp

@@ -0,0 +1,103 @@
+
+// before resource system exists so use rapidjson directly
+#include <rapidjson/document.h>
+#include <rapidjson/prettywriter.h>
+#include <rapidjson/filestream.h>
+
+#include <Atomic/IO/FileSystem.h>
+#include <Atomic/IO/File.h>
+
+#include "ToolEnvironment.h"
+
+using namespace rapidjson;
+
+
+namespace ToolCore
+{
+
+ToolEnvironment::ToolEnvironment(Context* context) : Object(context)
+{
+
+}
+
+ToolEnvironment::~ToolEnvironment()
+{
+
+}
+
+bool ToolEnvironment::InitFromJSON()
+{
+
+#ifndef ATOMIC_DEV_BUILD
+    return false;
+#else
+
+    // make sure config path is initialized
+    GetDevConfigFilename();
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    if (!fileSystem->FileExists(devConfigFilename_))
+        return false;
+
+    File jsonFile(context_, devConfigFilename_);
+
+    if (!jsonFile.IsOpen())
+        return false;
+
+    String json;
+    jsonFile.ReadText(json);
+
+    if (!json.Length())
+        return false;
+
+    rapidjson::Document document;
+    if (document.Parse<0>(json.CString()).HasParseError())
+    {
+        return false;
+    }
+
+    //env->SetRootSourceDir("/Users/josh/Dev/atomic/AtomicGameEngine");
+    //env->SetRootBuildDir("/Users/josh/Dev/atomic/AtomicGameEngine-build", true);
+
+    return true;
+
+#endif
+
+}
+
+
+const String& ToolEnvironment::GetDevConfigFilename()
+{
+    if (devConfigFilename_.Length())
+        return devConfigFilename_;
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+#ifdef ATOMIC_PLATFORM_OSX
+    devConfigFilename_ = fileSystem->GetUserDocumentsDir() = ".atomicgameengine/devConfig.json";
+#endif
+
+    return devConfigFilename_;
+}
+
+void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
+{
+    rootSourceDir_ = AddTrailingSlash(sourceDir);
+    resourceCoreDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/CoreData";
+}
+
+void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
+{
+    rootBuildDir_ = AddTrailingSlash(buildDir);
+
+    if (setBinaryPaths)
+    {
+#ifdef ATOMIC_PLATFORM_OSX
+        playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
+#endif
+    }
+
+}
+
+}

+ 88 - 0
Source/ToolCore/ToolEnvironment.h

@@ -0,0 +1,88 @@
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+using namespace Atomic;
+
+namespace ToolCore
+{
+
+// the tool environment contains paths for various
+// binaries, data paths, example folder, etc
+
+// it is either built from the cli, AtomicEditor, environment variables,
+// or a json config file, this avoids needing to symlink folders, etc
+
+class ToolEnvironment : public Object
+{
+    OBJECT(ToolEnvironment)
+
+public:
+
+    ToolEnvironment(Context* context);
+    virtual ~ToolEnvironment();
+
+    // dev build init env from json
+    bool InitFromJSON();
+
+    void SetRootSourceDir(const String& sourceDir);
+    void SetRootBuildDir(const String& buildDir, bool setBinaryPaths = false);
+
+    const String& GetEditorBinary() { return editorBinary_; }
+    const String& GetPlayerBinary() { return playerBinary_; }
+    const String& GetToolBinary() { return toolBinary_; }
+
+    const String& GetCoreDataDir() { return resourceCoreDataDir_; }
+
+    const String& GetDeploymentDataDir() { return toolBinary_; }
+
+    const String& GetMacPlayerDeploymentBinary();
+
+    const String& GetExamplesDir() { return examplesDir_; }
+
+    const String& GetDevConfigFilename();
+
+private:
+
+    // root source directory (for development builds)
+    String rootSourceDir_;
+
+    // root build directory (for development builds)
+    String rootBuildDir_;
+
+    // path to the Atomic Editor binary
+    String editorBinary_;
+
+    // path to Atomic player binary used when running content from the editor or cli
+    String playerBinary_;
+
+    // path to the AtomicTool command line binary
+    String toolBinary_;
+
+    // examples directory
+    String examplesDir_;
+
+    // resources
+    String resourceCoreDataDir_;
+
+    // deployment
+
+    // static deployment data directory
+    String deploymentDataDir_;
+
+    // whether to use individual build folders, or the deployment data dir for binaries
+    bool useBuildDirs_;
+
+    String macBuildDir_;
+    String windowsBuildDir_;
+    String linuxBuildDir_;
+
+    String androidBuildDir_;
+    String iosBuildDir_;
+    String webBuildDir_;
+
+    String devConfigFilename_;
+};
+
+}

+ 2 - 0
Source/ToolCore/ToolSystem.cpp

@@ -9,7 +9,9 @@
 #include "Net/CurlManager.h"
 #include "License/LicenseSystem.h"
 #include "Build/BuildSystem.h"
+
 #include "ToolSystem.h"
+#include "ToolEnvironment.h"
 
 #include "Project/Project.h"