Support for getting the last turn time.

This commit is contained in:
Deukhoofd 2020-08-30 13:50:19 +02:00
parent ea4c9c6877
commit a90fb3e481
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 24 additions and 7 deletions

View File

@ -57,6 +57,7 @@ namespace PkmnLibSharp.Battling
public ulong SidesCount => Creaturelib.Generated.Battle.GetSidesCount(Ptr);
public ulong PartiesCount => Creaturelib.Generated.Battle.GetPartiesCount(Ptr);
public ulong MonsPerSide => Creaturelib.Generated.Battle.GetCreaturesPerSide(Ptr);
public long LastTurnTimeMicroseconds => Creaturelib.Generated.Battle.GetLastTurnTimeMicroseconds(Ptr);
public ReadOnlyNativePtrArray<BattleSide> Sides
{
@ -105,10 +106,21 @@ namespace PkmnLibSharp.Battling
return b == 1;
}
private readonly List<BaseTurnChoice> _choiceCache = new List<BaseTurnChoice>();
public bool TrySetChoice(BaseTurnChoice turnChoice)
{
byte b = 0;
var initialTurn = CurrentTurn;
_choiceCache.Add(turnChoice);
var t1 = System.Diagnostics.Stopwatch.StartNew();
Creaturelib.Generated.Battle.TrySetChoice(ref b, Ptr, turnChoice.Ptr).Assert();
t1.Stop();
if (b == 1 && CurrentTurn != initialTurn)
{
LogHandler.Log(LogHandler.LogLevel.Information,
$"Ran turn in {t1.ElapsedMilliseconds} ms, battle reported {LastTurnTimeMicroseconds} microseconds");
_choiceCache.Clear();
}
return b == 1;
}

View File

@ -197,5 +197,10 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetHistory")]
internal static extern IntPtr GetHistory(IntPtr p);
/// <param name="p">const Battle *</param>
/// <returns>long int</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetLastTurnTimeMicroseconds")]
internal static extern long GetLastTurnTimeMicroseconds(IntPtr p);
}
}

BIN
PkmnLibSharp/Native/libArbutils.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/libCreatureLib.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

File diff suppressed because one or more lines are too long