public async Task StartRun() { await postgresTask; if (run != null) { PostgresExport.StopRun(run); } var runid = await PostgresExport.StartRun(curSessionId); //var s3Info = new S3FileInfo(client, "gtadata", run.archiveKey); //S3Stream = s3Info.Create(); outputPath = Path.GetTempFileName(); S3Stream = File.Open(outputPath, FileMode.Truncate); archive = new ZipArchive(S3Stream, ZipArchiveMode.Create); //archive = new ZipArchive(, ZipArchiveMode.Create); //archive = ZipFile.Open(Path.Combine(dataPath, run.guid + ".zip"), ZipArchiveMode.Create); run = runid; enabled = true; }
public VisionExport() { if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } PostgresExport.InitSQLTypes(); player = Game.Player; server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Bind(new IPEndPoint(IPAddress.Loopback, 5555)); server.Listen(5); //server = new UdpClient(5555); var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); var access_key = data["aws"]["access_key"]; var secret_key = data["aws"]["secret_key"]; //client = new AmazonS3Client(new BasicAWSCredentials(access_key, secret_key), RegionEndpoint.USEast1); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; Interval = 1000; if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } }
public VisionExport() { // loading ini file var parser = new FileIniDataParser(); location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; Logger.logFilePath = logFilePath; Logger.WriteLine("VisionExport constructor called."); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } PostgresExport.InitSQLTypes(); player = Game.Player; server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Bind(new IPEndPoint(IPAddress.Loopback, 5555)); server.Listen(5); //server = new UdpClient(5555); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; Interval = 50; if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } Logger.WriteLine("Logger prepared"); UINotify("Logger initialized. Going to initialize cameras."); CamerasList.initialize(); initialize4cameras(); // var newCamera = World.CreateCamera(new Vector3(), new Vector3(), 50); // newCamera.NearClip = 0.15f; // newCamera.IsActive = true; // newCamera.Position = new Vector3(-1078f, -216f, 37f); //// newCamera.Rotation = new Vector3(270f, 0f, 0f); // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2 // newCamera.Rotation = new Vector3(0f, 270f, 0f); // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2 // World.RenderingCamera = newCamera; // {-1078,-216,37} // CamerasList.setMainCamera(new Vector3(358f, -1308f, 52f), new Vector3(0f, 90f, 0f), 150, 0.15f); UINotify("VisionExport plugin initialized."); }
public void StopSession() { if (curSessionId == -1) { return; } PostgresExport.StopSession(curSessionId); curSessionId = -1; }
public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); enabled = false; PostgresExport.StopRun(run); run = null; Game.Player.LastVehicle.Alpha = int.MaxValue; }
public async Task StartSession() { var name = Guid.NewGuid().ToString(); if (curSessionId != -1) { StopSession(); } var id = await PostgresExport.StartSession(name); curSessionId = id; }
private void basicInit() { if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } PostgresExport.InitSQLTypes(); player = Game.Player; server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Bind(new IPEndPoint(IPAddress.Loopback, 5555)); server.Listen(5); //server = new UdpClient(5555); var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //var access_key = data["aws"]["access_key"]; //var secret_key = data["aws"]["secret_key"]; //client = new AmazonS3Client(new BasicAWSCredentials(access_key, secret_key), RegionEndpoint.USEast1); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); World.Weather = Weather.Clear; World.CurrentDayTime = new TimeSpan(14, 0, 0); timeOfDays.Add(new KeyValuePair <string, int>("Night1", 22)); // Night 1 //timeOfDays.Add(new KeyValuePair<string, int>("Night2", 23)); // Night 2 timeOfDays.Add(new KeyValuePair <string, int>("Morning1", 6)); // Morning 1 timeOfDays.Add(new KeyValuePair <string, int>("Morning2", 7)); // Morning 2 timeOfDays.Add(new KeyValuePair <string, int>("Afternoon", 13)); // Afternoon timeOfDays.Add(new KeyValuePair <string, int>("Evening", 19)); // Evening if (Game.Player.Character.IsInVehicle()) { Vehicle v = Game.Player.Character.CurrentVehicle; v.Repair(); } this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; Interval = 3000; // this variable controls after how many milliseconds script will trigger onTick() method. if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } }
public async Task StartSession(string name = session_name) { if (name == null) { name = Guid.NewGuid().ToString(); } if (curSessionId != -1) { StopSession(); } int id = await PostgresExport.StartSession(name); curSessionId = id; }
public async Task StartSession(string name = session_name) { if (name == null) { name = Guid.NewGuid().ToString(); } if (curSessionId != -1) { StopSession(); // makes sure that there is only one session at a time. } int id = await PostgresExport.StartSession(name); curSessionId = id; }
public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); if (S3Stream.CanWrite) { S3Stream.Flush(); } enabled = false; UploadFile().Wait(); PostgresExport.StopRun(run); run = null; Game.Player.LastVehicle.Alpha = int.MaxValue; }
public async Task StartRun(bool enable = true) { await postgresTask; if (run != null) { PostgresExport.StopRun(run); } var runid = await PostgresExport.StartRun(curSessionId); run = runid; if (enable) { enabled = true; } }
private void GatherDatForOneCamera(string dateTimeFormat, Guid guid) { GTAData dat; bool success; var weather = World.Weather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); if (CamerasList.activeCameraRotation.HasValue) { dat.CamRelativeRot = new GTAVector(CamerasList.activeCameraRotation.Value); } else { dat.CamRelativeRot = null; } if (CamerasList.activeCameraPosition.HasValue) { dat.CamRelativePos = new GTAVector(CamerasList.activeCameraPosition.Value); } else { dat.CamRelativePos = null; } dat.CurrentTarget = null; dat.sceneGuid = guid; if (dat == null) { return; } success = SaveSnapshotToFile(dat.ImageName); if (!success) { return; } PostgresExport.SaveSnapshot(dat, run.Id); }
public VisionExport() { // loading ini file var parser = new FileIniDataParser(); Location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(Location, "GTAVision.ini")); dataPath = data["Snapshots"]["OutputDir"]; LogFilePath = data["Snapshots"]["LogFile"]; everyNth = int.Parse(data["Snapshots"]["EveryNth"]); ticked = 0; Logger.logFilePath = LogFilePath; Logger.WriteLine("VisionExport constructor called."); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } PostgresExport.InitSQLTypes(); Tick += OnTick; KeyDown += OnKeyDown; Interval = 100; if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } Logger.WriteLine("Logger prepared"); UI.Notify("Logger initialized. Going to initialize cameras."); CamerasList.initialize(); InitializeCameras(); UI.Notify("VisionExport plugin initialized."); }
public VisionExport() { // loading ini file var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } PostgresExport.InitSQLTypes(); player = Game.Player; server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Bind(new IPEndPoint(IPAddress.Loopback, 5555)); server.Listen(5); //server = new UdpClient(5555); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; Interval = 1000; if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } }
private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { GTAData dat; bool success; if (multipleWeathers) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); } if (CamerasList.activeCameraRotation.HasValue) { dat.CamRelativeRot = new GTAVector(CamerasList.activeCameraRotation.Value); } else { dat.CamRelativeRot = null; } if (CamerasList.activeCameraPosition.HasValue) { dat.CamRelativePos = new GTAVector(CamerasList.activeCameraPosition.Value); } else { dat.CamRelativePos = null; } if (drivingOffroad && OffroadPlanning.currentTarget != null) { dat.CurrentTarget = GTAVector2.fromVector2(OffroadPlanning.currentTarget.Value); } else { dat.CurrentTarget = null; } dat.sceneGuid = guid; if (dat == null) { return; } if (multipleWeathers) { success = saveSnapshotToFile(dat.ImageName, wantedWeathers, false); } else { Weather weather = currentWeather ? World.Weather : wantedWeather; success = saveSnapshotToFile(dat.ImageName, weather, false); } if (!success) { // when getting data and saving to file failed, saving to db is skipped return; } PostgresExport.SaveSnapshot(dat, run.guid); }
public void OnTick(object o, EventArgs e) { if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); UI.Notify("CONNECTED"); connection.Blocking = false; } handlePipeInput(); if (!enabled) { return; } //Array values = Enum.GetValues(typeof(Weather)); switch (checkStatus()) { case GameStatus.NeedReload: //TODO: need to get a new session and run? StopRun(); runTask?.Wait(); runTask = StartRun(); //StopSession(); //Autostart(); UI.Notify("need reload game"); Script.Wait(100); ReloadGame(); break; case GameStatus.NeedStart: //TODO do the autostart manually or automatically? //Autostart(); // use reloading temporarily StopRun(); ReloadGame(); Script.Wait(100); runTask?.Wait(); runTask = StartRun(); //Autostart(); break; case GameStatus.NoActionNeeded: break; } if (!runTask.IsCompleted) { return; } if (!postgresTask.IsCompleted) { return; } List <byte[]> colors = new List <byte[]>(); Game.Pause(true); Script.Wait(500); GTAData dat = GTAData.DumpData(Game.GameTime + ".tiff", new List <Weather>(wantedWeather)); if (dat == null) { return; } var thisframe = VisionNative.GetCurrentTime(); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); colors.Add(VisionNative.GetColorBuffer()); /* * foreach (var wea in wantedWeather) { * World.TransitionToWeather(wea, 0.0f); * Script.Wait(1); * colors.Add(VisionNative.GetColorBuffer()); * }*/ Game.Pause(false); /* * if (World.Weather != Weather.Snowing) * { * World.TransitionToWeather(Weather.Snowing, 1); * * }*/ var colorframe = VisionNative.GetLastColorTime(); var depthframe = VisionNative.GetLastConstantTime(); var constantframe = VisionNative.GetLastConstantTime(); //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); if (depth == null || stencil == null) { return; } /* * this code checks to see if there's drift * it's kinda pointless because we end up "straddling" a present call, * so the capture time difference can be ~1/4th of a frame but still the * depth/stencil and color buffers are one frame offset from each other * if (Math.Abs(thisframe - colorframe) < 60 && Math.Abs(colorframe - depthframe) < 60 && * Math.Abs(colorframe - constantframe) < 60) * { * * * * * * PostgresExport.SaveSnapshot(dat, run.guid); * } */ ImageUtils.WaitForProcessing(); ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, Game.ScreenResolution.Height, colors, depth, stencil); PostgresExport.SaveSnapshot(dat, run.guid); if (S3Stream.Length > 512 * 1024 * 1024) { ImageUtils.WaitForProcessing(); StopRun(); runTask?.Wait(); runTask = StartRun(); } }