mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-21 16:07:26 -05:00
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer. Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis. Performance has also been slightly improved; no allocation is done anymore when updating the image.
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace NHSE.Core;
|
|
|
|
/// <summary>
|
|
/// Utility logic for dealing with bitflags in a byte array.
|
|
/// </summary>
|
|
public static class FlagUtil
|
|
{
|
|
public static bool GetFlag(ReadOnlySpan<byte> arr, int offset, int bitIndex)
|
|
{
|
|
var b = arr[offset + (bitIndex >> 3)];
|
|
var mask = 1 << (bitIndex & 7);
|
|
return (b & mask) != 0;
|
|
}
|
|
|
|
public static void SetFlag(Span<byte> arr, int offset, int bitIndex, bool value)
|
|
{
|
|
offset += (bitIndex >> 3);
|
|
bitIndex &= 7; // ensure bit access is 0-7
|
|
arr[offset] &= (byte)~(1 << bitIndex);
|
|
arr[offset] |= (byte)((value ? 1 : 0) << bitIndex);
|
|
}
|
|
|
|
public static bool GetFlag(ReadOnlySpan<byte> arr, int bitIndex)
|
|
{
|
|
var b = arr[bitIndex >> 3];
|
|
var mask = 1 << (bitIndex & 7);
|
|
return (b & mask) != 0;
|
|
}
|
|
|
|
public static void SetFlag(Span<byte> arr, int bitIndex, bool value)
|
|
{
|
|
var offset = bitIndex >> 3;
|
|
bitIndex &= 7; // ensure bit access is 0-7
|
|
arr[offset] &= (byte)~(1 << bitIndex);
|
|
arr[offset] |= (byte)((value ? 1 : 0) << bitIndex);
|
|
}
|
|
} |