Browse Source

When playing from the editor, project's Engine.json settings take precidence over those passed from the editor as commandline arguments. Default settings also don't take precidence over those set in the settings file.

Matt Benic 10 years ago
parent
commit
d60fb38af8

+ 1 - 1
Script/AtomicEditor/ui/Shortcuts.ts

@@ -35,7 +35,7 @@ class Shortcuts extends Atomic.ScriptObject {
                     var args = "--resizable";
                     var args = "--resizable";
                     Atomic.editorMode.playProject(args, debug);
                     Atomic.editorMode.playProject(args, debug);
                 } else {
                 } else {
-                    var args = "--windowposx " + playerWindow.x + " --windowposy " + playerWindow.y + " --windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable";
+                    var args = "--windowposx " + playerWindow.x + " --windowposy " + playerWindow.y + " --windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable" + " --fromEditorPlay";
                     if (playerWindow.maximized) {
                     if (playerWindow.maximized) {
                         args += " --maximize";
                         args += " --maximize";
                     }
                     }

+ 15 - 4
Source/Atomic/Engine/EngineConfig.cpp

@@ -326,13 +326,24 @@ bool EngineConfig::LoadFromFile(Context *context, const String& filename)
     return LoadFromJSON(json);
     return LoadFromJSON(json);
 }
 }
 
 
-void EngineConfig::ApplyConfig(VariantMap& settings)
+void EngineConfig::ApplyConfig(VariantMap& settings, bool overwrite)
 {
 {
     VariantMap::ConstIterator itr = engineConfig_.Begin();
     VariantMap::ConstIterator itr = engineConfig_.Begin();
-    while (itr != engineConfig_.End())
+    if (overwrite)
+    { 
+        while (itr != engineConfig_.End())
+        {
+            settings[itr->first_] = itr->second_;
+            itr++;
+        }
+    }
+    else
     {
     {
-        settings.InsertNew(itr->first_, itr->second_);
-        itr++;
+        while (itr != engineConfig_.End())
+        {
+            settings.InsertNew(itr->first_, itr->second_);
+            itr++;
+        }
     }
     }
 
 
 }
 }

+ 1 - 1
Source/Atomic/Engine/EngineConfig.h

@@ -40,7 +40,7 @@ public:
     static bool LoadFromJSON(const String& json);
     static bool LoadFromJSON(const String& json);
 
 
     /// Apply the configuration to a setting variant map, values that exist will not be overriden
     /// Apply the configuration to a setting variant map, values that exist will not be overriden
-    static void ApplyConfig(VariantMap& settings);
+    static void ApplyConfig(VariantMap& settings, bool overwrite = false);
 
 
     static const VariantMap& GetConfig() { return engineConfig_; }
     static const VariantMap& GetConfig() { return engineConfig_; }
 
 

+ 82 - 67
Source/AtomicEditor/Application/AEPlayerApp.cpp

@@ -52,7 +52,8 @@ namespace AtomicEditor
 
 
 AEPlayerApplication::AEPlayerApplication(Context* context) :
 AEPlayerApplication::AEPlayerApplication(Context* context) :
     AEEditorCommon(context),
     AEEditorCommon(context),
-    debugPlayer_(false)
+    debugPlayer_(false),
+    runningFromEditorPlay_(false)
 {
 {
 }
 }
 
 
@@ -60,44 +61,96 @@ void AEPlayerApplication::Setup()
 {
 {
     AEEditorCommon::Setup();
     AEEditorCommon::Setup();
 
 
-    // Read the engine configuration
+    // Read the project engine configuration
     ReadEngineConfig();
     ReadEngineConfig();
 
 
     engine_->SetAutoExit(false);
     engine_->SetAutoExit(false);
 
 
     engineParameters_.InsertNew("WindowTitle", "AtomicPlayer");
     engineParameters_.InsertNew("WindowTitle", "AtomicPlayer");
 
 
+    // Set defaults not already set from config
 #if (ATOMIC_PLATFORM_ANDROID)
 #if (ATOMIC_PLATFORM_ANDROID)
-    engineParameters_["FullScreen"] = true;
-    engineParameters_["ResourcePaths"] = "CoreData;AtomicResources";
+    engineParameters_.InsertNew("FullScreen", true);
+    engineParameters_.InsertNew("ResourcePaths", "CoreData;AtomicResources");
 #elif ATOMIC_PLATFORM_WEB
 #elif ATOMIC_PLATFORM_WEB
-    engineParameters_["FullScreen"] = false;
-    engineParameters_["ResourcePaths"] = "AtomicResources";
-    // engineParameters_["WindowWidth"] = 1280;
-    // engineParameters_["WindowHeight"] = 720;
+    engineParameters_.InsertNew("FullScreen", false);
+    engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
+    // engineParameters_.InsertNew("WindowWidth", 1280);
+    // engineParameters_.InsertNew("WindowHeight", 720);
 #elif ATOMIC_PLATFORM_IOS
 #elif ATOMIC_PLATFORM_IOS
-    engineParameters_["FullScreen"] = false;
-    engineParameters_["ResourcePaths"] = "AtomicResources";
+    engineParameters_.InsertNew("FullScreen", false);
+    engineParameters_.InsertNew("ResourcePaths", "AtomicResources)";
 #else
 #else
-    engineParameters_["FullScreen"] = false;
-    engineParameters_["WindowWidth"] = 1280;
-    engineParameters_["WindowHeight"] = 720;
+    engineParameters_.InsertNew("FullScreen", false);
+    engineParameters_.InsertNew("WindowWidth", 1280);
+    engineParameters_.InsertNew("WindowHeight", 720);
 #endif
 #endif
 
 
     engineParameters_.InsertNew("LogLevel", LOG_DEBUG);
     engineParameters_.InsertNew("LogLevel", LOG_DEBUG);
 
 
 #if ATOMIC_PLATFORM_WINDOWS || ATOMIC_PLATFORM_LINUX
 #if ATOMIC_PLATFORM_WINDOWS || ATOMIC_PLATFORM_LINUX
-    engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
-    engineParameters_["ResourcePrefixPath"] = "AtomicPlayer_Resources";
+    engineParameters_.InsertNew("WindowIcon", "Images/AtomicLogo32.png");
+    engineParameters_.InsertNew("ResourcePrefixPath", "AtomicPlayer_Resources");
 #elif ATOMIC_PLATFORM_ANDROID
 #elif ATOMIC_PLATFORM_ANDROID
-    //engineParameters_["ResourcePrefixPath"] = "assets";
+    //engineParameters_.InsertNew("ResourcePrefixPath", "assets");
 #elif ATOMIC_PLATFORM_OSX
 #elif ATOMIC_PLATFORM_OSX
-    engineParameters_["ResourcePrefixPath"] = "../Resources";
+    engineParameters_.InsertNew("ResourcePrefixPath", "../Resources");
 #endif
 #endif
 
 
-    FileSystem* filesystem = GetSubsystem<FileSystem>();
+    // Read command line arguments, potentially overwriting project settings
+    ReadCommandLineArguments();
 
 
+    // Re-apply project settings if running from editor play button
+    if (runningFromEditorPlay_)
+        EngineConfig::ApplyConfig(engineParameters_, true);
+
+    // Use the script file name as the base name for the log file
+    engineParameters_["LogName"] = GetSubsystem<FileSystem>()->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
+}
+
+void AEPlayerApplication::ReadEngineConfig()
+{
+    // find the project path from the command line args
+
+    String projectPath;
+    const Vector<String>& arguments = GetArguments();
+
+    for (unsigned i = 0; i < arguments.Size(); ++i)
+    {
+        if (arguments[i].Length() > 1)
+        {
+            String argument = arguments[i].ToLower();
+            String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
+
+            if (argument == "--project" && value.Length())
+            {
+                projectPath = AddTrailingSlash(value);
+                break;
+            }
+
+        }
+    }
+
+    if (!projectPath.Length())
+        return;
+
+    String filename = projectPath + "Settings/Engine.json";
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    if (!fileSystem->FileExists(filename))
+        return;
+
+    if (EngineConfig::LoadFromFile(context_, filename))
+    {
+        EngineConfig::ApplyConfig(engineParameters_);
+    }
+
+}
+
+void AEPlayerApplication::ReadCommandLineArguments()
+{
     const Vector<String>& arguments = GetArguments();
     const Vector<String>& arguments = GetArguments();
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
 
     for (unsigned i = 0; i < arguments.Size(); ++i)
     for (unsigned i = 0; i < arguments.Size(); ++i)
     {
     {
@@ -110,6 +163,10 @@ void AEPlayerApplication::Setup()
             {
             {
                 SubscribeToEvent(E_LOGMESSAGE, HANDLER(AEPlayerApplication, HandleLogMessage));
                 SubscribeToEvent(E_LOGMESSAGE, HANDLER(AEPlayerApplication, HandleLogMessage));
             }
             }
+            else if (argument == "--fromeditorplay")
+            {
+                runningFromEditorPlay_ = true;
+            }
             else if (argument == "--debug")
             else if (argument == "--debug")
             {
             {
                 debugPlayer_ = true;
                 debugPlayer_ = true;
@@ -121,7 +178,7 @@ void AEPlayerApplication::Setup()
                 value = AddTrailingSlash(value);
                 value = AddTrailingSlash(value);
 
 
                 // check that cache exists
                 // check that cache exists
-                if (!filesystem->DirExists(value + "Cache"))
+                if (!fileSystem->DirExists(value + "Cache"))
                 {
                 {
                     ErrorExit("Project cache folder does not exist, projects must be loaded into the Atomic Editor at least once before using the --player command line mode");
                     ErrorExit("Project cache folder does not exist, projects must be loaded into the Atomic Editor at least once before using the --player command line mode");
                     return;
                     return;
@@ -130,18 +187,18 @@ void AEPlayerApplication::Setup()
 #ifdef ATOMIC_DEV_BUILD
 #ifdef ATOMIC_DEV_BUILD
 
 
                 String resourcePaths = ToString("%s/Resources/CoreData;%s/Resources/PlayerData;%sResources;%s;%sCache",
                 String resourcePaths = ToString("%s/Resources/CoreData;%s/Resources/PlayerData;%sResources;%s;%sCache",
-                         ATOMIC_ROOT_SOURCE_DIR, ATOMIC_ROOT_SOURCE_DIR, value.CString(), value.CString(), value.CString());
+                    ATOMIC_ROOT_SOURCE_DIR, ATOMIC_ROOT_SOURCE_DIR, value.CString(), value.CString(), value.CString());
 
 
 #else
 #else
 
 
 #ifdef __APPLE__
 #ifdef __APPLE__
                 engineParameters_["ResourcePrefixPath"] = "../Resources";
                 engineParameters_["ResourcePrefixPath"] = "../Resources";
 #else
 #else
-				engineParameters_["ResourcePrefixPath"] = filesystem->GetProgramDir() + "Resources";
+                engineParameters_["ResourcePrefixPath"] = filesystem->GetProgramDir() + "Resources";
 #endif
 #endif
 
 
                 String resourcePaths = ToString("CoreData;PlayerData;%s/;%s/Resources;%s;%sCache",
                 String resourcePaths = ToString("CoreData;PlayerData;%s/;%s/Resources;%s;%sCache",
-                                                              value.CString(), value.CString(), value.CString(), value.CString());
+                    value.CString(), value.CString(), value.CString(), value.CString());
 #endif
 #endif
 
 
                 LOGINFOF("Adding ResourcePaths: %s", resourcePaths.CString());
                 LOGINFOF("Adding ResourcePaths: %s", resourcePaths.CString());
@@ -155,7 +212,7 @@ void AEPlayerApplication::Setup()
 #endif
 #endif
 
 
             }
             }
-            else if (argument == "--windowposx" && value.Length()) 
+            else if (argument == "--windowposx" && value.Length())
             {
             {
                 engineParameters_["WindowPositionX"] = atoi(value.CString());
                 engineParameters_["WindowPositionX"] = atoi(value.CString());
             }
             }
@@ -171,58 +228,16 @@ void AEPlayerApplication::Setup()
             {
             {
                 engineParameters_["WindowHeight"] = atoi(value.CString());
                 engineParameters_["WindowHeight"] = atoi(value.CString());
             }
             }
-            else if (argument == "--resizable") 
+            else if (argument == "--resizable")
             {
             {
                 engineParameters_["WindowResizable"] = true;
                 engineParameters_["WindowResizable"] = true;
-            } 
+            }
             else if (argument == "--maximize")
             else if (argument == "--maximize")
             {
             {
                 engineParameters_["WindowMaximized"] = true;
                 engineParameters_["WindowMaximized"] = true;
             }
             }
         }
         }
     }
     }
-
-    // Use the script file name as the base name for the log file
-    engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
-}
-
-void AEPlayerApplication::ReadEngineConfig()
-{
-    // find the project path from the command line args
-
-    String projectPath;
-    const Vector<String>& arguments = GetArguments();
-
-    for (unsigned i = 0; i < arguments.Size(); ++i)
-    {
-        if (arguments[i].Length() > 1)
-        {
-            String argument = arguments[i].ToLower();
-            String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
-
-            if (argument == "--project" && value.Length())
-            {
-                projectPath = AddTrailingSlash(value);
-                break;
-            }
-
-        }
-    }
-
-    if (!projectPath.Length())
-        return;
-
-    FileSystem* filesystem = GetSubsystem<FileSystem>();
-    String filename = projectPath + "Settings/Engine.json";
-
-    if (!filesystem->FileExists(filename))
-        return;
-
-    if (EngineConfig::LoadFromFile(context_, filename))
-    {
-        EngineConfig::ApplyConfig(engineParameters_);
-    }
-
 }
 }
 
 
 void AEPlayerApplication::Start()
 void AEPlayerApplication::Start()

+ 4 - 0
Source/AtomicEditor/Application/AEPlayerApp.h

@@ -45,8 +45,12 @@ private:
 
 
     void ReadEngineConfig();
     void ReadEngineConfig();
 
 
+    void ReadCommandLineArguments();
+
     bool debugPlayer_;
     bool debugPlayer_;
 
 
+    bool runningFromEditorPlay_;
+
 };
 };
 
 
 }
 }

+ 1 - 1
Source/AtomicEditor/EditorMode/AEEditorMode.cpp

@@ -124,7 +124,7 @@ bool EditorMode::PlayProject(String addArgs, bool debug)
 
 
     Vector<String> vargs;
     Vector<String> vargs;
 
 
-    String args = ToString("--player --project \"%s\"", AddTrailingSlash(project->GetProjectPath()).CString());
+    String args = ToString("--player --fromEditorPlay --project \"%s\"", AddTrailingSlash(project->GetProjectPath()).CString());
 
 
     vargs = args.Split(' ');
     vargs = args.Split(' ');