Commit 5198e8f4 authored by BERTON Florian Gaetan Hubert's avatar BERTON Florian Gaetan Hubert
Browse files

add command line script and add resolution in configreader

parent 6386276e
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** Authors: Florian Berton
**
** Contact: crowd_group@inria.fr
*/
using UnityEngine;
using System.IO;
public class CommandLineParser
{
#region attribute
protected string _ScenarioFile = "";
protected Vector2 _CamResolution = new Vector2(-1,-1);
protected int _Height = -1;
#endregion
#region getter
/// <summary>
/// Getter for the path to the scenario file
/// </summary>
public string GetScenarioFile()
{
return _ScenarioFile;
}
/// <summary>
/// Getter for the resolution of the camera recorder
/// </summary>
public Vector2 GetCamResolution()
{
return _CamResolution;
}
#endregion
#region function
/// <summary>
/// Basic Constructor
/// </summary>
public CommandLineParser()
{
}
/// <summary>
/// Constructor with an input command line
/// </summary>
public CommandLineParser(string[] Args)
{
ParseCommandLine(Args);
}
/// <summary>
/// Parse the arguments given in the command line
/// </summary>
protected void ParseCommandLine(string[] Args)
{
int nb = 0;
while (nb < Args.Length)
{
switch (Args[nb])
{
// check if it's a scenario file
case "-s":
if (nb<Args.Length-1)
{
string ScenarioFolder = Application.dataPath;
int lastIndex = ScenarioFolder.LastIndexOf('/');
ScenarioFolder = ScenarioFolder.Remove(lastIndex, ScenarioFolder.Length - lastIndex);
string ScenarioPath = Args[++nb];
ScenarioPath = ScenarioPath.Replace("\\", "/");
_ScenarioFile = ScenarioFolder + '/' + ScenarioPath;
if (!System.IO.File.Exists(_ScenarioFile))
Application.Quit();
}
break;
// check if it's the camera resolution
case "-r":
if (nb < Args.Length - 2)
{
_CamResolution = new Vector2(int.Parse(Args[++nb]), int.Parse(Args[++nb]));
}
break;
}
nb++;
}
}
#endregion
}
fileFormatVersion: 2
guid: 33cdbbc5bc819c74f913828630467b59
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -74,32 +74,18 @@ public class MenuManager : MonoBehaviour
string [] arguments = System.Environment.GetCommandLineArgs();
if (arguments.Length >1 && !Application.isEditor)
{
// manage screen resolution if at least 3 arguments are given
if (arguments.Length >=3)
{
int WidthResolution = int.Parse(arguments[2]);
int HeightResolution = int.Parse(arguments[3]);
Screen.SetResolution(WidthResolution, HeightResolution,false);
}
// get path scenario
string ScenarioFolder = Application.dataPath;
int lastIndex = ScenarioFolder.LastIndexOf('/');
ScenarioFolder = ScenarioFolder.Remove(lastIndex, ScenarioFolder.Length - lastIndex);
string ScenarioPath = arguments[1];
ScenarioPath = ScenarioPath.Replace("\\", "/");
configPath = ScenarioFolder + '/' + ScenarioPath;
// startScenario
// Parse Command Line
CommandLineParser CommandLine = new CommandLineParser(arguments);
configPath = CommandLine.GetScenarioFile();
// StartScenario
ConfigReader.LoadConfig(configPath);
obstReader.clear();
obstReader.createObstacles(ConfigReader.obstaclesFile, ConfigReader.stageInfos);
LoadEnv env = gameObject.GetComponent<LoadEnv>();
LoadEnv env = gameObject.GetComponent<LoadEnv>();
env.loadScenario(ConfigReader.trajectoriesDir);
ConfigReader.camResolution = CommandLine.GetCamResolution();
menu.SetActive(false);
Time.timeScale = 1;
}
}
......
......@@ -127,6 +127,16 @@ public static class ConfigReader
get { return data.cam.rotation.vect; }
set { data.cam.rotation = new ConfigVect3(value); }
}
/// <summary>
/// Camera Resolution
/// </summary>
static public Vector2 camResolution
{
get { return data.cam.CamResolution.vect; }
set { data.cam.CamResolution = new ConfigVect2(value); }
}
/// <summary>
/// ID of the agent to look at
/// </summary>
......@@ -338,12 +348,43 @@ public class ConfigCam
public ConfigCamBehaviour1 lookAtAgent;
public ConfigCamBehaviour2 followAgent;
public ConfigVect2 CamResolution;
public ConfigCam()
{
position = new ConfigVect3();
rotation = new ConfigVect3();
lookAtAgent = new ConfigCamBehaviour1();
followAgent = new ConfigCamBehaviour2();
CamResolution = new ConfigVect2(new Vector2(-1,-1));
}
}
/// <summary>
/// Vector 2D that can be serialize in XML config
/// </summary>
public class ConfigVect2
{
[XmlAttribute]
public float x;
[XmlAttribute]
public float y;
public ConfigVect2()
{
x = 0;
y = 0;
}
public ConfigVect2(Vector2 vect)
{
x = vect.x;
y = vect.y;
}
public Vector2 vect
{
get { return new Vector2(x, y); }
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment