#define uint _uint
#include <GL/gl.h>
- #include <GL/glut.h>
//#include <GLES/gl.h>
//#include <EGL/egl.h>
case ambient:
{
float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
+#if !defined(__EMSCRIPTEN__)
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
+#endif
break;
}
case alphaWrite:
import "instance"
-#if !defined(__EMSCRIPTEN__)
-
// Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
public int64 GetCurrentThreadID()
{
public class Mutex : struct
{
+#if !defined(__EMSCRIPTEN__)
+
// class_fixed
#if defined(__WIN32__)
#ifdef _DEBUG
#else
pthread_mutex_t mutex;
#endif
+#endif
#ifdef _DEBUG
int64 owningThread;
Mutex()
{
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
#ifdef _DEBUG
mutex = CreateMutex(null, FALSE, null);
#else
pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy(&attr);
#endif
+#endif
+
lockCount = 0;
#ifdef _DEBUG
owningThread = 0;
~Mutex()
{
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
#ifdef _DEBUG
CloseHandle(mutex);
#else
#else
pthread_mutex_destroy(&mutex);
#endif
+#endif
}
public:
{
if(this)
{
+#if !defined(__EMSCRIPTEN__)
/*
if(this == globalSystem.fileMonitorMutex)
printf("[%d] Waiting on Mutex %x\n", (int)GetCurrentThreadID(), this);
*/
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
#ifdef _DEBUG
if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
PrintLn("Deadlock?");
#endif
#endif
+#endif
+
#ifdef _DEBUG
owningThread = GetCurrentThreadID();
#endif
{
if(this)
{
+#if !defined(__EMSCRIPTEN__)
/*
if(this == globalSystem.fileMonitorMutex)
printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
#else
;
#endif
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
#ifdef _DEBUG
ReleaseMutex(mutex);
#else
pthread_mutex_unlock(&mutex);
#endif
#endif
+#endif
+
#ifdef _DEBUG
if(lockCount < 0)
PrintLn("WARNING: lockCount < 0");
property int lockCount { get { return lockCount; } }
};
-
-#endif // !defined(__EMSCRIPTEN__)
import "System"
-#if !defined(__EMSCRIPTEN__)
-
public class Semaphore : struct
{
+#if !defined(__EMSCRIPTEN__)
+
#if defined(__WIN32__)
HANDLE handle;
#elif defined(__APPLE__)
#else
sem_t semaphore;
#endif
+#endif
int initCount, maxCount;
Semaphore()
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
handle = CreateSemaphore(null, 0, 1, null);
#elif defined(__APPLE__)
#else
sem_init(&semaphore, 0, 0);
#endif
+#endif
maxCount = 1;
initCount = 0;
}
~Semaphore()
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(handle) CloseHandle(handle);
#elif defined(__APPLE__)
#else
sem_destroy(&semaphore);
#endif
+#endif
}
public:
bool TryWait(void)
{
bool result;
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
result = WaitForSingleObject(handle, 0) != WAIT_TIMEOUT;
#elif defined(__APPLE__)
#else
result = sem_trywait(&semaphore) != EAGAIN;
#endif
+#endif
return result;
}
void Wait(void)
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(WaitForSingleObject(handle, INFINITE /*2000*/) == WAIT_TIMEOUT)
PrintLn("Semaphore not released?");
sem_wait(&semaphore);
#endif
#endif
+#endif
}
void Release(void)
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
ReleaseSemaphore(handle, 1, null);
#elif defined(__APPLE__)
if(count < maxCount)
sem_post(&semaphore);
#endif
+#endif
}
property int initCount
{
set
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(handle) CloseHandle(handle);
handle = CreateSemaphore(null, initCount, value, null);
sem_destroy(&semaphore);
sem_init(&semaphore, 0, initCount);
#endif
+#endif
initCount = value;
}
get { return initCount; }
{
set
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(handle) CloseHandle(handle);
handle = CreateSemaphore(null, value, maxCount, null);
#endif
+#endif
maxCount = value;
}
get { return maxCount; }
};
};
-
-#endif // !defined(__EMSCRIPTEN__)
import "Semaphore"
#endif
-#if !defined(__EMSCRIPTEN__)
-
public enum ThreadPriority
{
normal = 0,
#if defined(__WIN32__)
HANDLE handle;
uint id;
-#else
+#elif !defined(__EMSCRIPTEN__)
pthread_t id;
bool dontDetach;
Semaphore sem { };
uint returnCode;
bool started;
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
uint ThreadCallBack()
#else
return (void *)(uintptr_t)returnCode;
#endif
}
+#endif
public:
virtual uint Main(void);
incref this;
if(!started)
{
-#if !defined(__WIN32__)
+#if !defined(__WIN32__) && !defined(__EMSCRIPTEN__)
sem.TryWait();
#endif
started = true;
// printf("Creating %s thread\n", _class.name);
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(!handle)
{
error = pthread_create(&id, null /*&attr*/, ThreadCallBack, this);
if(error)
printf("Error %d creating a thread\n", error);
- }
+ }
+#endif
#endif
}
}
void Kill()
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(handle)
{
if(started)
pthread_kill(id, SIGQUIT);
#endif
+#endif
if(started)
{
started = false;
void Wait()
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(WaitForSingleObject(handle, INFINITE /*2000*/) == WAIT_TIMEOUT)
PrintLn("Thread not returning?\n");
if(started)
sem.Wait();
#endif
+#endif
}
void SetPriority(ThreadPriority priority)
{
+#if !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
SetThreadPriority(handle, priority);
#else
pthread_setschedparam(id, policy, ¶m);
*/
#endif
+#endif
}
property bool created { get { return started; } };
}
-#endif // !defined(__EMSCRIPTEN__)