Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/openw3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
wwdebug
wwbitpack
wwtranslatedb
wwlib
shell: bash

steps:
Expand Down
13 changes: 9 additions & 4 deletions Code/wwlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(WWLIB_SRC
mixfile.cpp
mpmath.cpp
mpu.cpp
msgloop.cpp
multilist.cpp
mutex.cpp
nstrdup.cpp
Expand All @@ -39,7 +38,6 @@ set(WWLIB_SRC
readline.cpp
realcrc.cpp
refcount.cpp
registry.cpp
rndstrng.cpp
slnode.cpp
straw.cpp
Expand All @@ -53,7 +51,6 @@ set(WWLIB_SRC
verchk.cpp
widestring.cpp
win.cpp
WWCOMUtil.cpp
wwfile.cpp
wwstring.cpp
xpipe.cpp
Expand Down Expand Up @@ -139,7 +136,6 @@ set(WWLIB_SRC
verchk.h
widestring.h
win.h
WWCOMUtil.h
wwdialog.cpp
wwdialog.h
wwfile.h
Expand All @@ -149,6 +145,15 @@ set(WWLIB_SRC
xstraw.h
)

if(WIN32)
list(APPEND WWLIB_SRC
registry.cpp
msgloop.cpp
)
else()
list(APPEND WWLIB_SRC registry_linux.cpp)
endif()

if(TARGET ffmpeg)
list(APPEND WWLIB_SRC FFmpegFile.cpp FFmpegFile.h)
endif()
Expand Down
57 changes: 57 additions & 0 deletions Code/wwlib/always.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,63 @@ __forceinline unsigned int _byteswap_ulong(unsigned int value)
#ifndef _alloca
#define _alloca(size) alloca(size)
#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?

#endif

// 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.

#endif

// Windows path constant equivalents
#ifndef _MAX_DRIVE
#define _MAX_DRIVE 3
#endif
#ifndef _MAX_DIR
#define _MAX_DIR 260
#endif
#ifndef _MAX_PATH
#define _MAX_PATH 260
#endif
#ifndef _MAX_FNAME
#define _MAX_FNAME 256
#endif
#ifndef _MAX_EXT
#define _MAX_EXT 256
#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)

{
if (drive) drive[0] = '\0'; // no drive letters on Linux
const char *last_slash = strrchr(path, '/');
const char *name_start = last_slash ? last_slash + 1 : path;
const char *last_dot = strrchr(name_start, '.');
if (dir) {
if (last_slash) {
size_t n = (size_t)(last_slash - path) + 1;
std::memcpy(dir, path, n);
dir[n] = '\0';
} else {
dir[0] = '\0';
}
}
if (fname) {
size_t n = last_dot ? (size_t)(last_dot - name_start) : std::strlen(name_start);
std::memcpy(fname, name_start, n);
fname[n] = '\0';
}
if (ext) {
if (last_dot) {
std::strcpy(ext, last_dot);
} else {
ext[0] = '\0';
}
}
}

#endif // !_WIN32

#endif
52 changes: 49 additions & 3 deletions Code/wwlib/cpudetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@
#include "wwdebug.h"
#include "thread.h"
#include "mpu.h"
#if defined(_WIN32)
#include <windows.h>
#else
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <stdio.h>
// Stub out Windows OS version platform IDs; Linux Init_OS sets OSVersionPlatformId=3
// so all switch statements on OSVersionPlatformId fall through to the default case.
#define VER_PLATFORM_WIN32s 0
#define VER_PLATFORM_WIN32_WINDOWS 1
#define VER_PLATFORM_WIN32_NT 2
#endif
#include "systimer.h"

#if CPU_X86 || CPU_X86_64
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <x86intrin.h>
#include <cpuid.h>
#endif
#endif

#if CPU_X86 || CPU_X86_64
Expand Down Expand Up @@ -890,6 +906,7 @@ void CPUDetectClass::Init_Processor_Features()

void CPUDetectClass::Init_Memory()
{
#if defined(_WIN32)
MEMORYSTATUS mem;
GlobalMemoryStatus(&mem);
TotalPhysicalMemory=mem.dwTotalPhys;
Expand All @@ -898,10 +915,22 @@ void CPUDetectClass::Init_Memory()
AvailablePageMemory=mem.dwAvailPageFile;
TotalVirtualMemory=mem.dwTotalVirtual;
AvailableVirtualMemory=mem.dwAvailVirtual;
#else
struct sysinfo si = {};
if (sysinfo(&si) == 0) {
TotalPhysicalMemory = (unsigned)(si.totalram * si.mem_unit);
AvailablePhysicalMemory = (unsigned)(si.freeram * si.mem_unit);
TotalPageMemory = (unsigned)(si.totalswap * si.mem_unit);
AvailablePageMemory = (unsigned)(si.freeswap * si.mem_unit);
TotalVirtualMemory = (unsigned)((si.totalram + si.totalswap) * si.mem_unit);
AvailableVirtualMemory = (unsigned)((si.freeram + si.freeswap) * si.mem_unit);
}
#endif
}

void CPUDetectClass::Init_OS()
{
#if defined(_WIN32)
// GetVersionEx only returns the version of Windows it was manifested for since Windows 8.
// RtlGetVersion returns the correct information at least at the time of writing.
typedef LONG(WINAPI * RtlGetVersionFuncPtr)(PRTL_OSVERSIONINFOW);
Expand All @@ -927,6 +956,17 @@ void CPUDetectClass::Init_OS()
OSVersionBuildNumber = 0;
OSVersionPlatformId = 2;
OSVersionExtraInfo = "";
#else
struct utsname uts = {};
if (uname(&uts) == 0) {
OSVersionExtraInfo = uts.release;
sscanf(uts.release, "%u.%u.%u",
&OSVersionNumberMajor,
&OSVersionNumberMinor,
&OSVersionBuildNumber);
}
OSVersionPlatformId = 3; // No Windows platform match; switches fall to default
#endif
}

bool CPUDetectClass::CPUID(
Expand All @@ -940,17 +980,19 @@ bool CPUDetectClass::CPUID(
if (!Has_CPUID_Instruction()) {
return false; // Most processors since 486 have CPUID...
}
#if defined(_MSC_VER)
int cpuInfo[4];
__cpuid(cpuInfo, cpuid_type);

u_eax_=cpuInfo[0];
u_ebx_=cpuInfo[1];
u_ecx_=cpuInfo[2];
u_edx_=cpuInfo[3];

#else
__cpuid(cpuid_type, u_eax_, u_ebx_, u_ecx_, u_edx_);
#endif
return true;
#else
return false
return false;
#endif
}

Expand Down Expand Up @@ -1059,9 +1101,13 @@ void CPUDetectClass::Init_Compact_Log()
{
StringClass work(0,true);

#if defined(_WIN32)
TIME_ZONE_INFORMATION time_zone;
GetTimeZoneInformation(&time_zone);
COMPACTLOG(("%d\t",time_zone.Bias));
#else
COMPACTLOG(("0\t"));
#endif

OSInfoStruct os_info;
Get_OS_Info(os_info,OSVersionPlatformId,OSVersionNumberMajor,OSVersionNumberMinor,OSVersionBuildNumber);
Expand Down
83 changes: 0 additions & 83 deletions Code/wwlib/critsection.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions Code/wwlib/critsection.h

This file was deleted.

Loading
Loading