@jack120/test 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1140 -0
- package/dist/index.js +1 -2415
- package/package.json +7 -2
- package/{library/adamas-types.d.ts → types/index.d.ts} +2 -5
- package/.gitmodules +0 -3
- package/.prettierrc +0 -6
- package/.vscode/c_cpp_properties.json +0 -14
- package/.vscode/launch.json +0 -24
- package/.vscode/settings.json +0 -8
- package/CMakeLists.txt +0 -52
- package/adamas-config.json +0 -5
- package/external/CMakeLists.txt +0 -1
- package/external/Unity-NodeJS-RPC/CMakeLists.txt +0 -13
- package/external/Unity-NodeJS-RPC/README.md +0 -1
- package/external/Unity-NodeJS-RPC/RpcClient.cpp +0 -265
- package/external/Unity-NodeJS-RPC/include/RpcClient.h +0 -118
- package/external/Unity-NodeJS-RPC/main.cpp +0 -76
- package/external/Unity-NodeJS-RPC/nlohmann/json.hpp +0 -25526
- package/external/Unity-NodeJS-RPC/server/Program.cs +0 -52
- package/external/Unity-NodeJS-RPC/server/json.cs +0 -66
- package/external/Unity-NodeJS-RPC/server/rpc.cs +0 -369
- package/external/Unity-NodeJS-RPC/server/sample1.csproj +0 -10
- package/external/Unity-NodeJS-RPC/server/sample1.sln +0 -24
- package/external/Unity-NodeJS-RPC/server/unity/RpcUnity.cs.txt +0 -60
- package/index.ts +0 -36
- package/library/debug.ts +0 -7
- package/library/device.ts +0 -279
- package/library/entity.ts +0 -35
- package/library/index.ts +0 -19
- package/library/interaction/interaction.ts +0 -281
- package/library/native-bindings-osx.node +0 -0
- package/library/native-bindings-win.node +0 -0
- package/library/networking/state-sync.ts +0 -62
- package/library/physics/collider.ts +0 -252
- package/library/physics/rigidbody.ts +0 -119
- package/library/render/camera.ts +0 -172
- package/library/render/light.ts +0 -169
- package/library/render/material.ts +0 -258
- package/library/render/mesh.ts +0 -208
- package/library/render/primitives.ts +0 -76
- package/library/render/renderable.ts +0 -137
- package/library/render/renderer.ts +0 -124
- package/library/render/scene.ts +0 -89
- package/library/render/texture.ts +0 -247
- package/library/render/transform.ts +0 -259
- package/library/rpc.ts +0 -81
- package/library/utilities/base64.ts +0 -63
- package/loader-template.ts +0 -419
- package/native.cc +0 -111
- package/project.adamas.json +0 -457
- package/rusk.glb +0 -0
- package/samples/device-sample.ts +0 -30
- package/samples/interaction-sample.ts +0 -134
- package/samples/physics-sample.ts +0 -39
- package/samples/rendering-sample.ts +0 -88
- package/samples/spawn-cube.ts +0 -422
- package/samples/state-sync-sample.ts +0 -25
- package/tsconfig.json +0 -20
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
using SharedMemRPC;
|
|
2
|
-
using System.Threading;
|
|
3
|
-
|
|
4
|
-
class Program
|
|
5
|
-
{
|
|
6
|
-
static float mul(float a, float b)
|
|
7
|
-
{
|
|
8
|
-
return a * b;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static void Main()
|
|
12
|
-
{
|
|
13
|
-
RpcServer server = new RpcServer();
|
|
14
|
-
|
|
15
|
-
server.Register("add", (float a, float b) => a + b);
|
|
16
|
-
server.Register("sub", (double a, double b) => a - b);
|
|
17
|
-
server.Register("mul", mul);
|
|
18
|
-
server.Register("echo", (string text) => "Server echo: " + text);
|
|
19
|
-
|
|
20
|
-
server.Register("do_work", (string input, int delay, int onComplete) =>
|
|
21
|
-
{
|
|
22
|
-
Console.WriteLine("input: " + input);
|
|
23
|
-
Console.WriteLine("Delay: " + delay);
|
|
24
|
-
Console.WriteLine("onComoplate: " + onComplete);
|
|
25
|
-
server.TriggerCallback(onComplete, new { a = 1, b = "str", c = 3.33 });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
server.Register("timer", (int interval, int callback, int text) =>
|
|
29
|
-
{
|
|
30
|
-
return server.handleRegistry.AddHandle(new Timer(
|
|
31
|
-
callback: state => server.TriggerCallback(callback, new { text }),
|
|
32
|
-
state: null,
|
|
33
|
-
dueTime: 0,
|
|
34
|
-
period: interval
|
|
35
|
-
));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
server.Register("dispose_timer", (int timerHandle) =>
|
|
39
|
-
{
|
|
40
|
-
Console.WriteLine("Handle disposed: " + timerHandle);
|
|
41
|
-
if (server.handleRegistry.GetObject(timerHandle, out Timer timer))
|
|
42
|
-
{
|
|
43
|
-
timer.Dispose();
|
|
44
|
-
server.handleRegistry.RemoveHandle(timerHandle);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
while (true) ;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#if UNITY_2017_1_OR_NEWER
|
|
2
|
-
using UnityEngine; // Use Unity's JSON system
|
|
3
|
-
#else
|
|
4
|
-
using System.Text.Json;
|
|
5
|
-
#endif
|
|
6
|
-
|
|
7
|
-
using System;
|
|
8
|
-
using System.Threading;
|
|
9
|
-
using System.Collections.Generic;
|
|
10
|
-
using System.IO.MemoryMappedFiles;
|
|
11
|
-
using System.Runtime.InteropServices;
|
|
12
|
-
|
|
13
|
-
namespace Serialization
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
[Serializable]
|
|
17
|
-
public class RpcArgsWrapper
|
|
18
|
-
{
|
|
19
|
-
public string[] keys;
|
|
20
|
-
public string[] values;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
[Serializable]
|
|
24
|
-
public class ResultWrapper
|
|
25
|
-
{
|
|
26
|
-
public string result;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public class JsonHelper
|
|
30
|
-
{
|
|
31
|
-
static public string ToJson(string result)
|
|
32
|
-
{
|
|
33
|
-
#if UNITY_2017_1_OR_NEWER
|
|
34
|
-
return JsonUtility.ToJson(new ResultWrapper { result = result.ToString() });
|
|
35
|
-
#else
|
|
36
|
-
return JsonSerializer.Serialize(
|
|
37
|
-
new ResultWrapper { result = result.ToString() },
|
|
38
|
-
new JsonSerializerOptions { IncludeFields = true }
|
|
39
|
-
);
|
|
40
|
-
#endif
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static public string ToJson(RpcArgsWrapper rpcArgs)
|
|
44
|
-
{
|
|
45
|
-
#if UNITY_2017_1_OR_NEWER
|
|
46
|
-
return JsonUtility.ToJson(rpcArgs);
|
|
47
|
-
#else
|
|
48
|
-
return JsonSerializer.Serialize(rpcArgs,
|
|
49
|
-
new JsonSerializerOptions { IncludeFields = true }
|
|
50
|
-
);
|
|
51
|
-
#endif
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static public RpcArgsWrapper? FromJson(string jsonString)
|
|
55
|
-
{
|
|
56
|
-
#if UNITY_2017_1_OR_NEWER
|
|
57
|
-
return JsonUtility.FromJson<RpcArgsWrapper>(jsonString);
|
|
58
|
-
#else
|
|
59
|
-
return JsonSerializer.Deserialize<RpcArgsWrapper>(
|
|
60
|
-
jsonString,
|
|
61
|
-
new JsonSerializerOptions { IncludeFields = true }
|
|
62
|
-
);
|
|
63
|
-
#endif
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Threading;
|
|
3
|
-
using System.Collections.Generic;
|
|
4
|
-
using System.Runtime.InteropServices;
|
|
5
|
-
using Serialization;
|
|
6
|
-
using System.Net.Sockets;
|
|
7
|
-
using System.Net;
|
|
8
|
-
using System.Text;
|
|
9
|
-
using System.IO;
|
|
10
|
-
using System.Collections.Concurrent;
|
|
11
|
-
using System.Threading.Tasks;
|
|
12
|
-
|
|
13
|
-
#if UNITY_2017_1_OR_NEWER
|
|
14
|
-
using UnityEngine;
|
|
15
|
-
#endif
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
namespace SharedMemRPC
|
|
19
|
-
{
|
|
20
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
|
21
|
-
public struct RpcRequest
|
|
22
|
-
{
|
|
23
|
-
public int request_id;
|
|
24
|
-
|
|
25
|
-
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
26
|
-
public string functionName;
|
|
27
|
-
|
|
28
|
-
public int bufferSize;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
|
32
|
-
public struct ResponseHeader
|
|
33
|
-
{
|
|
34
|
-
// enum class MsgType {
|
|
35
|
-
// CALLBACK = 0,
|
|
36
|
-
// RETURN = 1
|
|
37
|
-
// };
|
|
38
|
-
public int clientId;
|
|
39
|
-
public int msgType;
|
|
40
|
-
public int statusCodeOrCallbackId;
|
|
41
|
-
public int bufferSize;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public class HandleRegistry
|
|
45
|
-
{
|
|
46
|
-
private readonly Dictionary<int, object> handles = new();
|
|
47
|
-
private int nextHandleId = 1;
|
|
48
|
-
|
|
49
|
-
public int AddHandle(object obj)
|
|
50
|
-
{
|
|
51
|
-
int handleId = nextHandleId++;
|
|
52
|
-
handles[handleId] = obj;
|
|
53
|
-
return handleId;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public bool GetObject<T>(int handleID, out T obj)
|
|
57
|
-
{
|
|
58
|
-
bool found = handles.TryGetValue(handleID, out object? value);
|
|
59
|
-
obj = (T) value;
|
|
60
|
-
return found;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public bool RemoveHandle(int handle)
|
|
64
|
-
{
|
|
65
|
-
return handles.Remove(handle);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public class RpcServer
|
|
70
|
-
{
|
|
71
|
-
private readonly Dictionary<string, Func<Dictionary<string, string>, object>> functions = new();
|
|
72
|
-
private readonly Dictionary<int, TcpClient> clients = new();
|
|
73
|
-
private readonly Dictionary<int, int> callbackToClientId = new();
|
|
74
|
-
private readonly List<Thread> threads = new();
|
|
75
|
-
private readonly ConcurrentQueue<Action> mainThreadQueue = new();
|
|
76
|
-
|
|
77
|
-
private int nextCallbackId = 0;
|
|
78
|
-
private readonly Mutex respMutex = new();
|
|
79
|
-
private readonly Mutex queueMutex = new();
|
|
80
|
-
|
|
81
|
-
private readonly TcpListener listener;
|
|
82
|
-
|
|
83
|
-
public HandleRegistry handleRegistry;
|
|
84
|
-
|
|
85
|
-
public RpcServer(int port = 6969)
|
|
86
|
-
{
|
|
87
|
-
handleRegistry = new HandleRegistry();
|
|
88
|
-
Register<Func<int, int>>("_RPC::AllocateCallback", (int clientId) =>
|
|
89
|
-
{
|
|
90
|
-
callbackToClientId[nextCallbackId] = clientId;
|
|
91
|
-
return nextCallbackId++;
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
listener = new TcpListener(IPAddress.Any, port);
|
|
95
|
-
listener.Start();
|
|
96
|
-
listener.BeginAcceptTcpClient(OnClientConnected, null);
|
|
97
|
-
DebugPrint("Server started...");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public void Register<TDelegate>(string name, TDelegate del) where TDelegate : Delegate
|
|
101
|
-
{
|
|
102
|
-
var method = del.Method;
|
|
103
|
-
var target = del.Target;
|
|
104
|
-
|
|
105
|
-
functions[name] = (argDict) =>
|
|
106
|
-
{
|
|
107
|
-
var parameters = method.GetParameters();
|
|
108
|
-
var args = new object[parameters.Length];
|
|
109
|
-
|
|
110
|
-
for (int i = 0; i < parameters.Length; i++)
|
|
111
|
-
{
|
|
112
|
-
var param = parameters[i];
|
|
113
|
-
if (!argDict.TryGetValue(param.Name, out var strValue))
|
|
114
|
-
throw new ArgumentException($"Missing argument: {param.Name}");
|
|
115
|
-
|
|
116
|
-
args[i] = Convert.ChangeType(strValue, param.ParameterType);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
object? result = method.Invoke(target, args);
|
|
120
|
-
return result?.ToString() ?? "";
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public void ProcessRPC()
|
|
125
|
-
{
|
|
126
|
-
queueMutex.WaitOne();
|
|
127
|
-
while (mainThreadQueue.TryDequeue(out Action action))
|
|
128
|
-
{
|
|
129
|
-
queueMutex.ReleaseMutex();
|
|
130
|
-
try
|
|
131
|
-
{
|
|
132
|
-
action();
|
|
133
|
-
}
|
|
134
|
-
catch (Exception ex)
|
|
135
|
-
{
|
|
136
|
-
DebugPrint($"[RPC Service {Environment.CurrentManagedThreadId}] Unexpected error: {ex}");
|
|
137
|
-
}
|
|
138
|
-
queueMutex.WaitOne();
|
|
139
|
-
}
|
|
140
|
-
queueMutex.ReleaseMutex();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private void OnClientConnected(IAsyncResult ar)
|
|
144
|
-
{
|
|
145
|
-
TcpClient client = listener.EndAcceptTcpClient(ar);
|
|
146
|
-
var thread = new Thread(() => HandleClient(client));
|
|
147
|
-
threads.Add(thread);
|
|
148
|
-
thread.Start();
|
|
149
|
-
|
|
150
|
-
// Continue accepting new clients
|
|
151
|
-
listener.BeginAcceptTcpClient(OnClientConnected, null);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private void OnClientDisconnected(int clientId)
|
|
155
|
-
{
|
|
156
|
-
DebugPrint($"[RPC Service {clientId}] Disconnected callback triggered.");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public void WaitAllClients()
|
|
160
|
-
{
|
|
161
|
-
foreach (Thread t in threads)
|
|
162
|
-
{
|
|
163
|
-
t.Join();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public void RunOnMainThread(Action action)
|
|
168
|
-
{
|
|
169
|
-
queueMutex.WaitOne();
|
|
170
|
-
mainThreadQueue.Enqueue(action);
|
|
171
|
-
queueMutex.ReleaseMutex();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private void HandleClient(TcpClient client)
|
|
175
|
-
{
|
|
176
|
-
try
|
|
177
|
-
{
|
|
178
|
-
respMutex.WaitOne();
|
|
179
|
-
clients[Environment.CurrentManagedThreadId] = client;
|
|
180
|
-
respMutex.ReleaseMutex();
|
|
181
|
-
client.NoDelay = true;
|
|
182
|
-
DebugPrint("Client connected.");
|
|
183
|
-
|
|
184
|
-
NetworkStream networkStream = client.GetStream();
|
|
185
|
-
WriteHeader(networkStream, new ResponseHeader
|
|
186
|
-
{
|
|
187
|
-
clientId = Environment.CurrentManagedThreadId,
|
|
188
|
-
msgType = 1,
|
|
189
|
-
statusCodeOrCallbackId = 0,
|
|
190
|
-
bufferSize = 0
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
while (true)
|
|
194
|
-
{
|
|
195
|
-
DebugPrint($"[RPC Service {Environment.CurrentManagedThreadId}] Waiting for request...");
|
|
196
|
-
var req = ReadHeader<RpcRequest>(networkStream);
|
|
197
|
-
string argsJson = ReadPayload(networkStream, req.bufferSize);
|
|
198
|
-
int clientId = Environment.CurrentManagedThreadId;
|
|
199
|
-
|
|
200
|
-
RunOnMainThread(() =>
|
|
201
|
-
{
|
|
202
|
-
string result = Dispatch(clientId, req.functionName, argsJson, out int status);
|
|
203
|
-
|
|
204
|
-
var resp = new ResponseHeader
|
|
205
|
-
{
|
|
206
|
-
clientId = clientId,
|
|
207
|
-
msgType = 1,
|
|
208
|
-
statusCodeOrCallbackId = status,
|
|
209
|
-
bufferSize = result.Length
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
respMutex.WaitOne();
|
|
213
|
-
if (clients.TryGetValue(clientId, out TcpClient tcpClient) && tcpClient.Connected)
|
|
214
|
-
{
|
|
215
|
-
WriteHeader(tcpClient.GetStream(), resp);
|
|
216
|
-
WritePayload(tcpClient.GetStream(), result);
|
|
217
|
-
}
|
|
218
|
-
respMutex.ReleaseMutex();
|
|
219
|
-
|
|
220
|
-
DebugPrint($"[RPC Service {clientId}] Handled: {req.functionName}, Response: {result}");
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (IOException)
|
|
225
|
-
{
|
|
226
|
-
respMutex.WaitOne();
|
|
227
|
-
clients.Remove(Environment.CurrentManagedThreadId);
|
|
228
|
-
client.Close();
|
|
229
|
-
respMutex.ReleaseMutex();
|
|
230
|
-
|
|
231
|
-
DebugPrint($"[RPC Service {Environment.CurrentManagedThreadId}] Client disconnected.");
|
|
232
|
-
OnClientDisconnected(Environment.CurrentManagedThreadId);
|
|
233
|
-
}
|
|
234
|
-
catch (Exception ex)
|
|
235
|
-
{
|
|
236
|
-
DebugPrint($"[RPC Service {Environment.CurrentManagedThreadId}] Unexpected error: {ex}");
|
|
237
|
-
}
|
|
238
|
-
// finally
|
|
239
|
-
// {
|
|
240
|
-
// respMutex.WaitOne();
|
|
241
|
-
// clients.Remove(Environment.CurrentManagedThreadId);
|
|
242
|
-
// client.Close();
|
|
243
|
-
// respMutex.ReleaseMutex();
|
|
244
|
-
// }
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
public void TriggerCallback(int callbackId, object namedArgs)
|
|
248
|
-
{
|
|
249
|
-
var props = namedArgs.GetType().GetProperties();
|
|
250
|
-
var keys = new List<string>();
|
|
251
|
-
var values = new List<string>();
|
|
252
|
-
|
|
253
|
-
foreach (var prop in props)
|
|
254
|
-
{
|
|
255
|
-
keys.Add(prop.Name);
|
|
256
|
-
object value = prop.GetValue(namedArgs);
|
|
257
|
-
values.Add(value?.ToString() ?? "");
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
var wrapper = new RpcArgsWrapper
|
|
261
|
-
{
|
|
262
|
-
keys = keys.ToArray(),
|
|
263
|
-
values = values.ToArray()
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
string json = JsonHelper.ToJson(wrapper);
|
|
267
|
-
|
|
268
|
-
var cb = new ResponseHeader
|
|
269
|
-
{
|
|
270
|
-
clientId = callbackToClientId[callbackId],
|
|
271
|
-
msgType = 0,
|
|
272
|
-
statusCodeOrCallbackId = callbackId,
|
|
273
|
-
bufferSize = json.Length
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
respMutex.WaitOne();
|
|
277
|
-
if (clients.TryGetValue(cb.clientId, out TcpClient tcpClient) && tcpClient.Connected)
|
|
278
|
-
{
|
|
279
|
-
WriteHeader(tcpClient.GetStream(), cb);
|
|
280
|
-
WritePayload(tcpClient.GetStream(), json);
|
|
281
|
-
}
|
|
282
|
-
respMutex.ReleaseMutex();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private string Dispatch(int clientId, string func, string argsJson, out int status)
|
|
286
|
-
{
|
|
287
|
-
try
|
|
288
|
-
{
|
|
289
|
-
Dictionary<string, string> args = ParseArgs(argsJson);
|
|
290
|
-
var result = functions[func](args);
|
|
291
|
-
status = 0;
|
|
292
|
-
return JsonHelper.ToJson(result?.ToString());
|
|
293
|
-
}
|
|
294
|
-
catch (Exception ex)
|
|
295
|
-
{
|
|
296
|
-
DebugPrint(
|
|
297
|
-
$"[RPC Service {clientId}] Dispatch exception: "+
|
|
298
|
-
ex.Message + "\n" + ex.StackTrace
|
|
299
|
-
);
|
|
300
|
-
status = 1;
|
|
301
|
-
return JsonHelper.ToJson(ex.Message);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
private Dictionary<string, string> ParseArgs(string json)
|
|
306
|
-
{
|
|
307
|
-
RpcArgsWrapper? parsed = JsonHelper.FromJson(json);
|
|
308
|
-
|
|
309
|
-
var dict = new Dictionary<string, string>();
|
|
310
|
-
for (int i = 0; i < parsed?.keys.Length; i++)
|
|
311
|
-
{
|
|
312
|
-
dict[parsed.keys[i]] = parsed.values[i];
|
|
313
|
-
}
|
|
314
|
-
return dict;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
private static T ReadHeader<T>(NetworkStream stream) where T : struct
|
|
318
|
-
{
|
|
319
|
-
int size = Marshal.SizeOf<T>();
|
|
320
|
-
byte[] buffer = new byte[size];
|
|
321
|
-
int read = stream.Read(buffer, 0, size);
|
|
322
|
-
if (read != size)
|
|
323
|
-
throw new IOException("Failed to read full header");
|
|
324
|
-
|
|
325
|
-
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
|
326
|
-
T header = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
|
327
|
-
handle.Free();
|
|
328
|
-
return header;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
private static string ReadPayload(NetworkStream stream, int size)
|
|
332
|
-
{
|
|
333
|
-
byte[] buffer = new byte[size];
|
|
334
|
-
int readTotal = 0;
|
|
335
|
-
while (readTotal < size)
|
|
336
|
-
{
|
|
337
|
-
int read = stream.Read(buffer, readTotal, size - readTotal);
|
|
338
|
-
if (read <= 0) throw new IOException("Failed to read full payload");
|
|
339
|
-
readTotal += read;
|
|
340
|
-
}
|
|
341
|
-
return Encoding.UTF8.GetString(buffer);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private static void WriteHeader<T>(NetworkStream stream, T header) where T : struct
|
|
345
|
-
{
|
|
346
|
-
int size = Marshal.SizeOf<T>();
|
|
347
|
-
byte[] buffer = new byte[size];
|
|
348
|
-
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
|
349
|
-
Marshal.StructureToPtr(header, handle.AddrOfPinnedObject(), false);
|
|
350
|
-
handle.Free();
|
|
351
|
-
stream.Write(buffer, 0, size);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
private static void WritePayload(NetworkStream stream, string data)
|
|
355
|
-
{
|
|
356
|
-
byte[] buffer = Encoding.UTF8.GetBytes(data);
|
|
357
|
-
stream.Write(buffer, 0, buffer.Length);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private static void DebugPrint(string message)
|
|
361
|
-
{
|
|
362
|
-
#if UNITY_2017_1_OR_NEWER
|
|
363
|
-
Debug.Log(message);
|
|
364
|
-
#else
|
|
365
|
-
Console.WriteLine(message);
|
|
366
|
-
#endif
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
2
|
-
# Visual Studio Version 17
|
|
3
|
-
VisualStudioVersion = 17.5.2.0
|
|
4
|
-
MinimumVisualStudioVersion = 10.0.40219.1
|
|
5
|
-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample1", "sample1.csproj", "{C99A5A7C-EA68-E506-DA55-1F7984401647}"
|
|
6
|
-
EndProject
|
|
7
|
-
Global
|
|
8
|
-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
9
|
-
Debug|Any CPU = Debug|Any CPU
|
|
10
|
-
Release|Any CPU = Release|Any CPU
|
|
11
|
-
EndGlobalSection
|
|
12
|
-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
13
|
-
{C99A5A7C-EA68-E506-DA55-1F7984401647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
14
|
-
{C99A5A7C-EA68-E506-DA55-1F7984401647}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
15
|
-
{C99A5A7C-EA68-E506-DA55-1F7984401647}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
16
|
-
{C99A5A7C-EA68-E506-DA55-1F7984401647}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
17
|
-
EndGlobalSection
|
|
18
|
-
GlobalSection(SolutionProperties) = preSolution
|
|
19
|
-
HideSolutionNode = FALSE
|
|
20
|
-
EndGlobalSection
|
|
21
|
-
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
22
|
-
SolutionGuid = {9010A7AB-FB94-4111-AC7B-7F2723CF0DFD}
|
|
23
|
-
EndGlobalSection
|
|
24
|
-
EndGlobal
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
using System.Collections;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using System.Threading;
|
|
4
|
-
using UnityEngine;
|
|
5
|
-
using SharedMemRPC;
|
|
6
|
-
using System;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
public class RpcUnity : MonoBehaviour
|
|
10
|
-
{
|
|
11
|
-
RpcServer server;
|
|
12
|
-
|
|
13
|
-
// Start is called before the first frame update
|
|
14
|
-
void Start()
|
|
15
|
-
{
|
|
16
|
-
server = new RpcServer();
|
|
17
|
-
|
|
18
|
-
server.Register<Func<float, float, float>>("add", (float a, float b) => a + b);
|
|
19
|
-
server.Register<Func<double, double, double>>("sub", (double a, double b) => a - b);
|
|
20
|
-
server.Register<Func<float, float, float>>("mul", (float a, float b) => a + b);
|
|
21
|
-
server.Register<Func<string, string>>("echo", (string text) => "Server echo: " + text);
|
|
22
|
-
|
|
23
|
-
server.Register<Func<string, int, int, int>>("do_work", (string input, int delay, int onComplete) =>
|
|
24
|
-
{
|
|
25
|
-
Console.WriteLine("input: " + input);
|
|
26
|
-
Console.WriteLine("Delay: " + delay);
|
|
27
|
-
Console.WriteLine("onComoplate: " + onComplete);
|
|
28
|
-
server.TriggerCallback(onComplete, new { a = 1, b = "str", c = 3.33 });
|
|
29
|
-
return 0;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
server.Register<Func<int, int, string, int>>("timer", (int interval, int callback, string text) =>
|
|
33
|
-
{
|
|
34
|
-
return server.handleRegistry.AddHandle(new Timer(
|
|
35
|
-
callback: state => server.TriggerCallback(callback, new { text }),
|
|
36
|
-
state: null,
|
|
37
|
-
dueTime: 0,
|
|
38
|
-
period: interval
|
|
39
|
-
));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
server.Register<Func<int, bool>>("dispose_timer", (int timerHandle) =>
|
|
43
|
-
{
|
|
44
|
-
Console.WriteLine("Handle disposed: " + timerHandle);
|
|
45
|
-
if (server.handleRegistry.GetObject(timerHandle, out Timer timer))
|
|
46
|
-
{
|
|
47
|
-
timer.Dispose();
|
|
48
|
-
server.handleRegistry.RemoveHandle(timerHandle);
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Update is called once per frame
|
|
56
|
-
void Update()
|
|
57
|
-
{
|
|
58
|
-
server.ProcessRPC();
|
|
59
|
-
}
|
|
60
|
-
}
|
package/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Entity } from "@adamas/entity";
|
|
2
|
-
|
|
3
|
-
import { GrabInteractableManager } from "@adamas/interaction/interaction";
|
|
4
|
-
import { ColliderManager, ColliderHandle } from "@adamas/physics/collider";
|
|
5
|
-
import { RigidbodyManager } from "@adamas/physics/rigidbody";
|
|
6
|
-
import { TransformManager } from "@adamas/render/transform";
|
|
7
|
-
import { vec3 } from "@adamas/gl-matrix";
|
|
8
|
-
import { cameraRenderTexture, renderGltf } from "samples/rendering-sample";
|
|
9
|
-
|
|
10
|
-
const heartModel = async () => {
|
|
11
|
-
const modelEntity: Entity = await renderGltf("realistic_human_heart.glb");
|
|
12
|
-
TransformManager.SetLocalPosition(modelEntity, vec3.fromValues(1, 1, 0));
|
|
13
|
-
TransformManager.SetLocalScale(modelEntity, vec3.fromValues(0.2, 0.2, 0.2));
|
|
14
|
-
RigidbodyManager.Create(modelEntity);
|
|
15
|
-
RigidbodyManager.SetIsKinematic(modelEntity, true);
|
|
16
|
-
RigidbodyManager.SetUseGravity(modelEntity, false);
|
|
17
|
-
const collider = ColliderManager.CreateCapsule(modelEntity);
|
|
18
|
-
ColliderManager.SetCapsuleColliderRadius(collider, 1.0);
|
|
19
|
-
ColliderManager.SetCapsuleColliderHeight(collider, 3.0);
|
|
20
|
-
GrabInteractableManager.Create(modelEntity);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const surgerySim = async () => {
|
|
24
|
-
const modelEntity: Entity = await renderGltf("hospital-bed.glb");
|
|
25
|
-
TransformManager.SetLocalPosition(modelEntity, vec3.fromValues(0, 0.5, 0));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
surgerySim();
|
|
29
|
-
|
|
30
|
-
// cameraRenderTexture();
|
|
31
|
-
// heartModel();
|
|
32
|
-
|
|
33
|
-
console.log(process.cwd());
|
|
34
|
-
setInterval(() => {
|
|
35
|
-
console.log("Ticked!");
|
|
36
|
-
}, 30000);
|