-
Notifications
You must be signed in to change notification settings - Fork 135
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
Upgrade tool projects #138
Comments
Is there any reason for converting all projects to C++? |
It eliminates the need to do It also allows the use of things like Having everything compiled as C++ code is more consistent and produces expected results for all files, whereas now a file could have a It'll also make it possible to use the headers from the game in the tools, currently some headers (e.g. |
…om build/rebuild/clean (project missing 3DS Max SDK) #138
…warnings about older C API functions #138
…pr & strlwr defined on platforms other than Windows only #138
I've done most of the work required for this issue, i just need to fix any remaining warnings that can be fixed, and test the projects to make sure they work as intended. There are 231 warnings and 21 messages when compiling with Visual Studio 2019 concerning local variables shadowing other variables, unused variables, uninitialized variables, signed/unsigned comparison mismatches, pointers that may be null due to malloc returning null when out of memory as well as buffer overflows. Some of these can be fixed (e.g. removing unused locals and not naming unused parameters), others would require changing behavior (e.g. checking for null return from malloc should either be a fatal error or be replaced with new, which throws on allocation failure). I'd say memory allocations should use throwing new everywhere since that simplifies error handling but that should have proper error logging to inform the user of why it failed (at minimum reporting out-of-memory error). If everything works as intended then it should be fine to merge. |
…ve path parameter from SetQdirFromPath #138
…rnings, comment out parameters that aren't used but useful or needed, remove parameters that aren't used at all #138
… load smd files during studiomodel compilation (fixes "input could be null" warnings) #138
…Actual type: 'char [16][256]'" #138
I replaced GLaux and GLUT with SDL2. The purpose of both was to make a window and draw to it using OpenGL, and process user input in mdlviewer's case. That said, GLaux was used by CSG and BSP to draw what the tool in question was doing. VHLT doesn't have this functionality anymore, probably because it was never used and having a GUI-only option on a tool used on the command line adds a dependency that's best left out. I fully re-implemented this feature using SDL2 and OpenGL. qcsg doesn't seem to draw anything, while qbsp2 draws the geometry it's working on. Enabling this feature causes qbsp2 to take about a minute to process c1a0, whereas before it took less than a second. The window created to draw this doesn't update properly and so Windows will treat it as frozen which prevents it from updating its contents, so you'd have to avoid doing anything that can change window focus or otherwise trigger Windows to treat it as frozen. I removed some of the functions in that code because they were never called and they were causing "unreferenced formal parameter" warnings. It would probably be better to remove this stuff altogether from those two tools. mdlviewer is incredibly bare bones compared to even the oldest community-made model viewers, so other than curiosity i doubt anybody will want to use it. If they do, they'll have to grab the SDL2 dll from the game installation and put it next to mdlviewer.exe to run it. The SDL2 changes came from the HLEnhanced repository where i'd already done most of that work. I've fixed as many warnings as i could, most of the remaining warnings are caused by code not checking for null returns by malloc/realloc/kalloc/calloc and passing potential null pointers to other functions like memset. Other warnings involve string operations that aren't secure like using strcpy or scanf, and unsafe array access caused by C-style dynamic array allocations that make arrays with fixed size have a dynamic size at runtime. Most of these warnings can be fixed by using C++-style design: using std::vector to allocate arrays and reallocate instead of using malloc/calloc + realloc, and using std::vector to allocate windings and returning those windings by value instead of allocating the entire object dynamically. Return value optimization and guaranteed copy elision combined with the use of constructors and move operations should eliminate any overhead that would be associated with that kind of refactoring work. Several functions allocate a lot of stack space, many of those are threaded functions so it might be a good idea to use static threadlocal storage for this. Replacing the thread code with std::thread should eliminate several unused parameters that are currently commented out, it should also get rid of warnings related to null thread handles. Those changes should fix all remaining warnings, but that's a bit out of scope. I tested the projects:
The map compile tools (qcsg, qbsp2, vis, qrad) are tied together so i tested them as one. I compiled c1a0 provided with the Half-Life SDK. Geometry-wise the output is the same, but because we don't have the lights.rad file used by Valve the lighting is different. The lighting that is there matches what's in the original version. I also tested the compile tools built as C and C++. Like studiomdl there are slight changes in floating point calculations that change the output. These kind of changes are minor and considering that ZHLT and VHLT are both compiled as C++ i doubt this matters. |
I've formatted all files using the This wraps up work on the tools code, everything aside from smdlexp compiles without requiring additional dependencies. |
The tool projects are Visual Studio 2010 projects and do not compile due to both missing and outdated dependencies and changes made to the game codebase.
Upgrade the projects:
smdlexp
because it requires the Max SDK)Issue #136 should be closed by the work required for this issue.
The text was updated successfully, but these errors were encountered: