GithubHelp home page GithubHelp logo

Comments (7)

Carbone13 avatar Carbone13 commented on July 20, 2024

Thanks for pointing this out. I also discovered that the GD.Hash(dictionary) was not the same as dictionary.hash(), therefore the way I compared the dictionary was wrong

from godot-rollback-cs.

Carbone13 avatar Carbone13 commented on July 20, 2024

More investigation is needed, I think some bugs remains
Once I implement a cleaner way to serialize, send & parse inputs, bugs may vanish

from godot-rollback-cs.

FireBrandMint avatar FireBrandMint commented on July 20, 2024

More investigation is needed, I think some bugs remains
Once I implement a cleaner way to serialize, send & parse inputs, bugs may vanish

Hey, i made a class for this, if you are unable to solve this problem with the godot dictionary.

using Godot;
using System;
using System.Text;
using System.Collections.Generic;

public class InputsDict
{
    public Dictionary<int, string> inpDict = new Dictionary<int, string>();

    public string this[int key]
    {
        get=>inpDict[key.GetHashCode()];
        set=>inpDict.Add(key, value);
    }

    public bool ContainsKey (int key) => inpDict.ContainsKey(key);

    public Dictionary<int, string> GetRootDictionary () => inpDict;

    public byte[] Serialize ()
    {
        var bytes = new List<byte>();

        bytes.AddRange(BitConverter.GetBytes((Int32) inpDict.Count));

        foreach (var entry in inpDict)
        {
            bytes.AddRange(BitConverter.GetBytes((Int32) entry.Key));
            byte[] strEncoded = Encoding.ASCII.GetBytes(entry.Value);
            bytes.AddRange(BitConverter.GetBytes((Int32) strEncoded.Length));
            bytes.AddRange(strEncoded);
        }
        return bytes.ToArray();
    }

    public static InputsDict Deserialize (byte[] data)
    {
        var toReturn = new InputsDict();
        int CurrByte = 0;
        
        int elementAmount = BitConverter.ToInt32(data, CurrByte);
        CurrByte+=4;

        for (int i = 0; i<elementAmount; ++i)
        {
            int key = BitConverter.ToInt32(data, CurrByte);
            CurrByte+=4;

            int valueLenght = BitConverter.ToInt32(data, CurrByte);
            CurrByte+=4;

            string value = Encoding.ASCII.GetString(data, CurrByte, valueLenght);
            CurrByte+= valueLenght;

            toReturn[key] = value;
        }

        return toReturn;
    }
}

from godot-rollback-cs.

Carbone13 avatar Carbone13 commented on July 20, 2024

Nice, last commit implement this, I created 2 additional class to prepare for the migration. I'm going on vacation tomorrow for one week so I will not be able to work on it soon. Feel free to do so, I'll accept PR

from godot-rollback-cs.

FireBrandMint avatar FireBrandMint commented on July 20, 2024

Have a good vacation then, maybe i will get around installing github on vscode to try.

EDIT: i did it, but oh god it was hard.

from godot-rollback-cs.

FireBrandMint avatar FireBrandMint commented on July 20, 2024

This issue will be fixed with my pull request, if anyone else is reading this just download my fork of this repo because the problem is already solved there.

from godot-rollback-cs.

Carbone13 avatar Carbone13 commented on July 20, 2024

Should be pushed to the master branch around Monday 👍

from godot-rollback-cs.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.