GlobalVariableService.cs 738 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. namespace FF8
  4. {
  5. public sealed class GlobalVariableService : IGlobalVariableService
  6. {
  7. public Boolean IsSupported => true;
  8. private readonly Int64[] _values = new Int64[8192];
  9. public T Get<T>(GlobalVariableId<T> id) where T : unmanaged
  10. {
  11. unsafe
  12. {
  13. fixed (Int64* ptr = &_values[id.VariableId])
  14. return *(T*)ptr;
  15. }
  16. }
  17. public void Set<T>(GlobalVariableId<T> id, T value) where T : unmanaged
  18. {
  19. unsafe
  20. {
  21. fixed (Int64* ptr = &_values[id.VariableId])
  22. *(T*)ptr = value;
  23. }
  24. }
  25. }
  26. }