Files

77 lines
1.7 KiB
C#
Raw Permalink Normal View History

2022-12-04 19:19:07 +02:00
using System.Diagnostics;
using Unity.Collections;
2022-12-06 12:22:07 +02:00
namespace SharedGame
{
2022-12-04 19:19:07 +02:00
2022-12-06 12:22:07 +02:00
public class Connections
{
2022-12-04 19:19:07 +02:00
public ushort port;
public string ip;
public bool spectator;
}
2022-12-06 12:22:07 +02:00
public interface IGame
{
2023-06-28 17:51:13 +03:00
int Frames { get; }
2022-12-04 19:19:07 +02:00
int Checksum { get; }
void Update(long[] inputs, int disconnectFlags);
void FromBytes(NativeArray<byte> data);
NativeArray<byte> ToBytes();
long ReadInputs(int controllerId);
void LogInfo(string filename);
void FreeBytes(NativeArray<byte> data);
}
2022-12-06 12:22:07 +02:00
public struct StatusInfo
{
2022-12-04 19:19:07 +02:00
public float idlePerc;
public float updatePerc;
public ChecksumInfo now;
public ChecksumInfo periodic;
2022-12-06 12:22:07 +02:00
public string TimePercString()
{
2022-12-04 19:19:07 +02:00
var otherPerc = 1f - (idlePerc + updatePerc);
return string.Format("idle:{0:.00} update{1:.00} other{2:.00}", idlePerc, updatePerc, otherPerc);
}
2022-12-06 12:22:07 +02:00
public string ChecksumString()
{
2022-12-04 19:19:07 +02:00
return "periodic: " + RenderChecksum(periodic) + " now:" + RenderChecksum(now);
}
2022-12-06 12:22:07 +02:00
private string RenderChecksum(ChecksumInfo info)
{
2022-12-04 19:19:07 +02:00
return string.Format("f:{0} c:{1}", info.framenumber, info.checksum); // %04d %08x
}
}
2022-12-06 12:22:07 +02:00
public interface IGameRunner
{
2022-12-04 19:19:07 +02:00
IGame Game { get; }
GameInfo GameInfo { get; }
void Idle(int ms);
void RunFrame();
StatusInfo GetStatus(Stopwatch updateWatch);
void DisconnectPlayer(int player);
void Shutdown();
}
2022-12-06 12:22:07 +02:00
public interface IGameView
{
2022-12-04 19:19:07 +02:00
void UpdateGameView(IGameRunner runner);
}
}