chore: updated projects properties for nuget
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>10</LangVersion>
|
||||
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
|
||||
<Authors>Eduard Kargin (Edmand46)</Authors>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Title>Ragon.Protocol</Title>
|
||||
<Copyright>Eduard Kargin</Copyright>
|
||||
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
||||
<Version>1.4.0</Version>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||
<RepositoryType>Source</RepositoryType>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
|
||||
@@ -4,7 +4,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Ragon.ENet</RootNamespace>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Copyright>Eduard Kargin</Copyright>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<Version>1.4.0</Version>
|
||||
<Title>Ragon Server ENet</Title>
|
||||
<Description>Ragon Server ENet transport</Description>
|
||||
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||
<RepositoryType>Source</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Ragon.WebSockets</RootNamespace>
|
||||
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<Copyright>Eduard Kargin</Copyright>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>1.4.0</Version>
|
||||
<Title>Ragon Server WebSocket</Title>
|
||||
<Description>Ragon Server WebSocket transport</Description>
|
||||
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||
<RepositoryType>Source</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Ragon.Core</RootNamespace>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>1.3.1</Version>
|
||||
<Version>1.4.0</Version>
|
||||
<Title>Ragon.Server</Title>
|
||||
<Copyright>Eduard Kargin</Copyright>
|
||||
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||
<RepositoryType>Source</RepositoryType>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
<LangVersion>10</LangVersion>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -65,7 +65,6 @@ public class BaseRoomPlugin: IRoomPlugin
|
||||
|
||||
public virtual bool OnData(RagonRoomPlayer player, byte[] data)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using Ragon.Client.Simulation;
|
||||
|
||||
var simulation = new Simulation();
|
||||
simulation.Start();
|
||||
@@ -1,32 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ragon.Client.Property\Ragon.Client.Property.csproj" />
|
||||
<ProjectReference Include="..\Ragon.Client\Ragon.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
||||
<PackageReference Include="Raylib-cs" Version="4.5.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="libenet.dylib">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Sources\Server\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,143 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Raylib_cs;
|
||||
using static Raylib_cs.Raylib;
|
||||
|
||||
namespace Ragon.Simulation;
|
||||
|
||||
public class Client
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new();
|
||||
camera.Position = new Vector3(0.2f, 0.4f, 0.2f);
|
||||
camera.Target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||
camera.FovY = 45.0f;
|
||||
camera.Projection = CameraProjection.CAMERA_PERSPECTIVE;
|
||||
|
||||
Image imMap = LoadImage("resources/cubicmap.png");
|
||||
Texture2D cubicmap = LoadTextureFromImage(imMap);
|
||||
Mesh mesh = GenMeshCubicmap(imMap, new Vector3(1.0f, 1.0f, 1.0f));
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||
|
||||
// Set map diffuse texture
|
||||
Raylib.SetMaterialTexture(ref model, 0, MaterialMapIndex.MATERIAL_MAP_ALBEDO, ref texture);
|
||||
|
||||
// Get map image data to be used for collision detection
|
||||
Color* mapPixels = LoadImageColors(imMap);
|
||||
UnloadImage(imMap);
|
||||
|
||||
Vector3 mapPosition = new(-16.0f, 0.0f, -8.0f);
|
||||
Vector3 playerPosition = camera.Position;
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
Vector3 oldCamPos = camera.Position;
|
||||
|
||||
UpdateCamera(ref camera, CameraMode.CAMERA_FIRST_PERSON);
|
||||
|
||||
// Check player collision (we simplify to 2D collision detection)
|
||||
Vector2 playerPos = new(camera.Position.X, camera.Position.Z);
|
||||
|
||||
// Collision radius (player is modelled as a cilinder for collision)
|
||||
float playerRadius = 0.1f;
|
||||
|
||||
int playerCellX = (int)(playerPos.X - mapPosition.X + 0.5f);
|
||||
int playerCellY = (int)(playerPos.Y - mapPosition.Z + 0.5f);
|
||||
|
||||
// Out-of-limits security check
|
||||
if (playerCellX < 0)
|
||||
{
|
||||
playerCellX = 0;
|
||||
}
|
||||
else if (playerCellX >= cubicmap.Width)
|
||||
{
|
||||
playerCellX = cubicmap.Width - 1;
|
||||
}
|
||||
|
||||
if (playerCellY < 0)
|
||||
{
|
||||
playerCellY = 0;
|
||||
}
|
||||
else if (playerCellY >= cubicmap.Height)
|
||||
{
|
||||
playerCellY = cubicmap.Height - 1;
|
||||
}
|
||||
|
||||
// Check map collisions using image data and player position
|
||||
// TODO: Improvement: Just check player surrounding cells for collision
|
||||
for (int y = 0; y < cubicmap.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < cubicmap.Width; x++)
|
||||
{
|
||||
Color* mapPixelsData = mapPixels;
|
||||
|
||||
// Collision: Color.white pixel, only check R channel
|
||||
Rectangle rec = new(
|
||||
mapPosition.X - 0.5f + x * 1.0f,
|
||||
mapPosition.Z - 0.5f + y * 1.0f,
|
||||
1.0f,
|
||||
1.0f
|
||||
);
|
||||
|
||||
bool collision = CheckCollisionCircleRec(playerPos, playerRadius, rec);
|
||||
if ((mapPixelsData[y * cubicmap.Width + x].R == 255) && collision)
|
||||
{
|
||||
// Collision detected, reset camera position
|
||||
camera.Position = oldCamPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RAYWHITE);
|
||||
|
||||
// Draw maze map
|
||||
BeginMode3D(camera);
|
||||
DrawModel(model, mapPosition, 1.0f, Color.WHITE);
|
||||
EndMode3D();
|
||||
|
||||
DrawTextureEx(cubicmap, new Vector2(GetScreenWidth() - cubicmap.Width * 4 - 20, 20), 0.0f, 4.0f, Color.WHITE);
|
||||
DrawRectangleLines(GetScreenWidth() - cubicmap.Width * 4 - 20, 20, cubicmap.Width * 4, cubicmap.Height * 4, Color.GREEN);
|
||||
|
||||
// Draw player position radar
|
||||
DrawRectangle(GetScreenWidth() - cubicmap.Width * 4 - 20 + playerCellX * 4, 20 + playerCellY * 4, 4, 4, Color.RED);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadImageColors(mapPixels);
|
||||
|
||||
UnloadTexture(cubicmap);
|
||||
UnloadTexture(texture);
|
||||
UnloadModel(model);
|
||||
|
||||
CloseWindow();
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using ENet;
|
||||
using Ragon.Protocol;
|
||||
using Event = ENet.Event;
|
||||
using EventType = ENet.EventType;
|
||||
|
||||
namespace Ragon.Client
|
||||
{
|
||||
public class RagonENetConnection : INetworkConnection
|
||||
{
|
||||
public ushort Id { get; }
|
||||
|
||||
public NetworkStatistics Statistics { get; private set; }
|
||||
public INetworkChannel Reliable { get; private set; }
|
||||
public INetworkChannel Unreliable { get; private set; }
|
||||
|
||||
public Action<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<RagonDisconnect> OnDisconnected { get; set; }
|
||||
public ulong BytesSent { get; }
|
||||
public ulong BytesReceived { get; }
|
||||
public int Ping { get; }
|
||||
|
||||
private static bool _libraryLoaded = false;
|
||||
private Host _host;
|
||||
private Peer _peer;
|
||||
private Event _netEvent;
|
||||
|
||||
public RagonENetConnection()
|
||||
{
|
||||
_host = new Host();
|
||||
_host.Create();
|
||||
}
|
||||
|
||||
|
||||
public void Prepare()
|
||||
{
|
||||
if (!_libraryLoaded)
|
||||
{
|
||||
Library.Initialize();
|
||||
_libraryLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
if (_peer.IsSet)
|
||||
_peer.DisconnectNow(0);
|
||||
}
|
||||
|
||||
public void Connect(string server, ushort port, uint protocol)
|
||||
{
|
||||
Address address = new Address();
|
||||
address.SetHost(server);
|
||||
address.Port = port;
|
||||
|
||||
_peer = _host.Connect(address, 2, protocol);
|
||||
_peer.Timeout(32, 5000, 5000);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
bool polled = false;
|
||||
while (!polled)
|
||||
{
|
||||
if (_host.CheckEvents(out _netEvent) <= 0)
|
||||
{
|
||||
if (_host.Service(0, out _netEvent) <= 0)
|
||||
break;
|
||||
|
||||
polled = true;
|
||||
}
|
||||
|
||||
switch (_netEvent.Type)
|
||||
{
|
||||
case EventType.None:
|
||||
break;
|
||||
case EventType.Connect:
|
||||
Statistics = new NetworkStatistics();
|
||||
Reliable = new ENetReliableChannel(_netEvent.Peer, 0);
|
||||
Unreliable = new ENetUnreliableChannel(_netEvent.Peer, 1);
|
||||
|
||||
OnConnected?.Invoke();
|
||||
break;
|
||||
case EventType.Disconnect:
|
||||
OnDisconnected?.Invoke(RagonDisconnect.SERVER);
|
||||
break;
|
||||
case EventType.Timeout:
|
||||
OnDisconnected?.Invoke(RagonDisconnect.TIMEOUT);
|
||||
break;
|
||||
case EventType.Receive:
|
||||
var data = new byte[_netEvent.Packet.Length];
|
||||
|
||||
_netEvent.Packet.CopyTo(data);
|
||||
_netEvent.Packet.Dispose();
|
||||
|
||||
OnData?.Invoke(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_host.IsSet)
|
||||
{
|
||||
_host?.Flush();
|
||||
_host?.Dispose();
|
||||
}
|
||||
|
||||
if (_libraryLoaded)
|
||||
Library.Deinitialize();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using ENet;
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public sealed class ENetReliableChannel : INetworkChannel
|
||||
{
|
||||
private Peer _peer;
|
||||
private byte _channelId;
|
||||
|
||||
public ENetReliableChannel(Peer peer, int channelId)
|
||||
{
|
||||
_peer = peer;
|
||||
_channelId = (byte) channelId;
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
var newPacket = new Packet();
|
||||
newPacket.Create(data, data.Length, PacketFlags.Reliable);
|
||||
|
||||
_peer.Send(_channelId, ref newPacket);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using ENet;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public sealed class ENetUnreliableChannel : INetworkChannel
|
||||
{
|
||||
private Peer _peer;
|
||||
private byte _channelId;
|
||||
|
||||
public ENetUnreliableChannel(Peer peer, int channelId)
|
||||
{
|
||||
_peer = peer;
|
||||
_channelId = (byte) channelId;
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
var newPacket = new Packet();
|
||||
newPacket.Create(data, data.Length, PacketFlags.None);
|
||||
|
||||
_peer.Send(_channelId, ref newPacket);
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using ENet;
|
||||
using Ragon.Protocol;
|
||||
using Event = ENet.Event;
|
||||
using EventType = ENet.EventType;
|
||||
|
||||
namespace Ragon.Client
|
||||
{
|
||||
public class RagonNullConnection : INetworkConnection
|
||||
{
|
||||
public ushort Id { get; }
|
||||
|
||||
public NetworkStatistics Statistics { get; private set; }
|
||||
public INetworkChannel Reliable { get; private set; }
|
||||
public INetworkChannel Unreliable { get; private set; }
|
||||
|
||||
public Action<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<RagonDisconnect> OnDisconnected { get; set; }
|
||||
public ulong BytesSent { get; }
|
||||
public ulong BytesReceived { get; }
|
||||
public int Ping { get; }
|
||||
|
||||
private static bool _libraryLoaded = false;
|
||||
private Host _host;
|
||||
private Peer _peer;
|
||||
private Event _netEvent;
|
||||
|
||||
public RagonNullConnection()
|
||||
{
|
||||
_host = new Host();
|
||||
_host.Create();
|
||||
}
|
||||
|
||||
|
||||
public void Prepare()
|
||||
{
|
||||
if (!_libraryLoaded)
|
||||
{
|
||||
Library.Initialize();
|
||||
_libraryLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
if (_peer.IsSet)
|
||||
_peer.DisconnectNow(0);
|
||||
}
|
||||
|
||||
public void Connect(string server, ushort port, uint protocol)
|
||||
{
|
||||
Address address = new Address();
|
||||
address.SetHost(server);
|
||||
address.Port = port;
|
||||
|
||||
_peer = _host.Connect(address, 2, protocol);
|
||||
_peer.Timeout(32, 5000, 5000);
|
||||
|
||||
Statistics = new NetworkStatistics();
|
||||
Reliable = new NullReliableChannel(_netEvent.Peer, 0);
|
||||
Unreliable = new NullUnreliableChannel(_netEvent.Peer, 1);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
bool polled = false;
|
||||
while (!polled)
|
||||
{
|
||||
if (_host.CheckEvents(out _netEvent) <= 0)
|
||||
{
|
||||
if (_host.Service(0, out _netEvent) <= 0)
|
||||
break;
|
||||
|
||||
polled = true;
|
||||
}
|
||||
|
||||
switch (_netEvent.Type)
|
||||
{
|
||||
case EventType.None:
|
||||
break;
|
||||
case EventType.Connect:
|
||||
|
||||
OnConnected?.Invoke();
|
||||
break;
|
||||
case EventType.Disconnect:
|
||||
OnDisconnected?.Invoke(RagonDisconnect.SERVER);
|
||||
break;
|
||||
case EventType.Timeout:
|
||||
OnDisconnected?.Invoke(RagonDisconnect.TIMEOUT);
|
||||
break;
|
||||
case EventType.Receive:
|
||||
var data = new byte[_netEvent.Packet.Length];
|
||||
|
||||
_netEvent.Packet.CopyTo(data);
|
||||
_netEvent.Packet.Dispose();
|
||||
|
||||
OnData?.Invoke(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_host.IsSet)
|
||||
{
|
||||
_host?.Flush();
|
||||
_host?.Dispose();
|
||||
}
|
||||
|
||||
if (_libraryLoaded)
|
||||
Library.Deinitialize();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using ENet;
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public sealed class NullReliableChannel : INetworkChannel
|
||||
{
|
||||
private Peer _peer;
|
||||
private byte _channelId;
|
||||
|
||||
public NullReliableChannel(Peer peer, int channelId)
|
||||
{
|
||||
_peer = peer;
|
||||
_channelId = (byte) channelId;
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using ENet;
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public sealed class NullUnreliableChannel : INetworkChannel
|
||||
{
|
||||
private Peer _peer;
|
||||
private byte _channelId;
|
||||
|
||||
public NullUnreliableChannel(Peer peer, int channelId)
|
||||
{
|
||||
_peer = peer;
|
||||
_channelId = (byte) channelId;
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client.Simulation.Sources;
|
||||
|
||||
public class PlayerPayload : IRagonPayload
|
||||
{
|
||||
public uint Name { get; set; }
|
||||
|
||||
public void Serialize(RagonBuffer buffer)
|
||||
{
|
||||
buffer.Write(Name, 16);
|
||||
}
|
||||
|
||||
public void Deserialize(RagonBuffer buffer)
|
||||
{
|
||||
Name = buffer.Read(16);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
using Ragon.Client.Property;
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client.Simulation;
|
||||
|
||||
public class Game : IRagonListener, IRagonSceneRequestListener
|
||||
{
|
||||
private RagonFloat _health;
|
||||
private RagonInt _points;
|
||||
private RagonString _name;
|
||||
private RagonEntity _entity;
|
||||
private RagonClient _client;
|
||||
|
||||
public Game(RagonClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public void OnConnected(RagonClient client)
|
||||
{
|
||||
RagonLog.Trace("Connected");
|
||||
_client.Session.AuthorizeWithKey("defaultkey", "Player Eduard");
|
||||
}
|
||||
|
||||
public void OnAuthorizationSuccess(RagonClient client, string playerId, string playerName)
|
||||
{
|
||||
RagonLog.Trace("Authorized");
|
||||
client.Session.CreateOrJoin("Example", 1, 20);
|
||||
}
|
||||
|
||||
public void OnAuthorizationFailed(RagonClient client, string message)
|
||||
{
|
||||
Console.WriteLine($"Authorization failed: {message}");
|
||||
}
|
||||
|
||||
public void OnJoined(RagonClient client)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnFailed(RagonClient client, string message)
|
||||
{
|
||||
RagonLog.Trace("Failed to join");
|
||||
}
|
||||
|
||||
public void OnLeft(RagonClient client)
|
||||
{
|
||||
RagonLog.Trace("Left");
|
||||
}
|
||||
|
||||
public void OnDisconnected(RagonClient client, RagonDisconnect ragonDisconnect)
|
||||
{
|
||||
RagonLog.Trace("Disconnected");
|
||||
}
|
||||
|
||||
public void OnPlayerJoined(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Player joined");
|
||||
}
|
||||
|
||||
public void OnPlayerLeft(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Player left");
|
||||
}
|
||||
|
||||
public void OnOwnershipChanged(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Owner ship changed");
|
||||
}
|
||||
|
||||
public void OnSceneLoaded(RagonClient client)
|
||||
{
|
||||
RagonLog.Trace("Joined");
|
||||
|
||||
_health = new RagonFloat(100.0f, false, 0);
|
||||
_health.Changed += () => Console.WriteLine($"[Ragon Property] Health: {_health.Value}");
|
||||
|
||||
_points = new RagonInt(0, -1000, 1000, false, 0);
|
||||
_points.Changed += () => Console.WriteLine($"[Ragon Property] Points: {_points.Value}");
|
||||
|
||||
_name = new RagonString("Edmand 000", false);
|
||||
_name.Changed += () => Console.WriteLine($"[Ragon Property] Name: {_name.Value}");
|
||||
|
||||
_entity = new RagonEntity(12, 0);
|
||||
_entity.State.AddProperty(_health);
|
||||
_entity.State.AddProperty(_points);
|
||||
_entity.State.AddProperty(_name);
|
||||
|
||||
client.Room.CreateEntity(_entity);
|
||||
}
|
||||
|
||||
private float _timer = 0;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_client.Status != RagonStatus.ROOM)
|
||||
return;
|
||||
|
||||
_timer += 1 / 60.0f;
|
||||
if (_timer > 1)
|
||||
{
|
||||
_health.Value += 20.0f;
|
||||
_points.Value += 10;
|
||||
_name.Value = $"Edmand 00{_client.Room.Local.PeerId}";
|
||||
Console.WriteLine($"{_health.Value} {_points.Value} {_name.Value}");
|
||||
_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRequestScene(RagonClient client, string sceneName)
|
||||
{
|
||||
client.Room.SceneLoaded();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using Ragon.Client;
|
||||
using Ragon.Client.Simulation;
|
||||
|
||||
namespace Ragon.Simulation;
|
||||
|
||||
public class EntityListener : IRagonEntityListener
|
||||
{
|
||||
public void OnEntityCreated(RagonEntity entity)
|
||||
{
|
||||
var health = new RagonFloat(100.0f, false, 0);
|
||||
health.Value = 50;
|
||||
health.Changed += () => Console.WriteLine($"[Ragon Property] Another Health: {health.Value}");
|
||||
|
||||
var points = new RagonInt(0, -1000, 1000, false, 0);
|
||||
points.Changed += () => Console.WriteLine($"[Ragon Property] Anther Points: {points.Value}");
|
||||
|
||||
var name = new RagonString("Eduard", false);
|
||||
name.Changed += () => Console.WriteLine($"[Ragon Property] Another Name: {name.Value}");
|
||||
|
||||
entity.State.AddProperty(health);
|
||||
entity.State.AddProperty(points);
|
||||
entity.State.AddProperty(name);
|
||||
}
|
||||
}
|
||||
|
||||
public class Simulation
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
var client = new Ragon.Simulation.Client();
|
||||
client.Start();
|
||||
|
||||
// INetworkConnection protocol = debug ? new RagonNullConnection() : new RagonENetConnection();
|
||||
// var network = new RagonClient(protocol, new EntityListener(), 30);
|
||||
// var game = new Game(network);
|
||||
// network.AddListener(game);
|
||||
// network.Connect("127.0.0.1", 5001, "1.0.0");
|
||||
// var dt = 1000 / 60.0f;
|
||||
// while (true)
|
||||
// {
|
||||
// game.Update();
|
||||
// network.Update(dt);
|
||||
// Thread.Sleep((int) dt);
|
||||
// }
|
||||
//
|
||||
// network.Disconnect();
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Server.ENetServer", "
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Client", "Ragon.Client\Ragon.Client.csproj", "{C82D65BF-6D80-4263-ADFE-CB9ED990B6C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Simulation", "Ragon.Simulation\Ragon.Simulation.csproj", "{0384848D-3B63-4B3A-B15F-A836EBB3E95D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Client.Property", "Ragon.Client.Property\Ragon.Client.Property.csproj", "{46A60DAB-F854-4BB6-A119-BD4C5B2B0D29}"
|
||||
EndProject
|
||||
Global
|
||||
@@ -46,10 +44,6 @@ Global
|
||||
{C82D65BF-6D80-4263-ADFE-CB9ED990B6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C82D65BF-6D80-4263-ADFE-CB9ED990B6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C82D65BF-6D80-4263-ADFE-CB9ED990B6C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0384848D-3B63-4B3A-B15F-A836EBB3E95D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0384848D-3B63-4B3A-B15F-A836EBB3E95D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0384848D-3B63-4B3A-B15F-A836EBB3E95D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0384848D-3B63-4B3A-B15F-A836EBB3E95D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{46A60DAB-F854-4BB6-A119-BD4C5B2B0D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{46A60DAB-F854-4BB6-A119-BD4C5B2B0D29}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{46A60DAB-F854-4BB6-A119-BD4C5B2B0D29}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
||||
Reference in New Issue
Block a user