This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved websocket data streaming to game thread, in order to avoid pote…
…ntially crashing KSP on exit
- Loading branch information
1 parent
757c9ec
commit 968ca67
Showing
6 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Timers; | ||
using UnityEngine; | ||
|
||
namespace Telemachus | ||
{ | ||
public class IterationToEvent<E> where E : EventArgs | ||
{ | ||
public event EventHandler<E> Iterated; | ||
|
||
public void update(E eventArgs) | ||
{ | ||
if (Iterated != null) | ||
{ | ||
Iterated(this, eventArgs); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Timers; | ||
using UnityEngine; | ||
|
||
namespace Telemachus | ||
{ | ||
public class UpdateTimer | ||
{ | ||
public event EventHandler<UpdateTimerEventArgs> Elapsed; | ||
private float lastEventTime = 0.0f; | ||
|
||
private float interval = 0.0f; | ||
public float Interval | ||
{ | ||
get { return interval; } | ||
set { interval = value; } | ||
} | ||
|
||
private bool enabled = false; | ||
public bool Enabled | ||
{ | ||
get { return enabled; } | ||
set { enabled = value; } | ||
} | ||
|
||
public void update(object sender, UpdateTimerEventArgs timeElapsedEventArgs) | ||
{ | ||
if ((timeElapsedEventArgs.Time - lastEventTime > interval) && Enabled) | ||
{ | ||
if (Elapsed != null) | ||
{ | ||
Elapsed(this, timeElapsedEventArgs); | ||
} | ||
|
||
lastEventTime = timeElapsedEventArgs.Time; | ||
} | ||
} | ||
} | ||
|
||
public class UpdateTimerEventArgs : EventArgs | ||
{ | ||
private float time = 0.0f; | ||
|
||
public float Time | ||
{ | ||
get { return time; } | ||
} | ||
|
||
public UpdateTimerEventArgs(float time) | ||
{ | ||
this.time = time; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters