Add **Web platform with Emscripten**
This commit is contained in:
116
Source/Engine/Platform/Web/WebPlatform.h
Normal file
116
Source/Engine/Platform/Web/WebPlatform.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if PLATFORM_WEB
|
||||
|
||||
#include "../Unix/UnixPlatform.h"
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The Web platform implementation and application management utilities.
|
||||
/// </summary>
|
||||
class FLAXENGINE_API WebPlatform : public UnixPlatform
|
||||
{
|
||||
public:
|
||||
// [UnixPlatform]
|
||||
FORCE_INLINE static void MemoryBarrier()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
// Fake a fence with an arbitrary atomic operation (from emscripten_atomic_fence to avoid including it for less header bloat)
|
||||
uint8 temp = 0;
|
||||
__c11_atomic_fetch_or((_Atomic uint8*)&temp, 0, __ATOMIC_SEQ_CST);
|
||||
#endif
|
||||
}
|
||||
FORCE_INLINE static void MemoryPrefetch(void const* ptr)
|
||||
{
|
||||
__builtin_prefetch(static_cast<char const*>(ptr));
|
||||
}
|
||||
FORCE_INLINE static int64 InterlockedExchange(int64 volatile* dst, int64 exchange)
|
||||
{
|
||||
return __sync_lock_test_and_set(dst, exchange);
|
||||
}
|
||||
FORCE_INLINE static int32 InterlockedCompareExchange(int32 volatile* dst, int32 exchange, int32 comperand)
|
||||
{
|
||||
return __sync_val_compare_and_swap(dst, comperand, exchange);
|
||||
}
|
||||
FORCE_INLINE static int64 InterlockedCompareExchange(int64 volatile* dst, int64 exchange, int64 comperand)
|
||||
{
|
||||
return __sync_val_compare_and_swap(dst, comperand, exchange);
|
||||
}
|
||||
FORCE_INLINE static int64 InterlockedIncrement(int64 volatile* dst)
|
||||
{
|
||||
return __sync_add_and_fetch(dst, 1);
|
||||
}
|
||||
FORCE_INLINE static int64 InterlockedDecrement(int64 volatile* dst)
|
||||
{
|
||||
return __sync_sub_and_fetch(dst, 1);
|
||||
}
|
||||
FORCE_INLINE static int64 InterlockedAdd(int64 volatile* dst, int64 value)
|
||||
{
|
||||
return __sync_fetch_and_add(dst, value);
|
||||
}
|
||||
FORCE_INLINE static int32 AtomicRead(int32 const volatile* dst)
|
||||
{
|
||||
int32 result;
|
||||
__atomic_load(dst, &result, __ATOMIC_SEQ_CST);
|
||||
return result;
|
||||
}
|
||||
FORCE_INLINE static int64 AtomicRead(int64 const volatile* dst)
|
||||
{
|
||||
int64 result;
|
||||
__atomic_load(dst, &result, __ATOMIC_SEQ_CST);
|
||||
return result;
|
||||
}
|
||||
FORCE_INLINE static void AtomicStore(int32 volatile* dst, int32 value)
|
||||
{
|
||||
__atomic_store(dst, &value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
FORCE_INLINE static void AtomicStore(int64 volatile* dst, int64 value)
|
||||
{
|
||||
__atomic_store(dst, &value, __ATOMIC_SEQ_CST);
|
||||
}
|
||||
FORCE_INLINE static uint64 GetCurrentThreadID()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
return (uint64)pthread_self();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
static String GetSystemName();
|
||||
static Version GetSystemVersion();
|
||||
static CPUInfo GetCPUInfo();
|
||||
static MemoryStats GetMemoryStats();
|
||||
static ProcessMemoryStats GetProcessMemoryStats();
|
||||
static void SetThreadPriority(ThreadPriority priority);
|
||||
static void SetThreadAffinityMask(uint64 affinityMask);
|
||||
static void Sleep(int32 milliseconds);
|
||||
static void Yield();
|
||||
static double GetTimeSeconds();
|
||||
static uint64 GetTimeCycles();
|
||||
static void GetSystemTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond);
|
||||
static void GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond);
|
||||
#if !BUILD_RELEASE
|
||||
static void Log(const StringView& msg);
|
||||
static bool IsDebuggerPresent();
|
||||
#endif
|
||||
static String GetComputerName();
|
||||
static bool GetHasFocus();
|
||||
static String GetMainDirectory();
|
||||
static String GetExecutableFilePath();
|
||||
static Guid GetUniqueDeviceId();
|
||||
static String GetWorkingDirectory();
|
||||
static bool SetWorkingDirectory(const String& path);
|
||||
static bool Init();
|
||||
static void LogInfo();
|
||||
static void Tick();
|
||||
static void Exit();
|
||||
static void* LoadLibrary(const Char* filename);
|
||||
static void FreeLibrary(void* handle);
|
||||
static void* GetProcAddress(void* handle, const char* symbol);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user