Added update logic, patch and engine fixes

This commit is contained in:
Norbi Peti 2019-12-01 03:39:31 +01:00
parent 425e3247d3
commit 04233dffa0
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 54 additions and 15 deletions

View file

@ -1,9 +1,11 @@
using System;
using System.Reflection;
using Gamecraft.Blocks.ConsoleBlock;
using Harmony;
using RobocraftX;
using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer;
using RobocraftX.StateSync;
using Svelto.Context;
using Svelto.ECS;
using Unity.Entities;
@ -14,18 +16,24 @@ namespace GCDC
[HarmonyPatch]
public class DiscordEngineInjectionPatch
{
static void Postfix(UnityContext<FullGameCompositionRoot> contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
static void Postfix(EnginesRoot enginesRoot, ref StateSyncRegistrationHelper stateSyncReg, bool isAuthoritative)
{
enginesRoot.AddEngine(new TextBlockUpdateEngine());
Debug.Log($"Added text block update engine");
if (isAuthoritative)
{
stateSyncReg.AddEngine(new TextBlockUpdateEngine());
Debug.Log($"Added Discord text block update engine");
}
else
Debug.Log("Not authoritative, not adding Discord engine");
}
static MethodBase TargetMethod(HarmonyInstance instance)
{
return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<UnityContext<FullGameCompositionRoot>>);
return _ComposeMethodInfo(ConsoleBlockCompositionRoot.Compose);
}
private static MethodInfo _ComposeMethodInfo(Action<UnityContext<FullGameCompositionRoot>, EnginesRoot, World, Action, MultiplayerInitParameters> a)
private delegate void ComposeAction(EnginesRoot er, ref StateSyncRegistrationHelper ssrh, bool isAuthoritative);
private static MethodInfo _ComposeMethodInfo(ComposeAction a)
{
return a.Method;
}

View file

@ -1,4 +1,7 @@
using IllusionPlugin;
using System.Reflection;
using Harmony;
using IllusionPlugin;
using UnityEngine;
namespace GCDC
{
@ -6,35 +9,39 @@ namespace GCDC
{
public string Name { get; } = "GCDC";
public string Version { get; } = "v0.0.1";
public static HarmonyInstance harmony { get; protected set; }
public const string HarmonyID = "io.github.norbipeti.GCDC";
public void OnApplicationStart()
{
throw new System.NotImplementedException();
if (harmony == null)
{
harmony = HarmonyInstance.Create(HarmonyID);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
Debug.Log("GCDC loaded");
}
public void OnApplicationQuit()
{
throw new System.NotImplementedException();
harmony?.UnpatchAll(HarmonyID);
}
public void OnLevelWasLoaded(int level)
{
throw new System.NotImplementedException();
}
public void OnLevelWasInitialized(int level)
{
throw new System.NotImplementedException();
}
public void OnUpdate()
{
throw new System.NotImplementedException();
}
public void OnFixedUpdate()
{
throw new System.NotImplementedException();
}
}
}

View file

@ -1,7 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using RobocraftX.Blocks.GUI;
using RobocraftX.Common;
using RobocraftX.Common.Input;
using RobocraftX.Common.Utilities;
using RobocraftX.SimulationModeState;
using RobocraftX.StateSync;
using Svelto.ECS;
using Svelto.ECS.Experimental;
using Unity.Jobs;
using uREPL;
@ -14,12 +20,30 @@ namespace GCDC
}
public IEntitiesDB entitiesDB { get; set; }
public JobHandle SimulatePhysicsStep(in float deltaTime, in PhysicsUtility utility, in PlayerInput[] playerInputs)
public string name { get; } = "GCDC-TextUpdate";
private volatile Queue<string> messages = new Queue<string>();
private volatile bool updatedTextBlock;
public JobHandle SimulatePhysicsStep(
in float deltaTime,
in PhysicsUtility utility,
in PlayerInput[] playerInputs) //Gamecraft.Blocks.ConsoleBlock.dll
{
//TODO
if (updatedTextBlock)
return new JobHandle();
var txt = messages.Count > 0 ? messages.Aggregate((current, msg) => current + "\n" + msg) : "<No messages yet>";
RuntimeCommands.Call("ChangeTextBlockCommand", "Discord", txt);
updatedTextBlock = true;
return new JobHandle();
}
public string name { get; } = "GCDC-TextUpdate";
public void AddMessage(string message)
{
messages.Enqueue(message);
if (messages.Count > 10)
messages.Dequeue();
updatedTextBlock = false;
}
}
}