Skip to content

Instantly share code, notes, and snippets.

@CryZe
CryZe / Monotonic.md
Last active June 14, 2023 08:42
Notes on Monotonic Clocks

Notes on Monotonic Clocks

We can't use std's Instant as it's insufficiently specified. It neither guarantees "real time" nor does it guarantee measuring "uptime" (the time the OS has been awake rather than suspended), meaning that you can't actually rely on it in practice. In livesplit-core we definitely want real time rather than uptime. Various operating systems are problematic:

Linux, BSD and other Unixes

Compiled Emblem Information

Drop Rates

  • Bronze: 88%
  • Silver: 10%
  • Gold: 2%

Type Stacking (when you have multiple of the same type)

@CryZe
CryZe / auto-splitter.c
Last active June 11, 2022 12:33
Auto Splitter written in C
#include "asr/asr_helpers.h"
#include "asr/mini_libc.h"
ProcessId process = 0;
Address unity = 0;
uint8_t old_run_active = 0;
uint8_t old_timer_paused = 0;
typedef struct {
@CryZe
CryZe / asr.d.ts
Last active June 2, 2022 18:42
TypeScript Definition file for the new Auto Splitting Runtime
/**
* Sets the tick rate of the runtime. This influences the amount of times the
* `update` function is called per second.
*/
declare function setTickRate(ticksPerSecond: number): void;
/** Prints a log message for debugging purposes. */
declare function printMessage(message: unknown): void;
declare type Address = BigInt;
pub trait PopulateString {
fn populate(self, buf: &mut String);
fn as_str(&self) -> &str;
fn into_string(self) -> String {
let mut buf = String::new();
self.populate(&mut buf);
buf
}
}
@CryZe
CryZe / asl_abstraction.rs
Last active January 9, 2022 18:13
Slight abstraction layer for the new Auto Splitting runtime.
struct Eversleep {
time_info: Watcher<TimeInfo>,
}
impl<'a> AutoSplitter<'a> for Eversleep {
type Data = &'a Pair<TimeInfo>;
fn unhooked(&mut self) {
self.time_info.update(None);
}
@CryZe
CryZe / auto_splitting_api_proposal.rs
Last active January 7, 2022 22:28
Proposal for the MVP of the auto splitting API.
#[repr(transparent)]
pub struct Address(pub u64);
#[repr(transparent)]
pub struct NonZeroAddress(pub NonZeroU64);
#[repr(transparent)]
pub struct ProcessId(NonZeroU64);
#[repr(transparent)]
#![feature(let_else)]
#![no_std]
use core::{fmt, mem};
use bytemuck::{Pod, Zeroable};
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Header {
@CryZe
CryZe / float_max_survey.md
Last active March 24, 2024 21:13
Survey of Floating Point Implementations for Maximum

Survey of Floating Point Implementations for Maximum

Following some IEEE Standard

IEEE Std 754-2008 maxNum (NaN Absorb, 0 implementation defined)

  • C17 fmax
  • Rust f64::max
  • LLVM llvm.maxnum
  • ARM FMAXNM (either mode)
@CryZe
CryZe / LiveSplitOneInUnity.cs
Created April 18, 2021 17:43
LiveSplit One in Unity
using UnityEngine;
using LiveSplitCore;
using System;
using System.IO;
public class LS : MonoBehaviour
{
Timer timer;
Layout layout;
LayoutState layoutState;