Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
AbstractNeodroidManager.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
11 using UnityEngine;
12 using Object = System.Object;
13 #if UNITY_EDITOR
14 using UnityEditor;
15 
16 #endif
17 
18 namespace droid.Runtime.Managers {
22  [DisallowMultipleComponent]
23  public abstract class AbstractNeodroidManager : MonoBehaviour,
24  IManager {
27  public static AbstractNeodroidManager Instance { get; private set; }
28 
32  get {
33  if (this._configuration == null) {
34  this._configuration = ScriptableObject.CreateInstance<SimulatorConfiguration>();
35  }
36 
37  return this._configuration;
38  }
39  set { this._configuration = (SimulatorConfiguration)value; }
40  }
41 
45  public event Action EarlyFixedUpdateEvent;
46 
49  public event Action FixedUpdateEvent;
50 
53  public event Action LateFixedUpdateEvent;
54 
58  public event Action EarlyUpdateEvent;
59 
62  public event Action UpdateEvent;
63 
66  public event Action LateUpdateEvent;
67 
70  public event Action OnPostRenderEvent;
71 
74  public event Action OnRenderImageEvent;
75 
78  public event Action OnEndOfFrameEvent;
79 
82  public event Action OnReceiveEvent;
83 
86  void FetchCommandLineArguments() {
87  var arguments = Environment.GetCommandLineArgs();
88 
89  for (var i = 0; i < arguments.Length; i++) {
90  if (arguments[i] == "-ip") {
91  this.Configuration.IpAddress = arguments[i + 1];
92  }
93 
94  if (arguments[i] == "-port") {
95  this.Configuration.Port = int.Parse(arguments[i + 1]);
96  }
97  }
98  }
99 
102  void CreateMessagingServer() {
103  try {
104  if (this.Configuration.IpAddress != "" || this.Configuration.Port != 0) {
105  this._Message_Server = new MessageServer(this.Configuration.IpAddress,
106  this.Configuration.Port,
107  false,
108  this.Debugging);
109  } else {
110  this._Message_Server = new MessageServer(this.Debugging);
111  }
112  } catch (Exception exception) {
113  Debug.Log(exception);
114  throw;
115 
116  //TODO: close application is port is already in use.
117  }
118  }
119 
123  void StartMessagingServer(bool threaded = false) {
124  /*if (threaded) {
125  this._Message_Server.ListenForClientToConnect(this.OnConnectCallback, this.OnDebugCallback);
126  #if NEODROID_DEBUG
127 
128  if (this.Debugging) {
129  Debug.Log("Started Messaging Server in a new thread");
130  }
131  #endif
132  } else {*/
133 
134  this._Message_Server.ListenForClientToConnect(this.OnDebugCallback);
135  #if NEODROID_DEBUG
136  if (this.Debugging) {
137  Debug.Log(" Messaging Server is listening for clients");
138  }
139  #endif
140 
141  if (threaded) {
142  this.OnListeningCallback();
143  }
144 
145  //}
146  }
147 
152  public void StatusString(DataPoller recipient) { recipient.PollData(this.GetStatus()); }
153 
154  #region PrivateFields
155 
158  [Header("Development", order = 110)]
159  [SerializeField]
160  bool _debugging;
161 
164  Object _send_lock = new Object();
165 
168  [SerializeField]
169  bool _testing_Actuators;
170 
171  #if UNITY_EDITOR
172  const int _script_execution_order = -1000;
175  #endif
176 
179  [Header("Simulation", order = 80)]
180  [SerializeField]
181  SimulatorConfiguration _configuration;
182 
185  [SerializeField]
186  int _skip_frame_i;
187 
190  [SerializeField]
191  bool _syncing_environments;
192 
195  [SerializeField]
196  bool _awaiting_reply;
197 
198  [SerializeField] bool _step;
199 
200  WaitForEndOfFrame _wait_for_end_of_frame = new WaitForEndOfFrame();
201  WaitForFixedUpdate _wait_for_fixed_update = new WaitForFixedUpdate();
202  List<Reaction> _sample_reactions = new List<Reaction>();
203 
204  #endregion
205 
206  #region Getter And Setters
207 
210  public Reaction[] CurrentReactions {
211  get {
212  lock (this._send_lock) {
213  return this._Current_Reactions;
214  }
215  }
216  set {
217  lock (this._send_lock) {
218  this._Current_Reactions = value;
219  }
220  }
221  }
222 
225  public float SimulationTimeScale {
226  get { return Time.timeScale; }
227  set {
228  #if UNITY_EDITOR
229  Time.timeScale = Math.Min(value, 99);
230  this._last_simulation_time = Math.Min(value, 99);
231  #else
232  Time.timeScale = value;
233  this._last_simulation_time = value;
234  #endif
235 
236  if (this.Configuration.UpdateFixedTimeScale) {
237  Time.fixedDeltaTime = 0.02F * Time.timeScale;
238  }
239  }
240  }
241 
242  [SerializeField] float _last_simulation_time;
243 
246  public bool HasStepped { get { return this._has_stepped; } set { this._has_stepped = value; } }
247 
250  public bool TestActuators {
251  get { return this._testing_Actuators; }
252  set { this._testing_Actuators = value; }
253  }
254 
257  public bool Debugging {
258  get { return this._debugging; }
259  set {
260  if (this._Message_Server != null) {
261  this._Message_Server.Debugging = value;
262  }
263 
264  this._debugging = value;
265  }
266  }
267 
270  public bool AwaitingReply {
271  get {
272  lock (this._send_lock) {
273  return this._awaiting_reply;
274  }
275  }
276  set {
277  lock (this._send_lock) {
278  this._awaiting_reply = value;
279  }
280  }
281  }
282 
283  public ISimulatorConfiguration SimulatorConfiguration { get { return this._configuration; } }
284 
287  public bool IsSyncingEnvironments {
288  get { return this._syncing_environments; }
289  set { this._syncing_environments = value; }
290  }
291 
294  public bool Stepping { get { return this._step; } }
295 
296  #endregion
297 
298  #region PrivateMembers
299 
302  protected Dictionary<string, IEnvironment> _Environments = new Dictionary<string, IEnvironment>();
303 
306  public void Clear() { this._Environments.Clear(); }
307 
311 
314  protected Reaction[] _Current_Reactions = { };
315 
316  [SerializeField] bool _has_stepped;
317 
318  #endregion
319 
320  #region UnityCallbacks
321 
324  protected void Awake() {
325  if (Instance == null) {
326  Instance = this;
327  } else if (Instance == this) {
328  #if NEODROID_DEBUG
329  if (this.Debugging) {
330  Debug.Log("Using " + Instance);
331  }
332  #endif
333  } else {
334  Debug.LogWarning("WARNING! There are multiple SimulationManagers in the scene! Only using "
335  + Instance);
336  }
337 
338  #if UNITY_EDITOR
339  if (!Application.isPlaying) {
340  var manager_script = MonoScript.FromMonoBehaviour(this);
341  if (MonoImporter.GetExecutionOrder(manager_script) != _script_execution_order) {
342  MonoImporter.SetExecutionOrder(manager_script,
343  _script_execution_order); // Ensures that PreStep is called first, before all other scripts.
344  Debug.LogWarning("Execution Order changed, you will need to press play again to make everything function correctly!");
345  EditorApplication.isPlaying = false;
346  //TODO: UnityEngine.Experimental.LowLevel.PlayerLoop.SetPlayerLoop(new UnityEngine.Experimental.LowLevel.PlayerLoopSystem());
347  }
348  }
349  #endif
350  }
351 
354  protected void Start() {
355  this.FetchCommandLineArguments();
356 
357  if (this.Configuration == null) {
358  this.Configuration = ScriptableObject.CreateInstance<SimulatorConfiguration>();
359  }
360 
361  this.ApplyConfigurationToUnity(this.Configuration);
362 
363  if (this.Configuration.SimulationType == SimulationType.Physics_dependent_) {
364  this.EarlyFixedUpdateEvent += this.OnPreTick;
365  this.FixedUpdateEvent += this.OnTick;
366  this.FixedUpdateEvent += this.Tick;
367  this.LateFixedUpdateEvent += this.OnPostTick;
368  this.StartCoroutine(this.LateFixedUpdateEventGenerator());
369  } else {
370  this.EarlyUpdateEvent += this.OnPreTick;
371  this.UpdateEvent += this.OnTick;
372  this.UpdateEvent += this.Tick;
373  switch (this.Configuration.FrameFinishes) {
374  case FrameFinishes.Late_update_:
375  this.LateUpdateEvent += this.OnPostTick;
376  break;
377  case FrameFinishes.On_post_render_:
378  this.OnPostRenderEvent += this.OnPostTick;
379  break;
380  case FrameFinishes.On_render_image_:
381  this.OnRenderImageEvent += this.OnPostTick;
382  break;
383  case FrameFinishes.End_of_frame_:
384  this.StartCoroutine(this.EndOfFrameEventGenerator());
385  this.OnEndOfFrameEvent += this.OnPostTick;
386  break;
387  default: throw new ArgumentOutOfRangeException();
388  }
389  }
390 
391  this.CreateMessagingServer();
392  if (this.Configuration.SimulationType == SimulationType.Physics_dependent_) {
393  this.StartMessagingServer(); // Remember to manually bind receive to an event in a derivation
394  } else {
395  this.StartMessagingServer(true);
396  }
397  }
398 
402  if (configuration.ApplyQualitySettings) {
403  QualitySettings.SetQualityLevel(configuration.QualityLevel, true);
404  QualitySettings.vSyncCount = configuration.VSyncCount;
405  }
406 
407  this.SimulationTimeScale = configuration.TimeScale;
408  Application.targetFrameRate = configuration.TargetFrameRate;
409 
410  if (this._configuration.OptimiseWindowForSpeed) {
411  Screen.SetResolution(1, 1, false);
412  }
413  #if !UNITY_EDITOR
414  else if( configuration.ApplyResolutionSettings ){
415  Screen.SetResolution(
416  width : configuration.Width,
417  height : configuration.Height,
418  fullscreen : configuration.FullScreen);
419  }
420  #else
421 
422  PlayerSettings.resizableWindow = configuration.ResizableWindow;
423  PlayerSettings.colorSpace = configuration.ColorSpace;
424  PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
425  //PlayerSettings.use32BitDisplayBuffer
426  #endif
427  }
428 
431  void OnPostRender() { this.OnPostRenderEvent?.Invoke(); }
432 
437  void OnRenderImage(RenderTexture src, RenderTexture dest) {
438  this.OnRenderImageEvent?.Invoke(); //TODO: May not work
439  }
440 
443  protected void FixedUpdate() {
444  this.EarlyFixedUpdateEvent?.Invoke();
445  this.FixedUpdateEvent?.Invoke();
446  }
447 
451  IEnumerator LateFixedUpdateEventGenerator() {
452  while (true) {
453  yield return this._wait_for_fixed_update;
454  #if NEODROID_DEBUG
455  if (this.Debugging) {
456  Debug.Log("LateFixedUpdate");
457  }
458  #endif
459  this.LateFixedUpdateEvent?.Invoke();
460  }
461 
462  // ReSharper disable once IteratorNeverReturns
463  }
464 
468  protected IEnumerator EndOfFrameEventGenerator() {
469  while (true) {
470  yield return this._wait_for_end_of_frame;
471  //yield return new WaitForEndOfFrame();
472  #if NEODROID_DEBUG
473  if (this.Debugging) {
474  Debug.Log("EndOfFrameEvent");
475  }
476  #endif
477  this.OnEndOfFrameEvent?.Invoke();
478  }
479  #pragma warning disable 162
480  // ReSharper disable once HeuristicUnreachableCode
481  yield return null;
482  #pragma warning restore 162
483  // ReSharper disable once IteratorNeverReturns
484  }
485 
488  protected void Update() {
489  this.EarlyUpdateEvent?.Invoke();
490  this.UpdateEvent?.Invoke();
491  }
492 
495  protected void LateUpdate() { this.LateUpdateEvent?.Invoke(); }
496 
497  #endregion
498 
499  #region PrivateMethods
500 
503  protected void OnPreTick() {
504  #if NEODROID_DEBUG
505  if (this.Debugging) {
506  Debug.Log("OnPreTick");
507  }
508  #endif
509 
510  if (this.Configuration.StepExecutionPhase == ExecutionPhase.Before_) {
511  this.ExecuteStep();
512  }
513  }
514 
517  protected void OnTick() {
518  #if NEODROID_DEBUG
519  if (this.Debugging) {
520  Debug.Log("OnTick");
521  }
522  #endif
523  if (this.Configuration.StepExecutionPhase == ExecutionPhase.Middle_) {
524  this.ExecuteStep();
525  }
526  }
527 
530  protected void OnPostTick() {
531  #if NEODROID_DEBUG
532  if (this.Debugging) {
533  Debug.Log("OnPostTick");
534  }
535  #endif
536 
537  foreach (var environment in this._Environments.Values) {
538  environment.PostStep();
539  }
540 
541  if (this.Configuration.StepExecutionPhase == ExecutionPhase.After_) {
542  this.ExecuteStep();
543  }
544 
545  if (this._has_stepped) {
546  this.ClearCurrentReactions();
547  }
548  }
549 
552  void ExecuteStep() {
553  if (!this._syncing_environments) {
554  this.React(this.CurrentReactions);
555  }
556 
557  if (this.AwaitingReply) {
558  var states = this.CollectStates();
559  this.PostReact(states);
560  }
561 
562  this.HasStepped = true;
563  }
564 
567  protected void Tick() {
568  if (this.TestActuators) {
569  this.React(this.SampleRandomReactions());
570  this.CollectStates();
571  }
572 
573  foreach (var environment in this._Environments.Values) {
574  environment.Tick();
575  }
576 
577  #if NEODROID_DEBUG
578  if (this.Debugging) {
579  Debug.Log("Tick");
580  }
581  #endif
582  }
583 
587  protected void PostReact(EnvironmentState[] states) {
588  lock (this._send_lock) {
589  foreach (var env in this._Environments.Values) {
590  if (env.IsResetting) {
591  #if NEODROID_DEBUG
592  if (this.Debugging) {
593  Debug.Log($"Environment {env} is resetting");
594  }
595  #endif
596 
597  this._syncing_environments = true;
598  return;
599  }
600  }
601 
602  this._syncing_environments = false;
603  if (this._skip_frame_i >= this.Configuration.FrameSkips) {
604  #if NEODROID_DEBUG
605  if (this.Debugging) {
606  Debug.Log("Not skipping frame, replying...");
607  }
608  #endif
609 
610  this.Reply(states);
611  this.AwaitingReply = false;
612  this._skip_frame_i = 0;
613  } else {
614  this._skip_frame_i += 1;
615  #if NEODROID_DEBUG
616  if (this.Debugging) {
617  Debug.Log($"Skipping frame, {this._skip_frame_i}/{this.Configuration.FrameSkips}");
618  }
619  #endif
620  if (this.Configuration.ReplayReactionInSkips) { }
621  }
622  }
623  }
624 
629  this._sample_reactions.Clear();
630  foreach (var environment in this._Environments.Values) {
631  this._sample_reactions.Add(environment.SampleReaction());
632  }
633 
634  return this._sample_reactions.ToArray();
635  }
636 
637  //TODO: Maybe add EnvironmentState[][] states for aggregation of states in unity side buffer, when using skips?
641  void Reply(EnvironmentState[] states) {
642  lock (this._send_lock) {
643  var configuration_message = new SimulatorConfigurationMessage(this.Configuration);
644  var describe = false;
645  if (this.CurrentReactions != null) {
646  foreach (var reaction in this.CurrentReactions) {
647  if (reaction.Parameters.Describe) {
648  describe = true;
649  }
650  }
651  }
652 
653  this._Message_Server.SendStates(states,
654  simulator_configuration_message : configuration_message,
655  do_serialise_unobservables :
656  describe || this.Configuration.AlwaysSerialiseUnobservables,
657  serialise_individual_observables :
658  describe || this.Configuration.AlwaysSerialiseIndividualObservables,
659  serialise_aggregated_float_array : describe
660  || this._configuration
661  .AlwaysSerialiseAggregatedFloatArray);
662  #if NEODROID_DEBUG
663  if (this.Debugging) {
664  Debug.Log("Replying");
665  }
666 
667  #endif
668  }
669  }
670 
673  void ClearCurrentReactions() {
674  this._step = false;
675  this.CurrentReactions = new Reaction[] { };
676  }
677 
678  #endregion
679 
680  #region PublicMethods
681 
687  this.SetStepping(reaction);
688  var states = new EnvironmentState[this._Environments.Values.Count];
689  var i = 0;
690  foreach (var environment in this._Environments.Values) {
691  if (reaction.RecipientEnvironment != "all") {
692  #if NEODROID_DEBUG
693  if (this.Debugging) {
694  Debug.Log($"Applying reaction to {reaction.RecipientEnvironment} environment");
695  }
696  #endif
697  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
698  states[i++] = this._Environments[reaction.RecipientEnvironment].ReactAndCollectState(reaction);
699  }
700  #if NEODROID_DEBUG
701  else {
702  if (this.Debugging) {
703  Debug.Log($"Could not find environment: {reaction.RecipientEnvironment}");
704  }
705  }
706  #endif
707  } else {
708  #if NEODROID_DEBUG
709  if (this.Debugging) {
710  Debug.Log("Applying reaction to all environments");
711  }
712  #endif
713  states[i++] = environment.ReactAndCollectState(reaction);
714  }
715  }
716 
717  return states;
718  }
719 
724  public void React(Reaction reaction) {
725  this.SetStepping(reaction);
726  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
727  this._Environments[reaction.RecipientEnvironment].React(reaction);
728  } else {
729  #if NEODROID_DEBUG
730  if (this.Debugging) {
731  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
732  }
733  #endif
734 
735  #if NEODROID_DEBUG
736  if (this.Debugging) {
737  Debug.Log("Applying to all environments");
738  }
739  #endif
740 
741  foreach (var environment in this._Environments.Values) {
742  environment.React(reaction);
743  }
744  }
745  }
746 
751  public void React(Reaction[] reactions) {
752  this.SetStepping(reactions);
753  foreach (var reaction in reactions) {
754  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
755  this._Environments[reaction.RecipientEnvironment].React(reaction);
756  } else if (reaction.RecipientEnvironment == "all") {
757  #if NEODROID_DEBUG
758  if (this.Debugging) {
759  Debug.Log("Applying to all environments");
760  }
761  #endif
762 
763  foreach (var environment in this._Environments.Values) {
764  environment.React(reaction);
765  }
766  } else {
767  #if NEODROID_DEBUG
768  if (this.Debugging) {
769  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
770  }
771  #endif
772  }
773  }
774  }
775 
780  var environments = this._Environments.Values;
781  var states = new EnvironmentState[environments.Count];
782  var i = 0;
783  foreach (var environment in environments) {
784  states[i++] = environment.CollectState();
785  }
786 
787  return states;
788  }
789 
790  void SetStepping(Reaction reaction) {
791  if (reaction.Parameters.Step) {
792  this.SetStepping(true);
793  }
794  }
795 
796  void SetStepping(bool step) {
797  if (step) {
798  #if NEODROID_DEBUG
799  if (this.Debugging) {
800  Debug.Log("Stepping from Reaction");
801  }
802  #endif
803 
804  this._step = true;
805  } else {
806  #if NEODROID_DEBUG
807  if (this.Debugging) {
808  Debug.Log("Not stepping from Reaction");
809  }
810  #endif
811  if (this.HasStepped) {
812  this._step = false;
813  }
814  }
815  }
816 
817  void SetStepping(Reaction[] reactions) {
818  if (reactions.Any(reaction => reaction.Parameters.Step)) {
819  this.SetStepping(true);
820  }
821  }
822 
823  public void SetTesting(bool arg0) { this.TestActuators = arg0; }
824 
825 /*
831  public EnvironmentState[] ReactAndCollectStates(Reaction[] reactions) {
832  this.SetStepping(reactions);
833  var states = new EnvironmentState[reactions.Length * this._Environments.Count];
834  var i = 0;
835  foreach (var reaction in reactions) {
836  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
837  states[i++] = this._Environments[reaction.RecipientEnvironment].ReactAndCollectState(reaction);
838  } else {
839  #if NEODROID_DEBUG
840  if (this.Debugging) {
841  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
842  }
843  #endif
844 
845  #if NEODROID_DEBUG
846  if (this.Debugging) {
847  Debug.Log($"Applying to all environments");
848  }
849  #endif
850 
851  foreach (var environment in this._Environments.Values) {
852  states[i++] = environment.ReactAndCollectState(reaction);
853  }
854  }
855  }
856 
857  return states;
858  }
859 */
860 
863  public void ResetAllEnvironments() {
864  this.React(new Reaction(new ReactionParameters(true, false, true, episode_count : true),
865  null,
866  null,
867  null,
868  null,
869  ""));
870  }
871 
875  public string GetStatus() {
876  if (this._Message_Server != null) {
877  return this._Message_Server._Listening_For_Clients ? "Connected" : "Not Connected";
878  }
879 
880  return "No server";
881  }
882 
883  #endregion
884 
885  #region Registration
886 
891  public void Register(IEnvironment environment) { this.Register(environment, environment.Identifier); }
892 
898  public void Register(IEnvironment environment, string identifier) {
899  if (!this._Environments.ContainsKey(identifier)) {
900  #if NEODROID_DEBUG
901  if (this.Debugging) {
902  Debug.Log($"Manager {this.name} already has an environment with the identifier: {identifier}");
903  }
904  #endif
905 
906  this._Environments.Add(identifier, environment);
907  } else {
908  Debug.LogWarning($"WARNING! Please check for duplicates, SimulationManager {this.name} "
909  + $"already has environment {identifier} registered");
910  }
911  }
912 
917  public void UnRegister(IEnvironment environment, string identifier) {
918  if (this._Environments.ContainsKey(identifier)) {
919  #if NEODROID_DEBUG
920  if (this.Debugging) {
921  Debug.Log($"SimulationManager {this.name} unregistered Environment {identifier}");
922  }
923  #endif
924 
925  this._Environments.Remove(identifier);
926  }
927  }
928 
932  public void UnRegister(IEnvironment neodroid_environment) {
933  this.UnRegister(neodroid_environment, neodroid_environment.Identifier);
934  }
935 
936  #endregion
937 
938  #region MessageServerCallbacks
939 
943  void OnReceiveCallback(Reaction[] reactions) {
944  lock (this._send_lock) {
945  #if NEODROID_DEBUG
946  if (this.Debugging) {
947  Debug.Log($"Received: {reactions.Select(r => r.ToString()).Aggregate((current, next) => $"{current}, {next}")}");
948  }
949  #endif
950 
951  this.SetReactionsFromExternalSource(reactions);
952 
953  this.OnReceiveEvent?.Invoke();
954  }
955  }
956 
960  protected void SetReactionsFromExternalSource(Reaction[] reactions) {
961  lock (this._send_lock) {
962  if (reactions != null) {
963  if (this.AwaitingReply || !this.HasStepped) {
964  #if NEODROID_DEBUG
965  if (this.Debugging) {
966  Debug.Log($"Got new reaction while not having stepped({!this.HasStepped}) or replied({this.AwaitingReply})");
967  }
968  #endif
969  }
970 
971  this.CurrentReactions = reactions;
972  foreach (var current_reaction in this.CurrentReactions) {
973  current_reaction.Parameters.IsExternal = true;
974  }
975 
976  this.Configuration.StepExecutionPhase = this.CurrentReactions[0].Parameters.Phase;
977  this.AwaitingReply = true;
978  this.HasStepped = false;
979  } else {
980  Debug.LogWarning("Reaction was null");
981  }
982  }
983  }
984 
987  void OnDisconnectCallback() {
988  #if NEODROID_DEBUG
989  if (this.Debugging) {
990  Debug.Log("Client disconnected.");
991  }
992  #endif
993  }
994 
998  void OnDebugCallback(string error) {
999  #if NEODROID_DEBUG
1000  if (this.Debugging) {
1001  Debug.Log("DebugCallback: " + error);
1002  }
1003  #endif
1004  }
1005 
1008  void OnListeningCallback() {
1009  #if NEODROID_DEBUG
1010  if (this.Debugging) {
1011  Debug.Log("Client connected");
1012  }
1013  #endif
1014 
1015  this._Message_Server.StartReceiving(this.OnReceiveCallback,
1016  this.OnDisconnectCallback,
1017  this.OnDebugCallback);
1018  }
1019 
1020  #endregion
1021 
1022  #region Deconstruction
1023 
1026  void OnApplicationQuit() { this._Message_Server.CleanUp(); }
1027 
1030  void OnDestroy() { this._Message_Server.Destroy(); }
1031 
1032  #endregion
1033  }
1034 }
void ApplyConfigurationToUnity(ISimulatorConfiguration configuration)
Action EarlyUpdateEvent
Can be subscribed to for pre update events (Will be called before any Update on any script) ...
void SendStates(EnvironmentState[] environment_states, bool do_serialise_unobservables=false, bool serialise_individual_observables=false, bool serialise_aggregated_float_array=false, SimulatorConfigurationMessage simulator_configuration_message=null, string api_version=_api_version)
void Register(IEnvironment environment, string identifier)
Contains everything relevant to configuring simulation environments engine specific settings ...
void StartReceiving(Action< Reaction[]> cmd_callback, Action disconnect_callback, Action< string > debug_callback)
FrameFinishes
Determines where in the monobehaviour cycle a frame/step is finished
Definition: FrameFinishes.cs:5
EnvironmentState [] ReactAndCollectStates(Reaction reaction)
Action EarlyFixedUpdateEvent
Can be subscribed to for pre fixed update events (Will be called before any FixedUpdate on any script...
void UnRegister(IEnvironment neodroid_environment)
System.Object Object
Configuration(string configurable_name, float configurable_value, bool sample_random=false)
Definition: Configuration.cs:8
SimulationType
Determines the discrete timesteps of the simulation environment.
void UnRegister(IEnvironment environment, string identifier)