Merge branch 'master' into mac

# Conflicts:
#	AerofoilX/GpMain_SDL_X.cpp
This commit is contained in:
Madthijs
2021-04-28 19:17:55 +02:00
186 changed files with 6016 additions and 1563 deletions

View File

@@ -5,6 +5,7 @@
struct IGpSystemServices;
struct IGpAudioDriver;
struct IGpLogDriver;
struct IGpAllocator;
struct GpAudioDriverProperties
{
@@ -15,4 +16,5 @@ struct GpAudioDriverProperties
IGpLogDriver *m_logger;
IGpSystemServices *m_systemServices;
IGpAllocator *m_alloc;
};

View File

@@ -1,11 +1,16 @@
#pragma once
#include "CoreDefs.h"
template<class T>
class GpComPtr final
{
public:
GpComPtr();
GpComPtr(const GpComPtr<T> &other);
#if GP_IS_CPP11
GpComPtr(GpComPtr<T> &&other);
#endif
explicit GpComPtr(T *ptr);
~GpComPtr();
@@ -41,6 +46,23 @@ inline GpComPtr<T>::GpComPtr(const GpComPtr<T> &other)
m_ptr->AddRef();
}
#if GP_IS_CPP11
template<class T>
inline GpComPtr<T>::GpComPtr(GpComPtr<T> &&other)
: m_ptr(other.m_ptr)
{
if (m_ptr)
m_ptr->AddRef();
if (other.m_ptr)
{
other.m_ptr->Release();
other.m_ptr = nullptr;
}
}
#endif
template<class T>
inline GpComPtr<T>::GpComPtr(T *ptr)
: m_ptr(ptr)

View File

@@ -10,6 +10,7 @@ struct IGpFiber;
struct IGpVOSEventQueue;
struct IGpLogDriver;
struct IGpSystemServices;
struct IGpAllocator;
struct GpDisplayDriverProperties
{
@@ -43,4 +44,5 @@ struct GpDisplayDriverProperties
IGpVOSEventQueue *m_eventQueue;
IGpLogDriver *m_logger;
IGpSystemServices *m_systemServices;
IGpAllocator *m_alloc;
};

View File

@@ -16,6 +16,7 @@ namespace GpDriverIDs
kSystemServices,
kFont,
kEventQueue,
kAlloc,
kCount
};
@@ -54,6 +55,7 @@ GP_DEFINE_MULTI_DRIVER(kInput, IGpInputDriver);
GP_DEFINE_DRIVER(kSystemServices, IGpSystemServices);
GP_DEFINE_DRIVER(kFont, IGpFontHandler);
GP_DEFINE_DRIVER(kEventQueue, IGpVOSEventQueue);
GP_DEFINE_DRIVER(kAlloc, IGpAllocator);
struct GpDriverCollection
{

View File

@@ -2,7 +2,11 @@
#include "EGpFontHandlerType.h"
struct IGpAllocator;
struct GpFontHandlerProperties
{
EGpFontHandlerType m_type;
IGpAllocator *m_alloc;
};

View File

@@ -3,6 +3,7 @@
#include <stddef.h>
#include "GpFilePos.h"
#include "CoreDefs.h"
class GpIOStream
{
@@ -17,11 +18,15 @@ public:
virtual bool SeekEnd(GpUFilePos_t loc) = 0;
virtual GpUFilePos_t Size() const = 0;
virtual GpUFilePos_t Tell() const = 0;
virtual void Close() = 0;
virtual void GP_ASYNCIFY_PARANOID_NAMED(Close)() = 0;
virtual void Flush() = 0;
bool ReadExact(void *bytesOut, size_t size);
bool WriteExact(const void *bytesOut, size_t size);
#if GP_ASYNCIFY_PARANOID
void Close();
#endif
};
inline bool GpIOStream::ReadExact(void *bytesOut, size_t size)

View File

@@ -4,10 +4,12 @@
struct IGpAudioDriver;
struct IGpVOSEventQueue;
struct IGpAllocator;
struct GpInputDriverProperties
{
EGpInputDriverType m_type;
IGpVOSEventQueue *m_eventQueue;
IGpAllocator *m_alloc;
};

View File

@@ -12,4 +12,6 @@ struct GpRenderedGlyphMetrics
int16_t m_bearingX;
int16_t m_bearingY;
int16_t m_advanceX;
int16_t m_bitmapOffsetX;
int16_t m_bitmapOffsetY;
};

165
GpCommon/GpUnicode.h Normal file
View File

@@ -0,0 +1,165 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
namespace GpUnicode
{
namespace UTF8
{
static const unsigned int kMaxEncodedBytes = 4;
inline bool Decode(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0x80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
size_t sz = 0;
uint32_t codePoint = 0;
uint32_t minCodePoint = 0;
if ((characters[0] & 0xe0) == 0xc0)
{
sz = 2;
minCodePoint = 0x80;
codePoint = (characters[0] & 0x1f);
}
else if ((characters[0] & 0xf0) == 0xe0)
{
sz = 3;
minCodePoint = 0x800;
codePoint = (characters[0] & 0x0f);
}
else if ((characters[0] & 0xf8) == 0xf0)
{
sz = 4;
minCodePoint = 0x10000;
codePoint = (characters[0] & 0x07);
}
else
return false;
if (availableCharacters < sz)
return false;
for (size_t auxByte = 1; auxByte < sz; auxByte++)
{
if ((characters[auxByte] & 0xc0) != 0x80)
return false;
codePoint = (codePoint << 6) | (characters[auxByte] & 0x3f);
}
if (codePoint < minCodePoint || codePoint > 0x10ffff)
return false;
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
return false;
outCodePoint = codePoint;
outCharactersDigested = sz;
return true;
}
inline void Encode(uint8_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
codePoint &= 0x1fffff;
uint8_t signalBits = 0;
size_t numBytes = 0;
if (codePoint < 0x0080)
{
numBytes = 1;
signalBits = 0;
}
else if (codePoint < 0x0800)
{
numBytes = 2;
signalBits = 0xc0;
}
else if (codePoint < 0x10000)
{
numBytes = 3;
signalBits = 0xe0;
}
else
{
numBytes = 4;
signalBits = 0xf0;
}
characters[0] = static_cast<uint8_t>((codePoint >> (6 * (numBytes - 1))) | signalBits);
for (size_t i = 1; i < numBytes; i++)
{
const uint32_t isolate = ((codePoint >> (6 * (numBytes - 1 - i))) & 0x3f) | 0x80;
characters[i] = static_cast<uint8_t>(isolate);
}
outCharactersEmitted = numBytes;
}
}
namespace UTF16
{
inline bool Decode(const uint16_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0xff80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
if (characters[0] <= 0xd7ff || characters[0] >= 0xe000)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
// Surrogate pair
if (characters[0] >= 0xdc00 || availableCharacters < 2)
return false;
if (characters[1] < 0xdc00 || characters[1] >= 0xe000)
return false;
uint16_t highBits = (characters[0] & 0x3ff);
uint16_t lowBits = (characters[1] & 0x3ff);
outCharactersDigested = 2;
outCodePoint = (highBits << 10) + lowBits + 0x10000;
return true;
}
inline void Encode(uint16_t *characters, size_t &outCharactersEmitted, uint32_t codePoint)
{
if (codePoint <= 0xd7ff || codePoint >= 0xe000)
{
outCharactersEmitted = 1;
characters[0] = static_cast<uint16_t>(codePoint);
return;
}
uint32_t codePointBits = (codePoint - 0x10000) & 0xfffff;
uint16_t lowBits = (codePointBits & 0x3ff);
uint16_t highBits = ((codePointBits >> 10) & 0x3ff);
outCharactersEmitted = 2;
characters[0] = (0xd800 + highBits);
characters[1] = (0xdc00 + lowBits);
}
}
}

View File

@@ -13,6 +13,7 @@
struct IGpBWCursor_Win32;
struct IGpCursor_Win32;
struct IGpAllocator;
struct IGpVOSEventQueue;
struct GpWindowsGlobals
@@ -28,7 +29,7 @@ struct GpWindowsGlobals
HICON m_hIconSm;
int m_nCmdShow;
IGpCursor_Win32 *(*m_createColorCursorFunc)(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
IGpCursor_Win32 *(*m_createBWCursorFunc)(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
IGpCursor_Win32 *(*m_createColorCursorFunc)(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
IGpCursor_Win32 *(*m_createBWCursorFunc)(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY);
};

12
GpCommon/IGpAllocator.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
struct IGpAllocator
{
virtual void *Realloc(void *buf, size_t newSize) = 0;
inline void *Alloc(size_t size) { return this->Realloc(nullptr, size); }
inline void Release(void *ptr) { this->Realloc(ptr, 0); }
};

View File

@@ -0,0 +1,8 @@
#pragma once
struct IGpAudioBuffer
{
public:
virtual void AddRef() = 0;
virtual void Release() = 0;
};

View File

@@ -3,11 +3,12 @@
#include <stddef.h>
struct IGpAudioChannelCallbacks;
struct IGpAudioBuffer;
struct IGpAudioChannel
{
virtual void SetAudioChannelContext(IGpAudioChannelCallbacks *callbacks) = 0;
virtual void PostBuffer(const void *buffer, size_t bufferSize) = 0;
virtual bool PostBuffer(IGpAudioBuffer *buffer) = 0;
virtual void Stop() = 0;
virtual void Destroy() = 0;
};

View File

@@ -4,10 +4,12 @@
struct IGpAudioChannel;
struct IGpPrefsHandler;
struct IGpAudioBuffer;
struct IGpAudioDriver
{
public:
virtual IGpAudioBuffer *CreateBuffer(const void *buffer, size_t bufferSize) = 0;
virtual IGpAudioChannel *CreateChannel() = 0;
virtual void SetMasterVolume(uint32_t vol, uint32_t maxVolume) = 0;

View File

@@ -1,6 +1,7 @@
#pragma once
#include "GpFileCreationDisposition.h"
#include "CoreDefs.h"
#include "VirtualDirectory.h"
#include <stdint.h>
@@ -17,7 +18,7 @@ public:
virtual bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) = 0;
virtual bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists) = 0;
virtual GpIOStream *OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition) = 0;
virtual bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) = 0;
GP_ASYNCIFY_PARANOID_VIRTUAL bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) GP_ASYNCIFY_PARANOID_PURE;
virtual IGpDirectoryCursor *ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths) = 0;
virtual bool ValidateFilePath(const char *path, size_t pathLen) const = 0;

View File

@@ -8,6 +8,7 @@ struct GpRenderedFontMetrics;
struct IGpFont
{
virtual void Destroy() = 0;
virtual IGpFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) = 0;
virtual IGpFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, unsigned int xScale, unsigned int yScale, bool aa) = 0;
virtual bool GetLineSpacing(unsigned int size, int32_t &outSpacing) = 0;
virtual bool SupportScaling() const = 0;
};

View File

@@ -7,6 +7,6 @@ struct IGpFontHandler
{
virtual void Shutdown() = 0;
virtual IGpFont *LoadFont(GpIOStream *stream) = 0;
virtual IGpFont *LoadFont(GpIOStream *stream, int typeFaceIndex) = 0;
virtual bool KeepStreamOpen() const = 0;
};