1:1 source port of the engine and game code; Windows build and system layer; docs. No game files or SDK headers.

This commit is contained in:
CRTkafa 2026-10-22 16:30:40 +08:00
parent c3b032a45a
commit 0ecb47e9cb
3871 changed files with 91080 additions and 1640063 deletions

140
port/external/openal/CAHostTimeBase.h vendored Normal file
View file

@ -0,0 +1,140 @@
// Port of pflib/external/openal/CAHostTimeBase.h (Apple Core Audio utility class, Playground SDK 4.0): the host
// clock (mach_absolute_time) and the conversion between host ticks and nanoseconds; all members are static.
// CAHostTimeBase.cpp is ported next to this file.
//
// The members defined inline below are header code. The SDK build emits GetTheCurrentTime, ConvertToNanos and
// GetCurrentTimeInNanos out of line in CAGuard.o (sdk @0x1e50 / @0x1e78 / @0x207e); the game inlines them
// (CAGuard::WaitUntil expands GetCurrentTimeInNanos).
//
// Game vs. SDK: the game binary has no sUseMicroseconds symbol, so the member below stays declared but is not
// defined (the SDK's CAHostTimeBase.cpp defines it). The Track_Host_TimeBase tracking of the SDK header
// (sLastTime, DebugMessageN2) is debug-only and left out. The Windows branches of the SDK header are not carried
// (macOS build); the commented-out Assert() lines of its inline bodies are dropped like the other debug-only notes.
//
// The statics are zero in the shipped image (game __data @0x1e8200..0x1e821f): sIsInited 0x1e8200,
// sFromNanosDenominator 0x1e8204, sFromNanosNumerator 0x1e8208, sToNanosDenominator 0x1e820c,
// sToNanosNumerator 0x1e8210, sMinDelta 0x1e8214, sFrequency 0x1e8218.
#ifndef CAHOSTTIMEBASE_H_INCLUDED
#define CAHOSTTIMEBASE_H_INCLUDED
#include <CoreAudio/CoreAudioTypes.h>
#include <mach/mach_time.h>
class CAHostTimeBase
{
public:
static UInt64 ConvertToNanos(UInt64 inHostTime);
static UInt64 ConvertFromNanos(UInt64 inNanos);
static UInt64 GetTheCurrentTime();
static UInt64 GetCurrentTime() { return GetTheCurrentTime(); }
static UInt64 GetCurrentTimeInNanos();
static Float64 GetFrequency() { if(!sIsInited) { Initialize(); } return sFrequency; }
static UInt32 GetMinimumDelta() { if(!sIsInited) { Initialize(); } return sMinDelta; }
static UInt64 AbsoluteHostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime);
static SInt64 HostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime);
private:
static void Initialize();
static bool sIsInited;
static Float64 sFrequency;
static UInt32 sMinDelta;
static UInt32 sToNanosNumerator;
static UInt32 sToNanosDenominator;
static UInt32 sFromNanosNumerator;
static UInt32 sFromNanosDenominator;
static bool sUseMicroseconds; // SDK-only: no symbol in the game binary (see the note above)
};
inline UInt64 CAHostTimeBase::GetTheCurrentTime()
{
UInt64 theTime = 0;
theTime = mach_absolute_time();
return theTime;
}
inline UInt64 CAHostTimeBase::ConvertToNanos(UInt64 inHostTime)
{
if(!sIsInited)
{
Initialize();
}
Float64 theNumerator = static_cast<Float64>(sToNanosNumerator);
Float64 theDenominator = static_cast<Float64>(sToNanosDenominator);
Float64 theHostTime = static_cast<Float64>(inHostTime);
Float64 thePartialAnswer = theHostTime / theDenominator;
Float64 theFloatAnswer = thePartialAnswer * theNumerator;
UInt64 theAnswer = static_cast<UInt64>(theFloatAnswer);
return theAnswer;
}
inline UInt64 CAHostTimeBase::ConvertFromNanos(UInt64 inNanos)
{
if(!sIsInited)
{
Initialize();
}
Float64 theNumerator = static_cast<Float64>(sToNanosNumerator);
Float64 theDenominator = static_cast<Float64>(sToNanosDenominator);
Float64 theNanos = static_cast<Float64>(inNanos);
Float64 thePartialAnswer = theNanos / theNumerator;
Float64 theFloatAnswer = thePartialAnswer * theDenominator;
UInt64 theAnswer = static_cast<UInt64>(theFloatAnswer);
return theAnswer;
}
inline UInt64 CAHostTimeBase::GetCurrentTimeInNanos()
{
return ConvertToNanos(GetTheCurrentTime());
}
inline UInt64 CAHostTimeBase::AbsoluteHostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime)
{
UInt64 theAnswer;
if(inStartTime <= inEndTime)
{
theAnswer = inEndTime - inStartTime;
}
else
{
theAnswer = inStartTime - inEndTime;
}
return ConvertToNanos(theAnswer);
}
inline SInt64 CAHostTimeBase::HostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime)
{
SInt64 theAnswer;
SInt64 theSign = 1;
if(inStartTime <= inEndTime)
{
theAnswer = inEndTime - inStartTime;
}
else
{
theAnswer = inStartTime - inEndTime;
theSign = -1;
}
return theSign * ConvertToNanos(theAnswer);
}
#endif