reformat code + level load events
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class CustomCharacterController : CharacterController
|
||||
{
|
||||
}
|
||||
public class CustomCharacterController : CharacterController
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using Cabrito;
|
||||
using FlaxEngine;
|
||||
using Cabrito;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public static class InputManager
|
||||
{
|
||||
public static bool GetAction(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return false;
|
||||
return Input.GetAction(name);
|
||||
}
|
||||
public static class InputManager
|
||||
{
|
||||
public static bool GetAction(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return false;
|
||||
return Input.GetAction(name);
|
||||
}
|
||||
|
||||
public static float GetAxis(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return 0.0f;
|
||||
return Input.GetAxis(name);
|
||||
}
|
||||
public static float GetAxis(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return 0.0f;
|
||||
return Input.GetAxis(name);
|
||||
}
|
||||
|
||||
public static float GetAxisRaw(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return 0.0f;
|
||||
return Input.GetAxisRaw(name);
|
||||
}
|
||||
}
|
||||
public static float GetAxisRaw(string name)
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return 0.0f;
|
||||
return Input.GetAxisRaw(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FlaxEngine;
|
||||
using Cabrito;
|
||||
#if FLAX_EDITOR
|
||||
using FlaxEditor.CustomEditors.Dedicated;
|
||||
using FlaxEditor.Scripting;
|
||||
#endif
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
@@ -16,16 +13,16 @@ namespace Game
|
||||
{
|
||||
protected override List<ItemInfo> GetItemsForType(ScriptType type)
|
||||
{
|
||||
List<ItemInfo> items = GetItemsForType(type, type.IsClass, true);
|
||||
var items = GetItemsForType(type, type.IsClass, true);
|
||||
|
||||
// Remove all Rigid Body options
|
||||
items.RemoveAll(x => x.Display.Group == "Rigid Body");
|
||||
|
||||
// Inject scripts editor
|
||||
var scriptsMember = type.GetProperty("Scripts");
|
||||
ScriptMemberInfo scriptsMember = type.GetProperty("Scripts");
|
||||
if (scriptsMember != ScriptMemberInfo.Null)
|
||||
{
|
||||
var item = new ItemInfo(scriptsMember)
|
||||
ItemInfo item = new ItemInfo(scriptsMember)
|
||||
{
|
||||
CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor))
|
||||
};
|
||||
|
||||
@@ -1,75 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerInputState
|
||||
{
|
||||
public ulong frame;
|
||||
public float viewDeltaX, viewDeltaY;
|
||||
public float moveForward;
|
||||
public float moveRight;
|
||||
public bool attacking;
|
||||
public bool jumping;
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerInputState
|
||||
{
|
||||
public ulong frame;
|
||||
public float viewDeltaX, viewDeltaY;
|
||||
public float moveForward;
|
||||
public float moveRight;
|
||||
public bool attacking;
|
||||
public bool jumping;
|
||||
|
||||
public Vector3 verificationPosition;
|
||||
public Vector3 verificationVelocity;
|
||||
public Vector3 verificationViewAngles;
|
||||
public Quaternion verificationOrientation;
|
||||
}
|
||||
public Vector3 verificationPosition;
|
||||
public Vector3 verificationVelocity;
|
||||
public Vector3 verificationViewAngles;
|
||||
public Quaternion verificationOrientation;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerActorState
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector3 velocity;
|
||||
public Quaternion orientation;
|
||||
public Vector3 viewAngles; // yaw, pitch, roll
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerActorState
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector3 velocity;
|
||||
public Quaternion orientation;
|
||||
public Vector3 viewAngles; // yaw, pitch, roll
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerState
|
||||
{
|
||||
public PlayerInputState input;
|
||||
public PlayerActorState actor;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PlayerState
|
||||
{
|
||||
public PlayerInputState input;
|
||||
public PlayerActorState actor;
|
||||
}
|
||||
|
||||
public class PlayerInput
|
||||
{
|
||||
public PlayerState currentState;
|
||||
public ulong frame;
|
||||
public class PlayerInput
|
||||
{
|
||||
public const byte DemoVer = 1;
|
||||
public PlayerState currentState;
|
||||
public ulong frame;
|
||||
|
||||
public const byte DemoVer = 1;
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
}
|
||||
public virtual void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
public virtual void OnEndFrame()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnEndFrame()
|
||||
{
|
||||
}
|
||||
public virtual void RecordCurrentActorState(PlayerActorState actorState)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void RecordCurrentActorState(PlayerActorState actorState)
|
||||
{
|
||||
}
|
||||
public PlayerInputState GetCurrentInputState()
|
||||
{
|
||||
return currentState.input;
|
||||
}
|
||||
|
||||
public PlayerInputState GetCurrentInputState()
|
||||
{
|
||||
return currentState.input;
|
||||
}
|
||||
|
||||
public PlayerActorState GetCurrentActorState()
|
||||
{
|
||||
return currentState.actor;
|
||||
}
|
||||
}
|
||||
public PlayerActorState GetCurrentActorState()
|
||||
{
|
||||
return currentState.actor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,88 +2,89 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using FlaxEngine;
|
||||
using Console = Cabrito.Console;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class PlayerInputDemo : PlayerInput
|
||||
{
|
||||
protected List<PlayerInputState> buffer = new List<PlayerInputState>();
|
||||
protected IEnumerator<PlayerInputState> bufferEnumerable;
|
||||
public class PlayerInputDemo : PlayerInput
|
||||
{
|
||||
protected List<PlayerInputState> buffer = new List<PlayerInputState>();
|
||||
protected IEnumerator<PlayerInputState> bufferEnumerable;
|
||||
|
||||
public PlayerInputDemo(string demoPath)
|
||||
{
|
||||
if (!File.Exists(demoPath))
|
||||
return;
|
||||
public PlayerInputDemo(string demoPath)
|
||||
{
|
||||
if (!File.Exists(demoPath))
|
||||
return;
|
||||
|
||||
var expectedPlayerInputStateSize = Marshal.SizeOf(typeof(PlayerInputState));
|
||||
int expectedPlayerInputStateSize = Marshal.SizeOf(typeof(PlayerInputState));
|
||||
|
||||
var stream = File.OpenRead(demoPath);
|
||||
var ver = (int)stream.ReadByte();
|
||||
var inputStateSize = (int)stream.ReadByte();
|
||||
if (ver != DemoVer && inputStateSize != expectedPlayerInputStateSize)
|
||||
{
|
||||
Console.Print("demover mismatch: version " + ver + " != " + DemoVer + ", inputStateSize " + inputStateSize + " != " + Marshal.SizeOf(typeof(PlayerInputState)));
|
||||
stream.Close();
|
||||
return;
|
||||
}
|
||||
FileStream stream = File.OpenRead(demoPath);
|
||||
int ver = stream.ReadByte();
|
||||
int inputStateSize = stream.ReadByte();
|
||||
if (ver != DemoVer && inputStateSize != expectedPlayerInputStateSize)
|
||||
{
|
||||
Console.Print("demover mismatch: version " + ver + " != " + DemoVer + ", inputStateSize " +
|
||||
inputStateSize + " != " + Marshal.SizeOf(typeof(PlayerInputState)));
|
||||
stream.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
T RawDeserialize<T>(byte[] rawData, int position)
|
||||
{
|
||||
int rawsize = Marshal.SizeOf(typeof(T));
|
||||
if (rawsize > rawData.Length - position)
|
||||
throw new ArgumentException("Not enough data to fill struct. Array length from position: " + (rawData.Length-position) + ", Struct length: " + rawsize);
|
||||
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
|
||||
Marshal.Copy(rawData, position, buffer, rawsize);
|
||||
T retobj = (T)Marshal.PtrToStructure(buffer, typeof(T));
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
return retobj;
|
||||
}
|
||||
T RawDeserialize<T>(byte[] rawData, int position)
|
||||
{
|
||||
int rawsize = Marshal.SizeOf(typeof(T));
|
||||
if (rawsize > rawData.Length - position)
|
||||
throw new ArgumentException("Not enough data to fill struct. Array length from position: " +
|
||||
(rawData.Length - position) + ", Struct length: " + rawsize);
|
||||
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
|
||||
Marshal.Copy(rawData, position, buffer, rawsize);
|
||||
T retobj = (T)Marshal.PtrToStructure(buffer, typeof(T));
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
return retobj;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
byte[] b = new byte[expectedPlayerInputStateSize];
|
||||
var readBytes = stream.Read(b, 0, b.Length);
|
||||
if (readBytes < expectedPlayerInputStateSize)
|
||||
break;
|
||||
while (true)
|
||||
{
|
||||
byte[] b = new byte[expectedPlayerInputStateSize];
|
||||
int readBytes = stream.Read(b, 0, b.Length);
|
||||
if (readBytes < expectedPlayerInputStateSize)
|
||||
break;
|
||||
|
||||
buffer.Add(RawDeserialize<PlayerInputState>(b, 0));
|
||||
}
|
||||
buffer.Add(RawDeserialize<PlayerInputState>(b, 0));
|
||||
}
|
||||
|
||||
bufferEnumerable = buffer.GetEnumerator();
|
||||
bufferEnumerable = buffer.GetEnumerator();
|
||||
|
||||
Console.Print("demo numstates: " + buffer.Count);
|
||||
Console.Print("demo numstates: " + buffer.Count);
|
||||
|
||||
OnEndFrame(); // advances to first frame
|
||||
}
|
||||
OnEndFrame(); // advances to first frame
|
||||
}
|
||||
|
||||
public override void OnEndFrame()
|
||||
{
|
||||
// TODO: check if the current state frame matches the current frame number before advancing
|
||||
public override void OnEndFrame()
|
||||
{
|
||||
// TODO: check if the current state frame matches the current frame number before advancing
|
||||
|
||||
/*asdf++;
|
||||
if (asdf < 8)
|
||||
return;*/
|
||||
/*asdf++;
|
||||
if (asdf < 8)
|
||||
return;*/
|
||||
|
||||
if (bufferEnumerable == null || !bufferEnumerable.MoveNext())
|
||||
{
|
||||
if (buffer.Any())
|
||||
{
|
||||
bufferEnumerable.Dispose();
|
||||
bufferEnumerable = null;
|
||||
buffer.Clear();
|
||||
Console.Print("Demo ended");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (bufferEnumerable == null || !bufferEnumerable.MoveNext())
|
||||
{
|
||||
if (buffer.Any())
|
||||
{
|
||||
bufferEnumerable.Dispose();
|
||||
bufferEnumerable = null;
|
||||
buffer.Clear();
|
||||
Console.Print("Demo ended");
|
||||
}
|
||||
|
||||
//var actorState = currentState.actor;
|
||||
currentState.input = bufferEnumerable.Current;
|
||||
//frame++;
|
||||
//currentState.actor = actorState;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//var actorState = currentState.actor;
|
||||
currentState.input = bufferEnumerable.Current;
|
||||
//frame++;
|
||||
//currentState.actor = actorState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,117 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using FlaxEngine;
|
||||
using Console = Cabrito.Console;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class PlayerInputLocal : PlayerInput
|
||||
{
|
||||
protected List<PlayerInputState> buffer = new List<PlayerInputState>();
|
||||
protected FileStream demoFileStream;
|
||||
public class PlayerInputLocal : PlayerInput
|
||||
{
|
||||
protected List<PlayerInputState> buffer = new List<PlayerInputState>();
|
||||
protected FileStream demoFileStream;
|
||||
|
||||
public bool IsRecording { get { return demoFileStream != null; } }
|
||||
public PlayerInputLocal()
|
||||
{
|
||||
}
|
||||
|
||||
public PlayerInputLocal()
|
||||
{
|
||||
}
|
||||
public PlayerInputLocal(string demoPath)
|
||||
{
|
||||
demoFileStream = File.Open(demoPath, FileMode.Create, FileAccess.Write);
|
||||
//stream.Position = 0;
|
||||
//stream.SetLength(0);
|
||||
demoFileStream.WriteByte(DemoVer);
|
||||
demoFileStream.WriteByte((byte)Marshal.SizeOf(typeof(PlayerInputState)));
|
||||
}
|
||||
|
||||
public PlayerInputLocal(string demoPath)
|
||||
{
|
||||
demoFileStream = File.Open(demoPath, FileMode.Create, FileAccess.Write);
|
||||
//stream.Position = 0;
|
||||
//stream.SetLength(0);
|
||||
demoFileStream.WriteByte(DemoVer);
|
||||
demoFileStream.WriteByte((byte)Marshal.SizeOf(typeof(PlayerInputState)));
|
||||
}
|
||||
public bool IsRecording => demoFileStream != null;
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Collect all input here
|
||||
// All axis values here should be accumulated
|
||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("Mouse X");
|
||||
currentState.input.viewDeltaY += InputManager.GetAxisRaw("Mouse Y");
|
||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("LookRight") * Time.DeltaTime * 100;
|
||||
currentState.input.viewDeltaY += -InputManager.GetAxisRaw("LookUp") * Time.DeltaTime * 100;
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Collect all input here
|
||||
// All axis values here should be accumulated
|
||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("Mouse X");
|
||||
currentState.input.viewDeltaY += InputManager.GetAxisRaw("Mouse Y");
|
||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("LookRight") * Time.DeltaTime * 100;
|
||||
currentState.input.viewDeltaY += -InputManager.GetAxisRaw("LookUp") * Time.DeltaTime * 100;
|
||||
|
||||
currentState.input.moveForward = InputManager.GetAxis("Vertical");
|
||||
currentState.input.moveRight = InputManager.GetAxis("Horizontal");
|
||||
currentState.input.attacking = InputManager.GetAction("Attack");
|
||||
currentState.input.jumping = InputManager.GetAction("Jump");
|
||||
}
|
||||
currentState.input.moveForward = InputManager.GetAxis("Vertical");
|
||||
currentState.input.moveRight = InputManager.GetAxis("Horizontal");
|
||||
currentState.input.attacking = InputManager.GetAction("Attack");
|
||||
currentState.input.jumping = InputManager.GetAction("Jump");
|
||||
}
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnEndFrame()
|
||||
{
|
||||
if (IsRecording)
|
||||
{
|
||||
currentState.input.verificationPosition = currentState.actor.position;
|
||||
currentState.input.verificationVelocity = currentState.actor.velocity;
|
||||
currentState.input.verificationViewAngles = currentState.actor.viewAngles;
|
||||
currentState.input.verificationOrientation = currentState.actor.orientation;
|
||||
public override void OnEndFrame()
|
||||
{
|
||||
if (IsRecording)
|
||||
{
|
||||
currentState.input.verificationPosition = currentState.actor.position;
|
||||
currentState.input.verificationVelocity = currentState.actor.velocity;
|
||||
currentState.input.verificationViewAngles = currentState.actor.viewAngles;
|
||||
currentState.input.verificationOrientation = currentState.actor.orientation;
|
||||
|
||||
currentState.input.frame = frame;
|
||||
buffer.Add(currentState.input);
|
||||
}
|
||||
currentState.input.frame = frame;
|
||||
buffer.Add(currentState.input);
|
||||
}
|
||||
|
||||
// Reset anything accumulatable here
|
||||
currentState.input.viewDeltaX = 0;
|
||||
currentState.input.viewDeltaY = 0;
|
||||
// Reset anything accumulatable here
|
||||
currentState.input.viewDeltaX = 0;
|
||||
currentState.input.viewDeltaY = 0;
|
||||
|
||||
frame++;
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
|
||||
public override void RecordCurrentActorState(PlayerActorState actorState)
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
public override void RecordCurrentActorState(PlayerActorState actorState)
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
|
||||
if (actorState.position.Length <= 0.01)
|
||||
Console.Print("wrong recorded position?");
|
||||
currentState.actor = actorState;
|
||||
}
|
||||
if (actorState.position.Length <= 0.01)
|
||||
Console.Print("wrong recorded position?");
|
||||
currentState.actor = actorState;
|
||||
}
|
||||
|
||||
public void FlushDemo()
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
public void FlushDemo()
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
|
||||
byte[] RawSerialize(object anything)
|
||||
{
|
||||
int rawSize = Marshal.SizeOf(anything);
|
||||
IntPtr buffer = Marshal.AllocHGlobal(rawSize);
|
||||
Marshal.StructureToPtr(anything, buffer, false);
|
||||
byte[] rawDatas = new byte[rawSize];
|
||||
Marshal.Copy(buffer, rawDatas, 0, rawSize);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
return rawDatas;
|
||||
}
|
||||
byte[] RawSerialize(object anything)
|
||||
{
|
||||
int rawSize = Marshal.SizeOf(anything);
|
||||
IntPtr buffer = Marshal.AllocHGlobal(rawSize);
|
||||
Marshal.StructureToPtr(anything, buffer, false);
|
||||
byte[] rawDatas = new byte[rawSize];
|
||||
Marshal.Copy(buffer, rawDatas, 0, rawSize);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
return rawDatas;
|
||||
}
|
||||
|
||||
foreach (var state in buffer)
|
||||
{
|
||||
var bytes = RawSerialize(state);
|
||||
demoFileStream.Write(bytes, 0, bytes.Length * sizeof(byte));
|
||||
}
|
||||
foreach (PlayerInputState state in buffer)
|
||||
{
|
||||
byte[] bytes = RawSerialize(state);
|
||||
demoFileStream.Write(bytes, 0, bytes.Length * sizeof(byte));
|
||||
}
|
||||
|
||||
buffer.Clear();
|
||||
}
|
||||
buffer.Clear();
|
||||
}
|
||||
|
||||
public void StopRecording()
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
public void StopRecording()
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
|
||||
FlushDemo();
|
||||
demoFileStream.Close();
|
||||
demoFileStream = null;
|
||||
FlushDemo();
|
||||
demoFileStream.Close();
|
||||
demoFileStream = null;
|
||||
|
||||
Debug.Write(LogType.Info, "demo, wrote states: " + buffer.Count);
|
||||
}
|
||||
}
|
||||
Debug.Write(LogType.Info, "demo, wrote states: " + buffer.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace Game
|
||||
namespace Game
|
||||
{
|
||||
public class PlayerInputNetwork : PlayerInput
|
||||
{
|
||||
|
||||
}
|
||||
public class PlayerInputNetwork : PlayerInput
|
||||
{
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user