浏览该文件的文档.
27 #ifndef _AK_PLATFORM_FUNCS_H_
28 #define _AK_PLATFORM_FUNCS_H_
31 #include <sce_atomic.h>
37 #include <kernel/eventflag.h>
67 #define AK_DECLARE_THREAD_ROUTINE( FuncName ) void* FuncName(void* lpParameter)
68 #define AK_THREAD_RETURN( _param_ ) return (_param_);
69 #define AK_THREAD_ROUTINE_PARAMETER lpParameter
70 #define AK_GET_THREAD_ROUTINE_PARAMETER_PTR(type) reinterpret_cast<type*>( AK_THREAD_ROUTINE_PARAMETER )
72 #define AK_RETURN_THREAD_OK 0x00000000
73 #define AK_RETURN_THREAD_ERROR 0x00000001
74 #define AK_DEFAULT_STACK_SIZE (128*1024)
75 #define AK_THREAD_DEFAULT_SCHED_POLICY SCE_KERNEL_SCHED_FIFO
76 #define AK_THREAD_PRIORITY_NORMAL SCE_KERNEL_PRIO_FIFO_DEFAULT
77 #define AK_THREAD_PRIORITY_ABOVE_NORMAL SCE_KERNEL_PRIO_FIFO_HIGHEST
78 #define AK_THREAD_PRIORITY_BELOW_NORMAL SCE_KERNEL_PRIO_FIFO_LOWEST
80 #define AK_THREAD_AFFINITY_ALL 63 // from binary 111111 setting the 6 available core to true. (ex: 4 << 1)
81 #define AK_THREAD_AFFINITY_DEFAULT AK_THREAD_AFFINITY_ALL
84 #define AK_RELEASE_GPU_OFFLINE_FRAME sce::Gnm::submitDone();
87 #define AK_NULL_THREAD NULL
89 #define AK_INFINITE (AK_UINT_MAX)
91 #define AkMax(x1, x2) (((x1) > (x2))? (x1): (x2))
92 #define AkMin(x1, x2) (((x1) < (x2))? (x1): (x2))
93 #define AkClamp(x, min, max) ((x) < (min)) ? (min) : (((x) > (max) ? (max) : (x)))
105 fputs( in_pszMsg, stderr );
110 fputws( in_pszMsg, stderr );
114 template <
int MaxSize = 0>
118 va_start(args, in_pszFmt);
119 vfwprintf(stderr, in_pszFmt, args);
124 template <
int MaxSize = 0>
128 va_start(args, in_pszFmt);
129 vfprintf(stderr, in_pszFmt, args);
136 template <
int MaxSize = 0>
139 template <
int MaxSize = 0>
157 int ret = sceKernelCreateEventFlag(
160 SCE_KERNEL_EVF_ATTR_MULTI,
180 sceKernelDeleteEventFlag(io_event);
190 SCE_KERNEL_EVF_WAITMODE_OR | SCE_KERNEL_EVF_WAITMODE_CLEAR_ALL,
198 AKVERIFY( sceKernelSetEventFlag( in_event, 1 ) == 0 );
210 int ret = sceKernelCreateSema(
224 AKVERIFY(sceKernelDeleteSema(io_semaphore) == SCE_OK);
230 AKVERIFY(sceKernelWaitSema(in_semaphore, 1,
NULL) == SCE_OK);
236 AKVERIFY(sceKernelSignalSema(in_semaphore, in_count) == SCE_OK);
265 #define AkExitThread( _result ) return _result;
282 const char * in_szThreadName )
289 AKVERIFY(!scePthreadAttrInit(&attr));
292 AKVERIFY(!scePthreadAttrSetdetachstate(&attr, SCE_PTHREAD_CREATE_JOINABLE));
293 AKVERIFY(!scePthreadAttrSetinheritsched(&attr, SCE_PTHREAD_EXPLICIT_SCHED));
298 if( scePthreadAttrSetschedpolicy( &attr, sched_policy ) )
300 AKASSERT( !
"AKCreateThread invalid sched policy, will automatically set it to FIFO scheduling" );
302 AKVERIFY( !scePthreadAttrSetschedpolicy( &attr, sched_policy ));
305 int minPriority, maxPriority;
306 minPriority = SCE_KERNEL_PRIO_FIFO_HIGHEST;
307 maxPriority = SCE_KERNEL_PRIO_FIFO_LOWEST;
311 if( in_threadProperties.
nPriority >= minPriority && in_threadProperties.
nPriority <= maxPriority )
313 SceKernelSchedParam schedParam;
314 AKVERIFY( scePthreadAttrGetschedparam(&attr, &schedParam) == 0 );
315 schedParam.sched_priority = in_threadProperties.
nPriority;
316 AKVERIFY( scePthreadAttrSetschedparam(&attr, &schedParam) == 0 );
320 int threadError = scePthreadCreate(out_pThread, &attr, pStartRoutine, pParams, in_szThreadName);
322 AKVERIFY(!scePthreadAttrDestroy(&attr));
324 if( threadError != 0 )
348 return scePthreadSelf();
354 usleep( in_ulMilliseconds * 1000 );
363 uint64_t uTime = sceKernelGetProcessTimeCounter();
364 *out_piLastTime = (
AkInt64)uTime;
370 *out_piFreq = (
AkInt64)sceKernelGetProcessTimeCounterFrequency();
390 char* io_pszAnsiString )
395 memset (&state,
'\0',
sizeof (state));
397 return (
AkInt32)wcsrtombs(io_pszAnsiString,
398 &in_pszUnicodeString,
407 void* io_pvUnicodeStringBuffer )
412 memset (&state,
'\0',
sizeof (state));
414 return (
AkInt32)mbsrtowcs((
wchar_t*)io_pvUnicodeStringBuffer,
422 void* io_pvUnicodeStringBuffer )
424 return AkCharToWideChar( in_pszUtf8String, in_uiOutBufferSize, (
wchar_t*)io_pvUnicodeStringBuffer );
430 size_t uSizeCopy =
AkMin( in_uDestMaxNumChars - 1, wcslen( in_pSrc ) + 1 );
431 wcsncpy( in_pDest, in_pSrc, uSizeCopy );
432 in_pDest[uSizeCopy] =
'\0';
438 size_t uSizeCopy =
AkMin( in_uDestMaxNumChars - 1, strlen( in_pSrc ) + 1 );
439 strncpy( in_pDest, in_pSrc, uSizeCopy );
440 in_pDest[uSizeCopy] =
'\0';
446 size_t uAvailableSize = ( in_uDestMaxNumChars - wcslen( in_pDest ) - 1 );
447 wcsncat( in_pDest, in_pSrc,
AkMin( uAvailableSize, wcslen( in_pSrc ) ) );
453 size_t uAvailableSize = ( in_uDestMaxNumChars - strlen( in_pDest ) - 1 );
454 strncat( in_pDest, in_pSrc,
AkMin( uAvailableSize, strlen( in_pSrc ) ) );
457 inline int SafeStrFormat(
wchar_t * in_pDest,
size_t in_uDestMaxNumChars,
const wchar_t* in_pszFmt, ...)
460 va_start(args, in_pszFmt);
461 int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
466 inline int SafeStrFormat(
char * in_pDest,
size_t in_uDestMaxNumChars,
const char* in_pszFmt, ...)
469 va_start(args, in_pszFmt);
470 int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
476 #define AkAlloca( _size_ ) alloca( _size_ )
488 #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
489 _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
490 AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
501 #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
511 #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
512 _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
513 AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
523 #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
529 return ( wcslen( in_pStr ) );
536 return ( strlen( in_pszString ) );
540 #define AK_OSPRINTF snprintf
550 return ( strcmp( in_pszString1, in_pszString2 ) );
561 return ( strncmp(in_pszString1, in_pszString2, in_MaxCountSize) );
567 return in_pathLen >= 1 && in_pszPath[0] ==
'/';
570 #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
571 #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
572 #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::SafeStrCpy( in_pdDest, in_pSrc, in_MaxSize )
573 #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
574 #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkWideCharToChar( in_pSrc, in_MaxSize, in_pdDest )
575 #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
576 #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkCharToWideChar( in_pSrc, in_MaxSize, in_pdDest )
579 #define AK_PATH_SEPARATOR "/"
580 #define AK_HOST_PATH_SEPARATOR "\\"
581 #define AK_LIBRARY_PREFIX ""
582 #define AK_DYNAMIC_LIBRARY_EXTENSION ".prx"
584 #define AK_FILEHANDLE_TO_UINTPTR(_h) ((AkUIntPtr)_h)
585 #define AK_SET_FILEHANDLE_TO_UINTPTR(_h,_u) _h = (AkFileHandle)_u
590 inline void CPUID(
AkUInt32 in_uLeafOpcode,
AkUInt32 in_uSubLeafOpcode,
unsigned int out_uCPUFeatures[4])
592 __get_cpuid_count( in_uLeafOpcode, in_uSubLeafOpcode,
593 &out_uCPUFeatures[0],
594 &out_uCPUFeatures[1],
595 &out_uCPUFeatures[2],
596 &out_uCPUFeatures[3]);
600 #endif // _AK_PLATFORM_FUNCS_H_
AKRESULT AkCreateSemaphore(AkSemaphore &out_semaphore, AkUInt32 in_initialCount)
Platform Independent Helper
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
@ AK_Fail
The operation failed.
int nPriority
Thread priority
void AkClearEvent(AkEvent &out_event)
Platform Independent Helper
AkForceInline void AkClearSemaphore(AkSemaphore &io_semaphore)
Platform Independent Helper
Platform-dependent helpers
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper
AkForceInline void UpdatePerformanceFrequency()
Platform Independent Helper
AKRESULT
Standard function call result.
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
void CPUID(AkUInt32 in_uLeafOpcode, AkUInt32 in_uSubLeafOpcode, unsigned int out_uCPUFeatures[4])
int SafeStrFormat(wchar_t *in_pDest, size_t in_uDestMaxNumChars, const wchar_t *in_pszFmt,...)
AkThreadID CurrentThread()
Returns the calling thread's ID.
bool IsAbsolutePath(const AkOSChar *in_pszPath, size_t in_pathLen)
Detects whether the string represents an absolute path to a file
float AkReal32
32-bit floating point
@ AK_Success
The operation was successful.
int32_t AkInt32
Signed 32-bit integer
void AkCreateThread(AkThreadRoutine pStartRoutine, void *pParams, const AkThreadProperties &in_threadProperties, AkThread *out_pThread, const char *)
Platform Independent Helper
void OutputDebugMsgV(const char *in_pszFmt,...)
Output a debug message on the console (variadic function).
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper
void AkDestroySemaphore(AkSemaphore &io_semaphore)
Platform Independent Helper
void AkDestroyEvent(AkEvent &io_event)
Platform Independent Helper
AkForceInline bool AkIsValidThread(AkThread *in_pThread)
Platform Independent Helper
#define AKASSERT(Condition)
AkForceInline void AkSleep(AkUInt32 in_ulMilliseconds)
Platform Independent Helper
AkForceInline void AkClearThread(AkThread *in_pThread)
Platform Independent Helper
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper
int OsStrNCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2, size_t in_MaxCountSize)
SceKernelCpumask dwAffinityMask
Affinity mask
double AkReal64
64-bit floating point
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper
AkForceInline void SafeStrCpy(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string copy.
int64_t AkInt64
Signed 64-bit integer
void AkWaitForSemaphore(AkSemaphore &in_semaphore)
Platform Independent Helper - Semaphore wait, aka Operation P. Decrements value of semaphore,...
size_t uStackSize
Thread stack size
void PerformanceFrequency(AkInt64 *out_piFreq)
Platform Independent Helper
int uSchedPolicy
Thread scheduling policy
AkForceInline AkInt32 AkCharToWideChar(const char *in_pszAnsiString, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper
uint32_t AkUInt32
Unsigned 32-bit integer
void AkReleaseSemaphore(AkSemaphore &in_semaphore, AkUInt32 in_count)
Platform Independent Helper - Semaphore signal, aka Operation V. Increments value of semaphore by an ...
AkForceInline void SafeStrCat(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string concatenation.
AkForceInline AKRESULT AkCreateNamedEvent(AkEvent &out_event, const char *in_szName)
AkForceInline AkInt32 AkWideCharToChar(const wchar_t *in_pszUnicodeString, AkUInt32 in_uiOutBufferSize, char *io_pszAnsiString)
String conversion helper
AkForceInline void AkWaitForSingleThread(AkThread *in_pThread)
Platform Independent Helper
void AkSignalEvent(const AkEvent &in_event)
Platform Independent Helper
AkForceInline AkInt32 AkUtf8ToWideChar(const char *in_pszUtf8String, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper
AkForceInline void AkCloseThread(AkThread *in_pThread)
Platform Independent Helper
AkForceInline int OsStrCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2)
AkForceInline size_t OsStrLen(const AkOSChar *in_pszString)
AkForceInline AkReal32 Elapsed(const AkInt64 &in_iNow, const AkInt64 &in_iStart)
Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
介绍一下自己的项目。我们会竭力为您提供帮助。
来注册自己的项目,我们帮您快速入门,不带任何附加条件!
开始 Wwise 之旅