Neodroid  0.2.1
Machine Learning Environment Prototyping Tool
NeodroidManager.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  [AddComponentMenu("Neodroid/Managers/VanillaManager")]
24  public abstract class NeodroidManager : MonoBehaviour,
25  IManager {
28  public static NeodroidManager Instance { get; private set; }
29 
33  get {
34  if (this._configuration == null) {
35  this._configuration = ScriptableObject.CreateInstance<SimulatorConfiguration>();
36  }
37 
38  return this._configuration;
39  }
40  set { this._configuration = (SimulatorConfiguration)value; }
41  }
42 
46  public event Action EarlyFixedUpdateEvent;
47 
50  public event Action FixedUpdateEvent;
51 
54  public event Action LateFixedUpdateEvent;
55 
59  public event Action EarlyUpdateEvent;
60 
63  public event Action UpdateEvent;
64 
67  public event Action LateUpdateEvent;
68 
71  public event Action OnPostRenderEvent;
72 
75  public event Action OnRenderImageEvent;
76 
79  public event Action OnEndOfFrameEvent;
80 
83  public event Action OnReceiveEvent;
84 
87  void FetchCommandLineArguments() {
88  var arguments = Environment.GetCommandLineArgs();
89 
90  for (var i = 0; i < arguments.Length; i++) {
91  if (arguments[i] == "-ip") {
92  this.Configuration.IpAddress = arguments[i + 1];
93  }
94 
95  if (arguments[i] == "-port") {
96  this.Configuration.Port = int.Parse(arguments[i + 1]);
97  }
98  }
99  }
100 
103  void CreateMessagingServer() {
104  try {
105  if (this.Configuration.IpAddress != "" || this.Configuration.Port != 0) {
106  this._Message_Server = new MessageServer(this.Configuration.IpAddress,
107  this.Configuration.Port,
108  false,
109  this.Debugging);
110  } else {
111  this._Message_Server = new MessageServer(this.Debugging);
112  }
113  } catch (Exception exception) {
114  Debug.Log(exception);
115  throw;
116 
117  //TODO: close application is port is already in use.
118  }
119  }
120 
124  void StartMessagingServer(bool threaded = false) {
125  /*if (threaded) {
126  this._Message_Server.ListenForClientToConnect(this.OnConnectCallback, this.OnDebugCallback);
127  #if NEODROID_DEBUG
128 
129  if (this.Debugging) {
130  Debug.Log("Started Messaging Server in a new thread");
131  }
132  #endif
133  } else {*/
134 
135  this._Message_Server.ListenForClientToConnect(this.OnDebugCallback);
136  #if NEODROID_DEBUG
137  if (this.Debugging) {
138  Debug.Log(" Messaging Server is listening for clients");
139  }
140  #endif
141 
142  if (threaded) {
143  this.OnListeningCallback();
144  }
145 
146  //}
147  }
148 
149  public void StatusString(DataPoller recipient) { recipient.PollData(this.GetStatus()); }
150 
151  #region PrivateFields
152 
155  [Header("Development", order = 110)]
156  [SerializeField]
157  bool _debugging;
158 
161  Object _send_lock = new Object();
162 
165  [SerializeField]
166  bool _testing_Actuators;
167 
168  #if UNITY_EDITOR
169  const int _script_execution_order = -1000;
172  #endif
173 
176  [Header("Simulation", order = 80)]
177  [SerializeField]
178  SimulatorConfiguration _configuration;
179 
182  [SerializeField]
183  int _skip_frame_i;
184 
187  [SerializeField]
188  bool _syncing_environments;
189 
192  [SerializeField]
193  bool _awaiting_reply;
194 
195  [SerializeField] bool _step;
196 
197  WaitForEndOfFrame _wait_for_end_of_frame = new WaitForEndOfFrame();
198  WaitForFixedUpdate _wait_for_fixed_update = new WaitForFixedUpdate();
199  List<Reaction> _sample_reactions = new List<Reaction>();
200 
201  #endregion
202 
203  #region Getter And Setters
204 
207  public Reaction[] CurrentReactions {
208  get {
209  lock (this._send_lock) {
210  return this._Current_Reactions;
211  }
212  }
213  set {
214  lock (this._send_lock) {
215  this._Current_Reactions = value;
216  }
217  }
218  }
219 
222  public float SimulationTimeScale {
223  get { return Time.timeScale; }
224  set {
225  #if UNITY_EDITOR
226  Time.timeScale = Math.Min(value, 99);
227  this._last_simulation_time = Math.Min(value, 99);
228  #else
229  Time.timeScale = value;
230  this._last_simulation_time = value;
231  #endif
232 
233  if (this.Configuration.UpdateFixedTimeScale) {
234  Time.fixedDeltaTime = 0.02F * Time.timeScale;
235  }
236  }
237  }
238 
239  [SerializeField] float _last_simulation_time;
240 
243  public bool HasStepped { get { return this._has_stepped; } set { this._has_stepped = value; } }
244 
247  public bool TestActuators {
248  get { return this._testing_Actuators; }
249  set { this._testing_Actuators = value; }
250  }
251 
254  public bool Debugging {
255  get { return this._debugging; }
256  set {
257  if (this._Message_Server != null) {
258  this._Message_Server.Debugging = value;
259  }
260 
261  this._debugging = value;
262  }
263  }
264 
267  public bool AwaitingReply {
268  get {
269  lock (this._send_lock) {
270  return this._awaiting_reply;
271  }
272  }
273  set {
274  lock (this._send_lock) {
275  this._awaiting_reply = value;
276  }
277  }
278  }
279 
280  public ISimulatorConfiguration SimulatorConfiguration { get { return this._configuration; } }
281 
284  public bool IsSyncingEnvironments {
285  get { return this._syncing_environments; }
286  set { this._syncing_environments = value; }
287  }
288 
291  public bool Stepping { get { return this._step; } }
292 
293  #endregion
294 
295  #region PrivateMembers
296 
299  protected Dictionary<string, IEnvironment> _Environments = new Dictionary<string, IEnvironment>();
300 
303  public void Clear() { this._Environments.Clear(); }
304 
308 
311  protected Reaction[] _Current_Reactions = { };
312 
313  [SerializeField] bool _has_stepped;
314 
315  #endregion
316 
317  #region UnityCallbacks
318 
321  protected void Awake() {
322  if (Instance == null) {
323  Instance = this;
324  } else if (Instance == this) {
325  #if NEODROID_DEBUG
326  if (this.Debugging) {
327  Debug.Log("Using " + Instance);
328  }
329  #endif
330  } else {
331  Debug.LogWarning("WARNING! There are multiple SimulationManagers in the scene! Only using "
332  + Instance);
333  }
334 
335  #if UNITY_EDITOR
336  if (!Application.isPlaying) {
337  var manager_script = MonoScript.FromMonoBehaviour(this);
338  if (MonoImporter.GetExecutionOrder(manager_script) != _script_execution_order) {
339  MonoImporter.SetExecutionOrder(manager_script,
340  _script_execution_order); // Ensures that PreStep is called first, before all other scripts.
341  Debug.LogWarning("Execution Order changed, you will need to press play again to make everything function correctly!");
342  EditorApplication.isPlaying = false;
343  //TODO: UnityEngine.Experimental.LowLevel.PlayerLoop.SetPlayerLoop(new UnityEngine.Experimental.LowLevel.PlayerLoopSystem());
344  }
345  }
346  #endif
347  }
348 
351  protected void Start() {
352  this.FetchCommandLineArguments();
353 
354  if (this.Configuration == null) {
355  this.Configuration = ScriptableObject.CreateInstance<SimulatorConfiguration>();
356  }
357 
358  this.ApplyConfigurationToUnity(this.Configuration);
359 
360  if (this.Configuration.SimulationType == SimulationType.Physics_dependent_) {
361  this.EarlyFixedUpdateEvent += this.OnPreTick;
362  this.FixedUpdateEvent += this.OnTick;
363  this.FixedUpdateEvent += this.Tick;
364  this.LateFixedUpdateEvent += this.OnPostTick;
365  this.StartCoroutine(this.LateFixedUpdateEventGenerator());
366  } else {
367  this.EarlyUpdateEvent += this.OnPreTick;
368  this.UpdateEvent += this.OnTick;
369  this.UpdateEvent += this.Tick;
370  switch (this.Configuration.FrameFinishes) {
371  case FrameFinishes.Late_update_:
372  this.LateUpdateEvent += this.OnPostTick;
373  break;
374  case FrameFinishes.On_post_render_:
375  this.OnPostRenderEvent += this.OnPostTick;
376  break;
377  case FrameFinishes.On_render_image_:
378  this.OnRenderImageEvent += this.OnPostTick;
379  break;
380  case FrameFinishes.End_of_frame_:
381  this.StartCoroutine(this.EndOfFrameEventGenerator());
382  this.OnEndOfFrameEvent += this.OnPostTick;
383  break;
384  default: throw new ArgumentOutOfRangeException();
385  }
386  }
387 
388  this.CreateMessagingServer();
389  if (this.Configuration.SimulationType == SimulationType.Physics_dependent_) {
390  this.StartMessagingServer(); // Remember to manually bind receive to an event in a derivation
391  } else {
392  this.StartMessagingServer(true);
393  }
394  }
395 
399  if (configuration.ApplyQualitySettings) {
400  QualitySettings.SetQualityLevel(configuration.QualityLevel, true);
401  QualitySettings.vSyncCount = configuration.vSyncCount;
402  }
403 
404  this.SimulationTimeScale = configuration.TimeScale;
405  Application.targetFrameRate = configuration.TargetFrameRate;
406 
407  if (this._configuration.OptimiseWindowForSpeed) {
408  Screen.SetResolution(1, 1, false);
409  }
410  #if !UNITY_EDITOR
411  else if( configuration.ApplyResolutionSettings ){
412  Screen.SetResolution(
413  width : configuration.Width,
414  height : configuration.Height,
415  fullscreen : configuration.FullScreen);
416  }
417  #else
418 
419  PlayerSettings.resizableWindow = configuration.ResizableWindow;
420  PlayerSettings.colorSpace = configuration.ColorSpace;
421  PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
422  //PlayerSettings.use32BitDisplayBuffer
423  #endif
424  }
425 
428  void OnPostRender() { this.OnPostRenderEvent?.Invoke(); }
429 
434  void OnRenderImage(RenderTexture src, RenderTexture dest) {
435  this.OnRenderImageEvent?.Invoke(); //TODO: May not work
436  }
437 
440  protected void FixedUpdate() {
441  this.EarlyFixedUpdateEvent?.Invoke();
442  this.FixedUpdateEvent?.Invoke();
443  }
444 
448  IEnumerator LateFixedUpdateEventGenerator() {
449  while (true) {
450  yield return this._wait_for_fixed_update;
451  #if NEODROID_DEBUG
452  if (this.Debugging) {
453  Debug.Log("LateFixedUpdate");
454  }
455  #endif
456  this.LateFixedUpdateEvent?.Invoke();
457  }
458 
459  // ReSharper disable once IteratorNeverReturns
460  }
461 
465  protected IEnumerator EndOfFrameEventGenerator() {
466  while (true) {
467  yield return this._wait_for_end_of_frame;
468  //yield return new WaitForEndOfFrame();
469  #if NEODROID_DEBUG
470  if (this.Debugging) {
471  Debug.Log("EndOfFrameEvent");
472  }
473  #endif
474  this.OnEndOfFrameEvent?.Invoke();
475  }
476  #pragma warning disable 162
477  // ReSharper disable once HeuristicUnreachableCode
478  yield return null;
479  #pragma warning restore 162
480  // ReSharper disable once IteratorNeverReturns
481  }
482 
485  protected void Update() {
486  this.EarlyUpdateEvent?.Invoke();
487  this.UpdateEvent?.Invoke();
488  }
489 
492  protected void LateUpdate() { this.LateUpdateEvent?.Invoke(); }
493 
494  #endregion
495 
496  #region PrivateMethods
497 
500  protected void OnPreTick() {
501  #if NEODROID_DEBUG
502  if (this.Debugging) {
503  Debug.Log("OnPreTick");
504  }
505  #endif
506 
507  if (this.Configuration.StepExecutionPhase == ExecutionPhase.Before_) {
508  this.ExecuteStep();
509  }
510  }
511 
514  protected void OnTick() {
515  #if NEODROID_DEBUG
516  if (this.Debugging) {
517  Debug.Log("OnTick");
518  }
519  #endif
520  if (this.Configuration.StepExecutionPhase == ExecutionPhase.Middle_) {
521  this.ExecuteStep();
522  }
523  }
524 
527  protected void OnPostTick() {
528  #if NEODROID_DEBUG
529  if (this.Debugging) {
530  Debug.Log("OnPostTick");
531  }
532  #endif
533 
534  foreach (var environment in this._Environments.Values) {
535  environment.PostStep();
536  }
537 
538  if (this.Configuration.StepExecutionPhase == ExecutionPhase.After_) {
539  this.ExecuteStep();
540  }
541 
542  if (this._has_stepped) {
543  this.ClearCurrentReactions();
544  }
545  }
546 
549  void ExecuteStep() {
550  if (!this._syncing_environments) {
551  this.React(this.CurrentReactions);
552  }
553 
554  if (this.AwaitingReply) {
555  var states = this.CollectStates();
556  this.PostReact(states);
557  }
558 
559  this.HasStepped = true;
560  }
561 
564  protected void Tick() {
565  if (this.TestActuators) {
566  this.React(this.SampleRandomReactions());
567  this.CollectStates();
568  }
569 
570  foreach (var environment in this._Environments.Values) {
571  environment.Tick();
572  }
573 
574  #if NEODROID_DEBUG
575  if (this.Debugging) {
576  Debug.Log("Tick");
577  }
578  #endif
579  }
580 
584  protected void PostReact(EnvironmentState[] states) {
585  lock (this._send_lock) {
586  foreach (var env in this._Environments.Values) {
587  if (env.IsResetting) {
588  #if NEODROID_DEBUG
589  if (this.Debugging) {
590  Debug.Log($"Environment {env} is resetting");
591  }
592  #endif
593 
594  this._syncing_environments = true;
595  return;
596  }
597  }
598 
599  this._syncing_environments = false;
600  if (this._skip_frame_i >= this.Configuration.FrameSkips) {
601  #if NEODROID_DEBUG
602  if (this.Debugging) {
603  Debug.Log("Not skipping frame, replying...");
604  }
605  #endif
606 
607  this.Reply(states);
608  this.AwaitingReply = false;
609  this._skip_frame_i = 0;
610  } else {
611  this._skip_frame_i += 1;
612  #if NEODROID_DEBUG
613  if (this.Debugging) {
614  Debug.Log($"Skipping frame, {this._skip_frame_i}/{this.Configuration.FrameSkips}");
615  }
616  #endif
617  if (this.Configuration.ReplayReactionInSkips) { }
618  }
619  }
620  }
621 
626  this._sample_reactions.Clear();
627  foreach (var environment in this._Environments.Values) {
628  this._sample_reactions.Add(environment.SampleReaction());
629  }
630 
631  return this._sample_reactions.ToArray();
632  }
633 
634  //TODO: Maybe add EnvironmentState[][] states for aggregation of states in unity side buffer, when using skips?
638  void Reply(EnvironmentState[] states) {
639  lock (this._send_lock) {
640  var configuration_message = new SimulatorConfigurationMessage(this.Configuration);
641  var describe = false;
642  if (this.CurrentReactions != null) {
643  foreach (var reaction in this.CurrentReactions) {
644  if (reaction.Parameters.Describe) {
645  describe = true;
646  }
647  }
648  }
649 
650  this._Message_Server.SendStates(states,
651  simulator_configuration_message : configuration_message,
652  do_serialise_unobservables :
653  describe || this.Configuration.AlwaysSerialiseUnobservables,
654  serialise_individual_observables :
655  describe || this.Configuration.AlwaysSerialiseIndividualObservables,
656  serialise_aggregated_float_array : describe
657  || this._configuration
658  .AlwaysSerialiseAggregatedFloatArray);
659  #if NEODROID_DEBUG
660  if (this.Debugging) {
661  Debug.Log("Replying");
662  }
663 
664  #endif
665  }
666  }
667 
670  void ClearCurrentReactions() {
671  this._step = false;
672  this.CurrentReactions = new Reaction[] { };
673  }
674 
675  #endregion
676 
677  #region PublicMethods
678 
684  this.SetStepping(reaction);
685  var states = new EnvironmentState[this._Environments.Values.Count];
686  var i = 0;
687  foreach (var environment in this._Environments.Values) {
688  if (reaction.RecipientEnvironment != "all") {
689  #if NEODROID_DEBUG
690  if (this.Debugging) {
691  Debug.Log($"Applying reaction to {reaction.RecipientEnvironment} environment");
692  }
693  #endif
694  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
695  states[i++] = this._Environments[reaction.RecipientEnvironment].ReactAndCollectState(reaction);
696  }
697  #if NEODROID_DEBUG
698  else {
699  if (this.Debugging) {
700  Debug.Log($"Could not find environment: {reaction.RecipientEnvironment}");
701  }
702  }
703  #endif
704  } else {
705  #if NEODROID_DEBUG
706  if (this.Debugging) {
707  Debug.Log("Applying reaction to all environments");
708  }
709  #endif
710  states[i++] = environment.ReactAndCollectState(reaction);
711  }
712  }
713 
714  return states;
715  }
716 
721  public void React(Reaction reaction) {
722  this.SetStepping(reaction);
723  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
724  this._Environments[reaction.RecipientEnvironment].React(reaction);
725  } else {
726  #if NEODROID_DEBUG
727  if (this.Debugging) {
728  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
729  }
730  #endif
731 
732  #if NEODROID_DEBUG
733  if (this.Debugging) {
734  Debug.Log("Applying to all environments");
735  }
736  #endif
737 
738  foreach (var environment in this._Environments.Values) {
739  environment.React(reaction);
740  }
741  }
742  }
743 
748  public void React(Reaction[] reactions) {
749  this.SetStepping(reactions);
750  foreach (var reaction in reactions) {
751  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
752  this._Environments[reaction.RecipientEnvironment].React(reaction);
753  } else if (reaction.RecipientEnvironment == "all") {
754  #if NEODROID_DEBUG
755  if (this.Debugging) {
756  Debug.Log("Applying to all environments");
757  }
758  #endif
759 
760  foreach (var environment in this._Environments.Values) {
761  environment.React(reaction);
762  }
763  } else {
764  #if NEODROID_DEBUG
765  if (this.Debugging) {
766  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
767  }
768  #endif
769  }
770  }
771  }
772 
777  var environments = this._Environments.Values;
778  var states = new EnvironmentState[environments.Count];
779  var i = 0;
780  foreach (var environment in environments) {
781  states[i++] = environment.CollectState();
782  }
783 
784  return states;
785  }
786 
787  void SetStepping(Reaction reaction) {
788  if (reaction.Parameters.Step) {
789  this.SetStepping(true);
790  }
791  }
792 
793  void SetStepping(bool step) {
794  if (step) {
795  #if NEODROID_DEBUG
796  if (this.Debugging) {
797  Debug.Log("Stepping from Reaction");
798  }
799  #endif
800 
801  this._step = true;
802  } else {
803  #if NEODROID_DEBUG
804  if (this.Debugging) {
805  Debug.Log("Not stepping from Reaction");
806  }
807  #endif
808  if (this.HasStepped) {
809  this._step = false;
810  }
811  }
812  }
813 
814  void SetStepping(Reaction[] reactions) {
815  if (reactions.Any(reaction => reaction.Parameters.Step)) {
816  this.SetStepping(true);
817  }
818  }
819 
820  public void SetTesting(bool arg0) { this.TestActuators = arg0; }
821 
822 /*
828  public EnvironmentState[] ReactAndCollectStates(Reaction[] reactions) {
829  this.SetStepping(reactions);
830  var states = new EnvironmentState[reactions.Length * this._Environments.Count];
831  var i = 0;
832  foreach (var reaction in reactions) {
833  if (this._Environments.ContainsKey(reaction.RecipientEnvironment)) {
834  states[i++] = this._Environments[reaction.RecipientEnvironment].ReactAndCollectState(reaction);
835  } else {
836  #if NEODROID_DEBUG
837  if (this.Debugging) {
838  Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
839  }
840  #endif
841 
842  #if NEODROID_DEBUG
843  if (this.Debugging) {
844  Debug.Log($"Applying to all environments");
845  }
846  #endif
847 
848  foreach (var environment in this._Environments.Values) {
849  states[i++] = environment.ReactAndCollectState(reaction);
850  }
851  }
852  }
853 
854  return states;
855  }
856 */
857 
860  public void ResetAllEnvironments() {
861  this.React(new Reaction(new ReactionParameters(true, false, true, episode_count : true),
862  null,
863  null,
864  null,
865  null,
866  ""));
867  }
868 
872  public string GetStatus() {
873  if (this._Message_Server != null) {
874  return this._Message_Server._Listening_For_Clients ? "Connected" : "Not Connected";
875  }
876 
877  return "No server";
878  }
879 
880  #endregion
881 
882  #region Registration
883 
888  public void Register(IEnvironment environment) { this.Register(environment, environment.Identifier); }
889 
895  public void Register(IEnvironment environment, string identifier) {
896  if (!this._Environments.ContainsKey(identifier)) {
897  #if NEODROID_DEBUG
898  if (this.Debugging) {
899  Debug.Log($"Manager {this.name} already has an environment with the identifier: {identifier}");
900  }
901  #endif
902 
903  this._Environments.Add(identifier, environment);
904  } else {
905  Debug.LogWarning($"WARNING! Please check for duplicates, SimulationManager {this.name} already has envi"
906  + $"ronment {identifier} registered");
907  }
908  }
909 
914  public void UnRegister(IEnvironment environment, string identifier) {
915  if (this._Environments.ContainsKey(identifier)) {
916  #if NEODROID_DEBUG
917  if (this.Debugging) {
918  Debug.Log($"SimulationManager {this.name} unregistered Environment {identifier}");
919  }
920  #endif
921 
922  this._Environments.Remove(identifier);
923  }
924  }
925 
929  public void UnRegister(IEnvironment neodroid_environment) {
930  this.UnRegister(neodroid_environment, neodroid_environment.Identifier);
931  }
932 
933  #endregion
934 
935  #region MessageServerCallbacks
936 
940  void OnReceiveCallback(Reaction[] reactions) {
941  lock (this._send_lock) {
942  #if NEODROID_DEBUG
943  if (this.Debugging) {
944  Debug.Log($"Received: {reactions.Select(r => r.ToString()).Aggregate((current, next) => $"{current}, {next}")}");
945  }
946  #endif
947 
948  this.SetReactionsFromExternalSource(reactions);
949 
950  this.OnReceiveEvent?.Invoke();
951  }
952  }
953 
957  protected void SetReactionsFromExternalSource(Reaction[] reactions) {
958  lock (this._send_lock) {
959  if (reactions != null) {
960  if (this.AwaitingReply || !this.HasStepped) {
961  #if NEODROID_DEBUG
962  if (this.Debugging) {
963  Debug.Log($"Got new reaction while not having stepped({!this.HasStepped}) or replied({this.AwaitingReply})");
964  }
965  #endif
966  }
967 
968  this.CurrentReactions = reactions;
969  foreach (var current_reaction in this.CurrentReactions) {
970  current_reaction.Parameters.IsExternal = true;
971  }
972 
973  this.Configuration.StepExecutionPhase = this.CurrentReactions[0].Parameters.Phase;
974  this.AwaitingReply = true;
975  this.HasStepped = false;
976  } else {
977  Debug.LogWarning("Reaction was null");
978  }
979  }
980  }
981 
984  void OnDisconnectCallback() {
985  #if NEODROID_DEBUG
986  if (this.Debugging) {
987  Debug.Log("Client disconnected.");
988  }
989  #endif
990  }
991 
995  void OnDebugCallback(string error) {
996  #if NEODROID_DEBUG
997  if (this.Debugging) {
998  Debug.Log("DebugCallback: " + error);
999  }
1000  #endif
1001  }
1002 
1005  void OnListeningCallback() {
1006  #if NEODROID_DEBUG
1007  if (this.Debugging) {
1008  Debug.Log("Client connected");
1009  }
1010  #endif
1011 
1012  this._Message_Server.StartReceiving(this.OnReceiveCallback,
1013  this.OnDisconnectCallback,
1014  this.OnDebugCallback);
1015  }
1016 
1017  #endregion
1018 
1019  #region Deconstruction
1020 
1023  void OnApplicationQuit() { this._Message_Server.CleanUp(); }
1024 
1027  void OnDestroy() { this._Message_Server.Destroy(); }
1028 
1029  #endregion
1030  }
1031 }
System.Object Object
void UnRegister(IEnvironment neodroid_environment)
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)
EnvironmentState [] ReactAndCollectStates(Reaction reaction)
void StatusString(DataPoller recipient)
void Register(IEnvironment environment, string identifier)
void UnRegister(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)
void ApplyConfigurationToUnity(ISimulatorConfiguration configuration)
FrameFinishes
Determines where in the monobehaviour cycle a frame/step is finished
Definition: FrameFinishes.cs:5
void Register(IEnvironment environment)
void SetReactionsFromExternalSource(Reaction[] reactions)
void React(Reaction[] reactions)
void PostReact(EnvironmentState[] states)
Configuration(string configurable_name, float configurable_value, bool sample_random=false)
Definition: Configuration.cs:8
Action EarlyUpdateEvent
Can be subscribed to for pre update events (Will be called before any Update on any script) ...
SimulationType
Determines the discrete timesteps of the simulation environment.
Action EarlyFixedUpdateEvent
Can be subscribed to for pre fixed update events (Will be called before any FixedUpdate on any script...