Skip to content

build wwlib on linux - #145

Open
rm5248 wants to merge 6 commits into
w3dhub:mainfrom
rm5248:build-wwlib-linux
Open

build wwlib on linux#145
rm5248 wants to merge 6 commits into
w3dhub:mainfrom
rm5248:build-wwlib-linux

Conversation

@rm5248

@rm5248 rm5248 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Build wwlib on Linux.

Mostly Claude generated, but I did clean it up slightly to better align with OpenW3D.

Comment on lines +18 to +25

/*
** Linux implementation of RegistryClass backed by an INI file.
** Persists settings to $HOME/.config/renegade/registry.ini.
*/

#if !defined(_WIN32)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wwlib/openw3d.h writes its settings to openw3d.ini.
Perhaps the OpenW3D:: functions should be moved into RegistryClass and RegistryClass should write its settings to openw3d.ini in an appropriate location instead?

Also, I think we want to remove the dependency on the registry on Windows as well.

@OmniBlade OmniBlade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things I'd personally prefer to be done in alternate ways. Not sure if others agree.

Comment thread Code/wwlib/always.h
#endif

#ifndef OutputDebugStringA
#define OutputDebugStringA(s) ((void)(s))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more inclined to remove these and replace with either WWDEBUG_SAY or pure printf. Generally I want to remove always.h and refactor into separate headers for the things its needed for.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reasonable to ask, but this is currently used many places in the code. I think that would make sense as a different PR?

Comment thread Code/wwlib/always.h

// Windows BOOL type
#ifndef BOOL
typedef int BOOL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just replace use of BOOL with int and be done with it, as winapi is removed this shouldn't be needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the OutputDebugString, a cursory glance indicates that there are 400+ files with a BOOL declared in them at some point, so removing it at the moment doesn't seem feasible.

Comment thread Code/wwlib/always.h Outdated

// Windows file operation equivalents
#ifndef DeleteFileA
#define DeleteFileA(f) (remove(f) == 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just replace calls to DeleteFile and MoveFile with calls to remove and rename which are supported by posix and msvc.

Comment thread Code/wwlib/always.h
#endif

// _splitpath: split a path into drive/dir/fname/ext components
static inline void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this function be moved to its own header along with the constants it uses and only included where needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be replaced with std::filesystem functions. It's currently used in a lot of places, so standardizing it does make sense(but probably as a separate PR)

Comment thread Code/wwlib/critsection.h Outdated
#if defined(_WIN32)
CRITICAL_SECTION Bar;
#else
std::mutex Bar;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::mutex is supported everywhere as our base C++ version is 20, maybe just convert to use that exclusively? Also, where is the corresponding cpp implementation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove this class, but this at least gets it into a state where it can compile. The cpp implementation was not changed, but I will go update that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually upon further investigation the h/cpp files are not used in the build at all.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, the same class with a slightly different implementation is implemented in mutex.h/cpp, can probably just remove this entirely then?

Comment thread Code/wwlib/mixfile.cpp Outdated
//
::DeleteFileA (MixFilename);
::MoveFileA (full_path, MixFilename);
DeleteFileA (MixFilename);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment on dealing with these.

Comment thread Code/wwlib/mixfile.cpp
/*
**
*/
#if defined(_WIN32)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs a std::filesystem, SDL3 or dirent alternative implementation here though that can be TODO.

Comment thread Code/wwlib/refcount.cpp Outdated


#include "refcount.h"
#if defined(_WIN32)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the windows header needed at all if its not needed on posix?


#if !defined(_WIN32)

#include "registry.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we want to replace the use of this class entirely throughout the codebase, so making a temp implementation seems counter productive. Maybe just stub it out instead if the intention is to just get wwlib compiling on linux to make further development easier.

Comment thread CMakeLists.txt Outdated
add_compile_definitions(strnicmp=strncasecmp)
add_compile_definitions(wcsnicmp=wcsncasecmp)
add_compile_definitions(wcsicmp=wcscasecmp)
add_compile_definitions(DebugBreak=__builtin_trap)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of these defines being added like this, would be better to add a few headers to wrap this kind of thing instead. Like how debug break is handled here: https://github.com/TheAssemblyArmada/Thyme/blob/ccef1e11c1355c6db577a057c06e7d790f1a0333/deps/baseconfig/src/intrinsics.h#L141

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long-term std::breakpoint would make more sense, but it's only used in 2 places at the moment so I'll simply remove it instead.

@caseychaos1212

Copy link
Copy Markdown
Collaborator

CODEX REVIEW

Findings

  1. P1: Windows webbrowser builds will lose RegisterCOMServer
    [Code/wwlib/CMakeLists.txt#L53](

    ) removes WWCOMUtil.cpp from wwlib, but [WebBrowser.cpp#L100](
    bool success = RegisterCOMServer(dllPath);
    ) still calls RegisterCOMServer, whose only definition is in [WWCOMUtil.cpp#L179](
    bool RegisterCOMServer(const char* dllName)
    ). Since WebBrowser.cpp is still in COMMANDO_SRC, Windows builds with webbrowser enabled should hit an unresolved external. Keep WWCOMUtil.cpp in the Windows source list or move it to the consumer target.

  2. P1: printf(buffer) introduces a format-string bug
    [Code/wwlib/ini.cpp#L2363](

    printf(buffer);
    ) passes INI-derived text as the format string. buffer includes entry, section, and Filename, so % sequences in those values can crash or corrupt memory. Use printf("%s", buffer) or fputs(buffer, stdout).

  3. P2: Linux registry export/import does not round-trip
    [registry_linux.cpp#L223-L232](

    void RegistryClass::Save_Registry_Tree(char *path, INIClass *ini)
    {
    const char *section = path;
    int index = 0;
    const char *entry = NULL;
    char buf[1024];
    while ((entry = Registry_INI().Get_Entry(section, index++)) != NULL) {
    Registry_INI().Get_String(section, entry, "", buf, sizeof(buf));
    ini->Put_String(section, entry, buf);
    }
    ) saves raw entry names, but Load_Registry only imports BIN_, DWORD_, and STRING_ entries. It also only saves/deletes the exact section, unlike the Windows implementation which recurses subkeys and prefixes typed values. Any Save then Load flow, such as slave registry cloning, will silently drop settings on Linux.

Validation

I fetched PR #145 locally and reviewed the full diff. git diff --check is clean. I did not run a Linux build from this Windows workspace.

Comment on lines +41 to +51
static void Ensure_Registry_Dir()
{
const char *home = getenv("HOME");
if (!home) return;
char dir[512];
snprintf(dir, sizeof(dir), "%s/.config", home);
mkdir(dir, 0755);
snprintf(dir, sizeof(dir), "%s/.config/renegade", home);
mkdir(dir, 0755);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the openw3d.ini path as established by #48 and #104.

Comment on lines +54 to +63
static INIClass ini;
static bool loaded = false;
if (!loaded) {
loaded = true;
RawFileClass file(OpenW3D::Get_Config_File_Path());
if (file.Is_Available()) {
ini.Load(file);
}
}
return ini;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This INIClass object will clash with the INIClass object created by the OpenW3D:: functions.

This sequence of actions will cause data loss:

  1. global INIClass object is initialized (through RegistryClass), loads data from disk and stays alive
  2. OpenW3D:: function reads ini
  3. OpenW3D:: function writes ini
  4. RegistryClass method is called: the ini is is not read again

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #48 and #104 should be partially reverted such that:

  • RegistryClass is only served by the ini: the win32 code can be removed. We don't want to access the registry
  • the openw3d.ini path is calculated as master currently does

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

Successfully merging this pull request may close these issues.

4 participants