Browse Source

Read command line from a file on Android and iOS.

Lasse Öörni 12 years ago
parent
commit
e8c16bf658
3 changed files with 11 additions and 6 deletions
  1. 1 0
      Bin/Data/CommandLine.txt
  2. 1 1
      Docs/GettingStarted.dox
  3. 9 5
      Tools/Urho3D/Urho3D.cpp

+ 1 - 0
Bin/Data/CommandLine.txt

@@ -0,0 +1 @@
+Scripts/NinjaSnowWar.as

+ 1 - 1
Docs/GettingStarted.dox

@@ -137,7 +137,7 @@ The scripting language supported by default is AngelScript (http://www.angelcode
 
 
 Lua language support can be alternatively be built in, see \ref Build_Options "Build options".
 Lua language support can be alternatively be built in, see \ref Build_Options "Build options".
 
 
-On Android and iOS there are no command line options, so running the NinjaSnowWar script example is hardcoded. This can be changed from the file Tools/Urho3D/Urho3D.cpp.
+On Android and iOS the command line can not be entered, so it is instead read from the file Bin/Data/CommandLine.txt. By default the NinjaSnowWar example will be run.
 
 
 Currently eleven example application scripts exist:
 Currently eleven example application scripts exist:
 
 

+ 9 - 5
Tools/Urho3D/Urho3D.cpp

@@ -78,6 +78,15 @@ Urho3D::Urho3D(Context* context) :
 
 
 void Urho3D::Setup()
 void Urho3D::Setup()
 {
 {
+    // On Android and iOS, read command line from a file as parameters can not otherwise be easily given
+    #if defined(ANDROID) || defined(IOS)
+    SharedPtr<File> commandFile(new File(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/CommandLine.txt",
+        FILE_READ));
+    String commandLine = commandFile->ReadLine();
+    ParseArguments(commandLine, false);
+    commandFile->Close();
+    #endif
+    
     // Check for script file name
     // Check for script file name
     const Vector<String>& arguments = GetArguments();
     const Vector<String>& arguments = GetArguments();
     String scriptFileName;
     String scriptFileName;
@@ -90,11 +99,6 @@ void Urho3D::Setup()
         }
         }
     }
     }
     
     
-    #if defined(ANDROID) || defined(IOS)
-    // Can not pass script name on mobile devices, so choose a hardcoded default
-    scriptFileName_ = "Scripts/NinjaSnowWar.as";
-    #endif
-    
     // Show usage if not found
     // Show usage if not found
     if (scriptFileName_.Empty())
     if (scriptFileName_.Empty())
     {
     {