Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small headsup #80

Open
spheenik opened this issue Nov 23, 2023 · 4 comments
Open

Small headsup #80

spheenik opened this issue Nov 23, 2023 · 4 comments

Comments

@spheenik
Copy link

Hi,
whenever a new Source 1/2 replay parser comes out, I read their code to find out how they did stuff.
Especially some comments in the send table parsing code made me smile.
Tough stuff, I know.
I think my codebase (https://github.com/skadistats/clarity) has a quite nice implementation, so, if you missed it before, feel free to have a look.
Good work anyway! Keep it on!

@LaihoE
Copy link
Owner

LaihoE commented Nov 24, 2023

Hey,

Yeah I've been checking your parser every now and then to see if you are done with CS2. Nice to see that you got it working!
I originally picked manta due to me being more familiar with GO, but looking back, I'm not so sure it was the correct choice.

I especially like this function 🤯

public Field getFieldForFieldPath(S2FieldPath fp) {
            switch (fp.last()) {
            case 0: return field.getChild(fp.get(0));
            case 1: return field.getChild(fp.get(0)).getChild(fp.get(1));
            case 2: return field.getChild(fp.get(0)).getChild(fp.get(1)).getChild(fp.get(2));
            case 3: return field.getChild(fp.get(0)).getChild(fp.get(1)).getChild(fp.get(2)).getChild(fp.get(3));
            case 4: return field.getChild(fp.get(0)).getChild(fp.get(1)).getChild(fp.get(2)).getChild(fp.get(3)).getChild(fp.get(4));
            case 5: return field.getChild(fp.get(0)).getChild(fp.get(1)).getChild(fp.get(2)).getChild(fp.get(3)).getChild(fp.get(4)).getChild(fp.get(5));
            case 6: return field.getChild(fp.get(0)).getChild(fp.get(1)).getChild(fp.get(2)).getChild(fp.get(3)).getChild(fp.get(4)).getChild(fp.get(5)).getChild(fp.get(6));
            default: throw new UnsupportedOperationException();
        }
    }

This is actually very interesting, because I thought this idea wasn't possible as I thought that I'm forced to to branching down the line but seems like its just due to how my fields/traversing is set up.

I kind of gave up understanding the sendtable/serializer/field logic at some point but this gave me new hope. I'll definitely take a deeper look at how you made it, as I cringe every time I have to deal with the current code.

@spheenik
Copy link
Author

The function you mention is my try to implement this the fastest way possible.

There is a class Field:
https://github.com/skadistats/clarity/blob/master/src/main/java/skadistats/clarity/io/s2/Field.java
Implementations:
https://github.com/skadistats/clarity/tree/master/src/main/java/skadistats/clarity/io/s2/field

The code that converts the sendtables into a nested structure of fields is here
https://github.com/skadistats/clarity/blob/master/src/main/java/skadistats/clarity/processor/sendtables/FieldGenerator.java

The code went through several revisions since Dota Source 2 first came out in 2017 (iirc), and it is hack free (apart from one single one I put in for CS2).

@LaihoE
Copy link
Owner

LaihoE commented Nov 26, 2023

After some poking around, I would like to implement "fields" the way you did it if you don't mind (of course with a mention where the idea came from). The implementation is sooo much more understandable.

@spheenik
Copy link
Author

I don't mind at all!
Good luck, and if you have questions, don't hesitate to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants