Added RPC tests

- Added test_cloud_point.dll
 - Added RpcTest.cs for test connection
This commit is contained in:
Max Barashev 2026-04-21 14:14:55 +03:00
parent e121987b85
commit acebaaec90
10 changed files with 332 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: 06a7b17ecdbb5c9449a742b22a92e15e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: 0085411ee3293a54fa12baa31d1d7515
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@ -746,6 +746,50 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &409312059
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 409312061}
- component: {fileID: 409312062}
m_Layer: 0
m_Name: TestThread
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &409312061
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 409312059}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -5.6778817, y: -23.816536, z: 1.4010417}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &409312062
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 409312059}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a311d9ad88850f649bf10fa4ce965a3d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &410087039 --- !u!1 &410087039
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2383,3 +2427,4 @@ SceneRoots:
- {fileID: 1537229630} - {fileID: 1537229630}
- {fileID: 763126626} - {fileID: 763126626}
- {fileID: 670812665} - {fileID: 670812665}
- {fileID: 409312061}

View File

@ -49,7 +49,7 @@ public class BlendShaderController : MonoBehaviour
void InitializeComputeBuffer() void InitializeComputeBuffer()
{ {
computeBuffer = new ComputeBuffer(currentRes * currentRes, 1 * sizeof(float));//2 dimensional array of 1 value type of double computeBuffer = new ComputeBuffer(currentRes * currentRes, 1 * sizeof(float));//2 dimensional array of 1 value type of float
} }
void InitializeTextures() void InitializeTextures()

148
Assets/Scripts/CrpcApi.cs Normal file
View File

@ -0,0 +1,148 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace CloudPointRpc
{
public static partial class CrpcTestApi
{
private const string DllName = "test_cloud_point";
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr RpcStringCallback(IntPtr rpcString);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_init();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_deinit();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_add_method(RpcStringCallback cb, IntPtr name);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int crpc_test_remove_method(IntPtr name);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_schedule_call(IntPtr name);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_change_duration(ulong durationMs);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong crpc_test_duration();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_test_auto_call(uint state);
}
public static partial class CrpcServerApi
{
private const string DllName = "libcloud_point_rpc";
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern IntPtr crpc_str_get_data(IntPtr rpcString);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong crpc_str_get_size(IntPtr rpcString);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern IntPtr crpc_str_create(byte[] data, ulong size);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_str_destroy(IntPtr rpcString);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void crpc_init(byte[] configPath);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_deinit();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void crpc_add_method(CrpcTestApi.RpcStringCallback cb, IntPtr name);
}
public sealed class RpcString : IDisposable
{
private IntPtr _handle;
private bool _disposed;
public IntPtr Handle => _handle;
public RpcString(string data)
{
var bytes = Encoding.UTF8.GetBytes(data);
_handle = CrpcServerApi.crpc_str_create(bytes, (ulong)bytes.Length);
}
internal RpcString(IntPtr handle)
{
_handle = handle;
}
public string Data
{
get
{
if (_disposed || _handle == IntPtr.Zero)
return string.Empty;
var dataPtr = CrpcServerApi.crpc_str_get_data(_handle);
var size = CrpcServerApi.crpc_str_get_size(_handle);
if (dataPtr == IntPtr.Zero || size == 0)
return string.Empty;
return Marshal.PtrToStringAnsi(dataPtr, (int)size) ?? string.Empty;
}
}
public void Dispose()
{
if (!_disposed && _handle != IntPtr.Zero)
{
CrpcServerApi.crpc_str_destroy(_handle);
_handle = IntPtr.Zero;
_disposed = true;
}
}
~RpcString()
{
Dispose();
}
}
public static class CrpcTestExtensions
{
public static void CrpcTestAddMethod(CrpcTestApi.RpcStringCallback cb, string name)
{
using var nameRpc = new RpcString(name);
CrpcTestApi.crpc_test_add_method(cb, nameRpc.Handle);
}
public static int CrpcTestRemoveMethod(string name)
{
using var nameRpc = new RpcString(name);
return CrpcTestApi.crpc_test_remove_method(nameRpc.Handle);
}
public static void CrpcTestScheduleCall(string name)
{
using var nameRpc = new RpcString(name);
CrpcTestApi.crpc_test_schedule_call(nameRpc.Handle);
}
public static void CrpcAddMethod(CrpcTestApi.RpcStringCallback cb, string name)
{
using var nameRpc = new RpcString(name);
CrpcServerApi.crpc_add_method(cb, nameRpc.Handle);
}
public static void CrpcInit(string configPath)
{
var bytes = Encoding.UTF8.GetBytes(configPath + '\0');
CrpcServerApi.crpc_init(bytes);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54dd0ebb0da474f4d8367649ea1b09f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

62
Assets/Scripts/RpcTest.cs Normal file
View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using CloudPointRpc;
public class RpcTest : MonoBehaviour
{
private static Queue<Task> _callbackTasks = new Queue<Task>();
[AOT.MonoPInvokeCallback(typeof(CrpcTestApi.RpcStringCallback))]
public static IntPtr RpcStringCallback(IntPtr rpcString)
{
Debug.Log("smth recieved");
var rpc = new RpcString(rpcString);
var message = rpc.Data;
rpc.Dispose();
var task = new Task(() => Debug.Log($"[RpcTest] Callback received: {message}"));
lock (_callbackTasks)
{
_callbackTasks.Enqueue(task);
}
task.Wait();
var responce = new RpcString("1");
return responce.Handle;
}
void Start()
{
CrpcTestApi.crpc_test_init();
CrpcTestExtensions.CrpcTestAddMethod(RpcStringCallback, "test_method");
Debug.Log("[RpcTest] Initialized and method added");
}
private void Update()
{
lock (_callbackTasks)
{
while (_callbackTasks.Count > 0)
{
var task = _callbackTasks.Dequeue();
task.Start();
}
}
}
private void OnDestroy()
{
lock (_callbackTasks)
{
_callbackTasks.Clear();
}
CrpcTestApi.crpc_test_deinit();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a311d9ad88850f649bf10fa4ce965a3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: