Exemplo n.º 1
0
        public void reportStatus(SimulatorStatus value, string message = "")
        {
            Console.WriteLine($"[LOADER] Update simulation status {status} -> {value}");

            var previous  = reportedStatus(status);
            var newStatus = reportedStatus(value);

            status = value;

            if (value == SimulatorStatus.Error && SimulatorManager.InstanceAvailable)
            {
                SimulatorManager.Instance.AnalysisManager.AddErrorEvent(message);
            }

            if (previous == newStatus)
            {
                return;
            }

            if (ConnectionManager.instance != null)
            {
                ConnectionManager.instance.UpdateStatus(newStatus, CurrentSimulation.Id, message);
            }

            if (value == SimulatorStatus.Idle)
            {
                currentSimulation = null;
            }

            if (status == SimulatorStatus.Running)
            {
                WindowFlasher.Flash();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Starts flashing window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FlashWindow(object sender, EventArgs e)
 {
     // If is active, flashes only once
     if (IsActive)
     {
         WindowFlasher.Flash(this, 1);
     }
     else
     {
         WindowFlasher.Start(this);
     }
 }
Exemplo n.º 3
0
        public void reportStatus(SimulatorStatus value, string message = "")
        {
            Debug.Log($"loader status: {status}->{value} {message}");
            Console.WriteLine($"[LOADER] Update simulation status {status} -> {value}");

            if (value < status && !(status == SimulatorStatus.Stopping && value == SimulatorStatus.Idle))
            {
                throw new Exception($"Attemted to transition simulation status from {Enum.GetName(typeof(SimulatorStatus), value)} to {Enum.GetName(typeof(SimulatorStatus), status)}");
            }

            var previous  = reportedStatus(status);
            var newStatus = reportedStatus(value);

            status = value;

            if (value == SimulatorStatus.Error && SimulatorManager.InstanceAvailable)
            {
                SimulatorManager.Instance.AnalysisManager.AddErrorEvent(message);
            }

            if (previous == newStatus)
            {
                return;
            }

            if (ConnectionManager.instance != null &&
                ConnectionManager.Status != ConnectionManager.ConnectionStatus.Offline &&
                CurrentSimulation != null)
            {
                ConnectionManager.instance.UpdateStatus(newStatus, CurrentSimulation.Id, message);
            }

            if (value == SimulatorStatus.Idle)
            {
                currentSimulation = null;
            }

            if (status == SimulatorStatus.Running)
            {
                WindowFlasher.Flash();
            }
        }
Exemplo n.º 4
0
        static void SetupScene(SimulationModel simulation)
        {
            Dictionary <string, GameObject> cachedVehicles = new Dictionary <string, GameObject>();

            using (var db = DatabaseManager.Open())
            {
                try
                {
                    foreach (var agentConfig in Instance.SimConfig.Agents)
                    {
                        var         bundlePath    = agentConfig.AssetBundle;
                        AssetBundle textureBundle = null;
                        AssetBundle vehicleBundle = null;
                        if (cachedVehicles.ContainsKey(agentConfig.Name))
                        {
                            agentConfig.Prefab = cachedVehicles[agentConfig.Name];
                            continue;
                        }

                        using (ZipFile zip = new ZipFile(bundlePath))
                        {
                            Manifest manifest;
                            ZipEntry entry = zip.GetEntry("manifest");
                            using (var ms = zip.GetInputStream(entry))
                            {
                                int    streamSize = (int)entry.Size;
                                byte[] buffer     = new byte[streamSize];
                                streamSize = ms.Read(buffer, 0, streamSize);
                                manifest   = new Deserializer().Deserialize <Manifest>(Encoding.UTF8.GetString(buffer, 0, streamSize));
                            }

                            if (manifest.bundleFormat != BundleConfig.VehicleBundleFormatVersion)
                            {
                                zip.Close();

                                // TODO: proper exception
                                throw new ZipException("BundleFormat version mismatch");
                            }

                            var texStream = zip.GetInputStream(zip.GetEntry($"{manifest.bundleGuid}_vehicle_textures"));
                            textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20);

                            string platform  = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux";
                            var    mapStream = zip.GetInputStream(zip.GetEntry($"{manifest.bundleGuid}_vehicle_main_{platform}"));

                            vehicleBundle = AssetBundle.LoadFromStream(mapStream, 0, 1 << 20);

                            if (vehicleBundle == null)
                            {
                                throw new Exception($"Failed to load '{agentConfig.Name}' vehicle asset bundle");
                            }

                            try
                            {
                                var vehicleAssets = vehicleBundle.GetAllAssetNames();
                                if (vehicleAssets.Length != 1)
                                {
                                    throw new Exception($"Unsupported '{agentConfig.Name}' vehicle asset bundle, only 1 asset expected");
                                }

                                // TODO: make this async
                                if (!AssetBundle.GetAllLoadedAssetBundles().Contains(textureBundle))
                                {
                                    textureBundle?.LoadAllAssets();
                                }

                                agentConfig.Prefab = vehicleBundle.LoadAsset <GameObject>(vehicleAssets[0]);
                                cachedVehicles.Add(agentConfig.Name, agentConfig.Prefab);
                            }
                            finally
                            {
                                textureBundle?.Unload(false);
                                vehicleBundle.Unload(false);
                            }
                        }
                    }

                    var sim = CreateSimulationManager();

                    Instance.CurrentSimulation        = simulation;
                    Instance.CurrentSimulation.Status = "Running";
                    // Notify WebUI simulation is running
                    NotificationManager.SendNotification("simulation",
                                                         SimulationResponse.Create(Loader.Instance.CurrentSimulation),
                                                         Loader.Instance.CurrentSimulation.Owner);

                    if (Instance.SimConfig.Clusters.Length == 0)
                    {
                        // Flash main window to let user know simulation is ready
                        WindowFlasher.Flash();
                    }
                }
                catch (ZipException ex)
                {
                    Debug.Log($"Failed to start '{simulation.Name}' simulation - out of date asset bundles");
                    Debug.LogException(ex);

                    // NOTE: In case of failure we have to update Simulation state
                    simulation.Status = "Invalid";
                    simulation.Error  = "Out of date Vehicle AssetBundle. Please check content website for updated bundle or rebuild the bundle.";
                    db.Update(simulation);

                    // TODO: take ex.Message and append it to response here
                    NotificationManager.SendNotification("simulation", SimulationResponse.Create(simulation), simulation.Owner);

                    ResetLoaderScene();
                }
                catch (Exception ex)
                {
                    Debug.Log($"Failed to start '{simulation.Name}' simulation");
                    Debug.LogException(ex);

                    // NOTE: In case of failure we have to update Simulation state
                    simulation.Status = "Invalid";
                    simulation.Error  = ex.Message;
                    db.Update(simulation);

                    // TODO: take ex.Message and append it to response here
                    NotificationManager.SendNotification("simulation", SimulationResponse.Create(simulation), simulation.Owner);

                    ResetLoaderScene();
                }
            }
        }
Exemplo n.º 5
0
        static void SetupScene(SimulationModel simulation)
        {
            using (var db = DatabaseManager.Open())
            {
                try
                {
                    foreach (var agentConfig in Instance.SimConfig.Agents)
                    {
                        var bundlePath = agentConfig.AssetBundle;

                        // TODO: make this async
                        var vehicleBundle = AssetBundle.LoadFromFile(bundlePath);
                        if (vehicleBundle == null)
                        {
                            throw new Exception($"Failed to load '{agentConfig.Name}' vehicle asset bundle");
                        }

                        try
                        {
                            var vehicleAssets = vehicleBundle.GetAllAssetNames();
                            if (vehicleAssets.Length != 1)
                            {
                                throw new Exception($"Unsupported '{agentConfig.Name}' vehicle asset bundle, only 1 asset expected");
                            }

                            // TODO: make this async
                            agentConfig.Prefab = vehicleBundle.LoadAsset <GameObject>(vehicleAssets[0]);
                        }
                        finally
                        {
                            vehicleBundle.Unload(false);
                        }
                    }

                    var sim = CreateSimulationManager();

                    // TODO: connect to cluster instances
                    //if (Instance.SimConfig.Clusters.Length > 0)
                    //{
                    //    SimulatorManager.SetTimeScale(0);

                    //    Instance.PendingSimulation = simulation;

                    //    StartNetworkMaster();
                    //    Instance.Master.AddClients(Instance.SimConfig.Clusters);
                    //}
                    //else
                    {
                        Instance.CurrentSimulation = simulation;

                        // Notify WebUI simulation is running
                        Instance.CurrentSimulation.Status = "Running";
                        NotificationManager.SendNotification("simulation", SimulationResponse.Create(Instance.CurrentSimulation), Instance.CurrentSimulation.Owner);

                        // Flash main window to let user know simulation is ready
                        WindowFlasher.Flash();
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"Failed to start '{simulation.Name}' simulation");
                    Debug.LogException(ex);

                    // NOTE: In case of failure we have to update Simulation state
                    simulation.Status = "Invalid";
                    db.Update(simulation);

                    // TODO: take ex.Message and append it to response here
                    NotificationManager.SendNotification("simulation", SimulationResponse.Create(simulation), simulation.Owner);

                    ResetLoaderScene();
                }
            }
        }
Exemplo n.º 6
0
        public ParsedOutputWriter(MudClientForm form)
        {
            Store.TcpSend.Subscribe((message) => {
                // output = output + "\n"; // seems to be the most like zMud
                form.WriteToOutput(" " + message + " ", MudColors.CommandColor);
            });

            Store.ClientInfo.Subscribe((message) => {
                form.WriteToOutput("\n" + message + "\n", MudColors.ClientInfoColor);
            });


            Store.ParsedOutput.Subscribe((parsedOutputs) => {
                foreach (var p in parsedOutputs)
                {
                    switch (p.Type)
                    {
                    case ParsedOutputType.Raw:
                        // todo: dont unsplit things, dont decode things ~ waste of time & effort
                        // probably copy paste a custom version of .FormatOutput

                        /*var lines = p.Lines;
                         * for (int i = 0; i < p.Lines.Length; i++) {
                         *  if (!string.IsNullOrWhiteSpace(p.Lines[i])) {
                         *      lines[i] = p.LineMetadata[i].Type.ToString().PadRight(15)[..15] + " " + p.Lines[i];
                         *  }
                         * }*/

                        var formattedOutput = FormatDecodedText.Format(ControlCharacterEncoder.Decode(string.Join("\n", p.Lines) + "\n"));
                        form.WriteToOutput(formattedOutput);

                        if (!form.ContainsFocus)
                        {
                            WindowFlasher.Flash(form);
                        }
                        break;

                    case ParsedOutputType.Room:
                        // todo: there's a break between rooms even if it was a dline

                        form.WriteToOutput("\n" + p.Title, MudColors.RoomTitle);
                        // form.WriteToOutput(string.Join("\n", p.Description) + "\n", MudColors.ForegroundColor);
                        form.WriteToOutput(p.Exits + "\n", MudColors.RoomExits);
                        if (p.Tracks.Length > 0)
                        {
                            form.WriteToOutput(string.Join("\n", p.Tracks) + "\n", MudColors.Tracks);
                        }
                        if (p.Items.Length > 0)
                        {
                            form.WriteToOutput(string.Join("\n", p.Items) + "\n", MudColors.ItemsOnFloor);
                        }
                        if (p.Creatures.Length > 0)
                        {
                            // Todo: does this work correctly? also it's inefficient
                            form.WriteToOutput(FormatDecodedText.Format(ControlCharacterEncoder.Decode("\\x1B[33m" + string.Join("\n", p.Creatures) + "\n")));
                        }

                        break;

                    case ParsedOutputType.Status:
                        form.WriteToOutput(p.Lines[0] + " ", MudColors.ForegroundColor);
                        break;

                    default:
                        throw new Exception("Unhandled parsed output type");
                    }
                }
            });
        }
 public static void Notify(Window window, BroadcastMessage message)
 {
     WindowFlasher.Flash(window);
 }