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
Adding support for arbritrary NBT tags #5015
Conversation
Added Conversion for cParsedNBT and cFastNBT
trying to fix unordered map
AAAAAAAAAA - this compiles in MVSC :/ |
{ | ||
using cByteArray = std::vector<char>; // Todo: Make this a Int8 | ||
using cIntArray = std::vector<Int32>; | ||
using cList = std::vector<cNBT>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A list isn't just an array of tags, all the entries need to have the same tag type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cNBT::Push enforces this I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes, BUT you can create a cList object and create a cNBT from this and have a list with various types of entries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried to fix this
Hm. Clang doesn't like the circular behaviour. I'd suggest creating a cCompound class that stores dynamically allocated cNBT objects in a map. Directly using a unordered map works too but then the user has to keep track of the memory leaks. I'd rather use the cCompound to take care of this |
What's the issue with circular things? We shouldn't need any sort of inheritance right? |
We have compounds including cNBT objects And we have cNBT objects containing the variant containing compounds |
It should just work, I think. I.e. with the example in the other PR this compiles: NBT Root{
NBT::Compound{
{ "a", { NBT::List() } },
{ "b", { 5 } }
}
}; |
Of course it depends on undefined behaviour of std::map accepting incomplete types; so we should probably look to storing a std::unique_ptr in an unordered_map for your solution |
ok - i made the variant contain a pointer to |
I think i'm gonna hide some things in the private parts (yeah sorry) of the |
added direct access to compound serialize takes a cNBT
|
float, // TAG_Float | ||
double, // TAG_Double | ||
AString, // TAG_String | ||
cCompound *, // TAG_Compound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a pointer to cNBT
would be better to assure safety even for nested lists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to use a smart pointer but that blows up :/
There was discussion on your forum thread (https://forum.cuberite.org/thread-3325.html), the main outcome was storing a std::variant containing every thing we need (as objects) into cItem, for better type safety and more ergonomic field accesses. If we do that a cNBT class isn't immediately required anymore. |
But how do we access the values in the vector of variants - do we set constant indexes for certain values? Or do we actually map values from string to values? |
We can say |
Didn't know this works on a vector of variant? What is the behaviour if there are multiple values of the same type? |
Oh I see what you mean, we do a linear search and the first variant that matches counts. A map/set is conceptually more appropriate but I'd say is too high overhead for a couple largely fixed values. |
Yeah this makes more sense - there won't be that many entries in the vector so that linear search wont be that slow |
Closed in favour of #5454 |
see #4179
Added Compound and types
Added Conversion for cParsedNBT and cFastNBT