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); }
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(); } }