Skip to content

Instantly share code, notes, and snippets.

View HeatXD's full-sized avatar
💭
:)

Jamie Meyer HeatXD

💭
:)
View GitHub Profile
@HeatXD
HeatXD / godot_ggrs.rs
Created January 14, 2023 15:30
godot 4 -> ggrs
use ggrs::{Config, GGRSError, P2PSession, PlayerType, SessionBuilder, UdpNonBlockingSocket, GameStateCell};
use godot::prelude::*;
use std::{
collections::{HashMap, VecDeque},
net::SocketAddr,
};
pub struct GGRSConfig;
impl Config for GGRSConfig {
type Input = i32;
@HeatXD
HeatXD / RunLengthEncoding.cs
Created September 4, 2022 00:02
RunLengthEncoding C#
private static List<byte> RLEEncode(List<byte> toEncode)
{
var bytes = new List<byte>();
byte count = 1;
byte current = toEncode[0];
for (int i = 0; i < toEncode.Count; i++)
{
if (current == toEncode[i] && count != byte.MaxValue)
{
@HeatXD
HeatXD / FletcherChecksum.cs
Created November 26, 2021 17:15
Fletcher Checksum C#
using System;
using System.Collections.Generic;
using System.Text;
public class FletcherChecksum
{
/// <summary>
/// Transforms byte array into an enumeration of blocks of 'blockSize' bytes
/// </summary>
/// <param name="inputAsBytes"></param>
Readme: In the following pseudo code, [] indicates a subroutine.
Sometimes I choose to write the subroutine inline under the [] in order to maintain context.
One important fact about the way rollbacks are handled here is that we are storing state for every frame.
In any real implementation you only need to store one game state at a time. Storing a game
state for every frame allows us to only rollback to the first frame where the predicted inputs don't match the true ones.
==Constants==
MAX_ROLLBACK_FRAMES := Any Positive Integer # Specifies the maximum number of frames that can be resimulated
FRAME_ADVANTAGE_LIMIT := Any Positive Integer # Specifies the number of frames the local client can progress ahead of the remote client before time synchronizing.