This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bitvec::{field::BitField, prelude::*}; | |
use std::{ | |
fs, io, | |
path::{Path, PathBuf}, | |
}; | |
// Limitations: | |
// max sprite sheet size: (256 in either direction) | |
// max number of colors: 4 (for wasm4) | |
// ASSUMES THE FILE HAS BEEN EXPORTED FROM ASEPRITE IN INDEXED MODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specialize spec constants ourselves cause there's no other way to do it (fuck) | |
fn specialize_spec_constants(binary: &mut [u32], constants: &Constants) { | |
// Converts a SpecConstant op code to it's specialized variant (Constant) | |
fn specialize(op_code_index: usize, binary: &mut [u32], defined: SpecConstant) { | |
// Get the op code of the spec constant | |
let op_code = binary[op_code_index] & 0x0000ffff; | |
// Get the index of the spec constant literal | |
let literal_index = match op_code { | |
48 | 49 => op_code_index + 2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Update a value in a specific bitmask, though return the unwritten value first | |
pub fn toggle_bit<T: PrimInt>(bitmask: &mut T, index: usize, value: bool) -> bool { | |
let copy = ((*bitmask >> index) & T::one()) == T::one(); | |
if value { | |
*bitmask = *bitmask | (T::one() << index); | |
} else { | |
*bitmask = *bitmask & (!(T::one() << index)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Unity.Burst; | |
using Unity.Collections; | |
using Unity.Jobs; | |
[BurstCompile(CompileSynchronously = true)] | |
internal struct RleCompressionJob : IJob { | |
[ReadOnly] | |
public NativeArray<byte> bytesIn; | |
[WriteOnly] | |
public NativeList<uint> uintsOut; |