BSD: Add support (#140)

* BSD: Add support

* BSD: other fixes

There is still a bug when vgui haven't got text, maybe because of resources.

Also there is bug where when trying to start new game caption names shows wrong.

* BSD: Debugging

* BSD: modify preprocessor and fix windows

* BSD: Remove debugging and fix labels in gameui

* BSD: Remove disabling some DX9 commands

* BSD: Remove -g flag
This commit is contained in:
Er2
2022-11-24 22:04:29 +03:00
committed by GitHub
parent 807eaae850
commit 53bd92f7a8
49 changed files with 221 additions and 178 deletions

View File

@@ -11,6 +11,11 @@
#include <linux/sysctl.h>
#else
#include <sys/sysctl.h>
# ifdef __APPLE__
# define CPUFREQ_SYSCTL "hw.cpufrequency_max"
# else
# define CPUFREQ_SYSCTL "dev.cpu.0.freq"
# endif
#endif
#include <sys/time.h>
#include <unistd.h>
@@ -46,18 +51,15 @@ static inline uint64 diff(uint64 v1, uint64 v2)
return -d;
}
#ifdef OSX
#if defined(OSX) || defined(BSD)
// Mac
// Mac or BSD
uint64 GetCPUFreqFromPROC()
{
int mib[2] = {CTL_HW, HW_CPU_FREQ};
uint64 frequency = 0;
size_t len = sizeof(frequency);
if (sysctl(mib, 2, &frequency, &len, NULL, 0) == -1)
return 0;
return frequency;
uint64 freq_hz = 0;
size_t freq_size = sizeof(freq_hz);
int retval = sysctlbyname(CPUFREQ_SYSCTL, &freq_hz, &freq_size, NULL, 0);
return freq_hz;
}
#else
@@ -99,14 +101,8 @@ uint64 GetCPUFreqFromPROC()
uint64 CalculateCPUFreq()
{
#ifdef __APPLE__
uint64 freq_hz = 0;
size_t freq_size = sizeof(freq_hz);
int retval = sysctlbyname("hw.cpufrequency_max", &freq_hz, &freq_size, NULL, 0);
// MoeMod : TODO dont know how to get freq on Apple Silicon
if(!freq_hz)
freq_hz = 3200000000;
return freq_hz;
#if defined(__APPLE__) || defined(BSD)
return GetCPUFreqFromPROC();
#else
// Try to open cpuinfo_max_freq. If the kernel was built with cpu scaling support disabled, this will fail.
FILE *fp = fopen( "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r" );
@@ -127,9 +123,9 @@ uint64 CalculateCPUFreq()
return retVal * 1000;
}
}
#endif
#if !defined(__arm__) && !defined(__aarch64__)
// fallback mechanism to calculate when failed
// Compute the period. Loop until we get 3 consecutive periods that
// are the same to within a small error. The error is chosen
// to be +/- 0.02% on a P-200.
@@ -179,7 +175,10 @@ uint64 CalculateCPUFreq()
}
return period;
#endif
#else
// ARM hard-coded frequency
return (uint64)2000000000;
#endif // if !ARM
#endif // if APPLE
}