-
Notifications
You must be signed in to change notification settings - Fork 66
[GEN][ZH] Add endian compat for BIGFileSystems #798
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
Conversation
GeneralsMD/Code/GameEngineDevice/Source/StdDevice/Common/StdBIGFileSystem.cpp
Outdated
Show resolved
Hide resolved
Updated with a more fleshed out endian handling compatability header. |
GeneralsMD/Code/GameEngineDevice/Source/StdDevice/Common/StdBIGFileSystem.cpp
Show resolved
Hide resolved
3a98c64
to
de0f8f7
Compare
Updated, Rebased off main and merge conflict fixed. Tweaked with discussed changes and added endian compat functions to win32Bigfilesystems for generals and zero hour along with stdbigfilesystem. Should be good to go now. |
VC6 does not like the variadic macro. Then we need to do |
Yeah i just noticed this, was just about to change it, should be up in a few seconds. |
8759381
to
615da66
Compare
Now it doesn't like long long, this is taking a long long time. i should really sort my local VC6 build environment lol. |
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.
Looks good.
It would seem that VC6 doesn't like the helper templates EDIT: Figured it out, VC6 doesn't support EDIT2: Nvm wasn't that... |
8fe7c1e
to
497f7af
Compare
It is using what is called "partial template class specialization". Perhaps VC6 does not support that? Chat Gippity says No, Visual C++ 6.0 (VC6) does not support partial template class specialization. While VC6 does support full class template specialization, it lacks support for partial specialization, which was not fully implemented in Microsoft's compiler until later versions (Visual Studio .NET 2003 and later improved this significantly). Example of what VC6 does not support:// This is partial specialization — not supported in VC6
template <typename T, typename U>
class MyClass {};
template <typename T>
class MyClass<T, int> {
// ...
}; What VC6 does support:// This is full specialization — supported in VC6
template <typename T, typename U>
class MyClass {};
template <>
class MyClass<int, float> {
// ...
}; If you need to simulate partial specialization in VC6, you can sometimes use traits classes or template overloading with helper structs, but it's usually a bit hacky. Here’s a workaround for partial class template specialization in Visual C++ 6.0 (VC6) using helper structs and full specialization, which VC6 does support. 🎯 Goal:Simulate this partial specialization (which VC6 does not support): template <typename T, typename U>
class MyClass;
template <typename T>
class MyClass<T, int> {
// specialized for second type being int
}; ✅ Workaround using helper class:// Primary implementation — not specialized
template <typename T, typename U>
struct MyClassImpl {
static void doSomething() {
// Generic implementation
std::cout << "Generic MyClassImpl<T, U>\n";
}
};
// Full specialization of helper for U = int
template <typename T>
struct MyClassImpl<T, int> {
static void doSomething() {
std::cout << "Specialized MyClassImpl<T, int>\n";
}
};
// Wrapper class
template <typename T, typename U>
class MyClass {
public:
void doSomething() {
MyClassImpl<T, U>::doSomething();
}
}; 🔧 Usage:#include <iostream>
int main() {
MyClass<double, float> a;
MyClass<char, int> b;
a.doSomething(); // Prints: Generic MyClassImpl<T, U>
b.doSomething(); // Prints: Specialized MyClassImpl<T, int>
return 0;
} 💡 Summary:
Do you want a version of this that works with older C++ features only (e.g. no |
I have not used it before myself, just looking it up, but It's possibly not working due to a defect in the C++ 98 standard. |
Will have a go at this again tomorrow. |
The Ai generated workaround looks strange however. // Full specialization of helper for U = int
template <typename T>
struct MyClassImpl<T, int> { It describes this as full specialization, but it still looks like partial. I expect this does not work. |
I was thinking that we might have to just do #if defined(_msc_ver) && _msc_ver < 1300
Littlefiles = ntohl(Littlefiles)
#else
Littlefiles = betoh(Littlefiles)
#endif In the win32 big file system then conditionally gate the endian compat to include winsock2 for vc6 and hide all the template code. |
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 think we can do it simpler by creating inline functions. This should be sufficient for non-enum types.
inline uint16_t betoh(uint16_t x) ...
inline uint32_t betoh(uint32_t x) ...
Letting you know that Linux & macOS both have |
Hopefully this is the one lol. Checked the byte swap macros by having them get compiled in VS22 and they worked fine. |
Tested the VC6 builds and they work as expected. |
Refactored taking the suggestions into account. |
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.
Looks good.
Pushed with tweaks to the comments, should be good now. |
This was quite the journey :P |
Always learning something along the way. |
This PR is a prerequisit to a PR to unify AsciiString, it adds endian compatibility functions within an endian_compat header.
These are then used in the BIGFileSystems as they previously reloed on the networking ntohl function.
For StdBIGFileSystem this was being indirectly provided through the windows header in AsciiString. And directly included in win32BigFileSystem through winsock2.
This change is necessary to provide cross compat byte swapping functionality.