ecere: More Emscripten tweaks
authorJerome St-Louis <jerome@ecere.com>
Thu, 27 Nov 2014 07:59:54 +0000 (02:59 -0500)
committerJerome St-Louis <jerome@ecere.com>
Fri, 20 Feb 2015 15:39:20 +0000 (10:39 -0500)
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/sys/Mutex.ec
ecere/src/sys/Semaphore.ec
ecere/src/sys/Thread.ec

index 64e47ac..49ad50e 100644 (file)
@@ -86,7 +86,6 @@ namespace gfx::drivers;
    #define uint _uint
 
    #include <GL/gl.h>
-   #include <GL/glut.h>
 
    //#include <GLES/gl.h>
    //#include <EGL/egl.h>
@@ -3449,7 +3448,9 @@ class OpenGLDisplayDriver : DisplayDriver
          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:
index 38cb873..9632796 100644 (file)
@@ -27,8 +27,6 @@ namespace sys;
 
 import "instance"
 
-#if !defined(__EMSCRIPTEN__)
-
 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
 public int64 GetCurrentThreadID()
 {
@@ -41,6 +39,8 @@ public int64 GetCurrentThreadID()
 
 public class Mutex : struct
 {
+#if !defined(__EMSCRIPTEN__)
+
 //   class_fixed
 #if defined(__WIN32__)
 #ifdef _DEBUG
@@ -51,6 +51,7 @@ public class Mutex : struct
 #else
    pthread_mutex_t mutex;
 #endif
+#endif
 
 #ifdef _DEBUG
    int64 owningThread;
@@ -59,7 +60,8 @@ public class Mutex : struct
 
    Mutex()
    {
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
 #ifdef _DEBUG
       mutex = CreateMutex(null, FALSE, null);
 #else
@@ -79,6 +81,8 @@ public class Mutex : struct
       pthread_mutex_init(&mutex, &attr);
       pthread_mutexattr_destroy(&attr);
 #endif
+#endif
+
       lockCount = 0;
 #ifdef _DEBUG
       owningThread = 0;
@@ -88,7 +92,8 @@ public class Mutex : struct
 
    ~Mutex()
    {
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
 #ifdef _DEBUG
       CloseHandle(mutex);
 #else
@@ -97,6 +102,7 @@ public class Mutex : struct
 #else
       pthread_mutex_destroy(&mutex);
 #endif
+#endif
    }
 
 public:
@@ -104,11 +110,12 @@ 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?");
@@ -128,6 +135,8 @@ public:
 #endif
 #endif
 
+#endif
+
 #ifdef _DEBUG
          owningThread = GetCurrentThreadID();
 #endif
@@ -139,6 +148,7 @@ public:
    {
       if(this)
       {
+#if !defined(__EMSCRIPTEN__)
          /*
          if(this == globalSystem.fileMonitorMutex)
             printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
@@ -154,7 +164,7 @@ public:
 #else
             ;
 #endif
-#if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
+#if defined(__WIN32__)
 #ifdef _DEBUG
          ReleaseMutex(mutex);
 #else
@@ -172,6 +182,8 @@ public:
          pthread_mutex_unlock(&mutex);
 #endif
 #endif
+#endif
+
 #ifdef _DEBUG
          if(lockCount < 0)
             PrintLn("WARNING: lockCount < 0");
@@ -181,5 +193,3 @@ public:
 
    property int lockCount { get { return lockCount; } }
 };
-
-#endif // !defined(__EMSCRIPTEN__)
index 8f4c98a..b7e5c7c 100644 (file)
@@ -24,10 +24,10 @@ namespace sys;
 
 import "System"
 
-#if !defined(__EMSCRIPTEN__)
-
 public class Semaphore : struct
 {
+#if !defined(__EMSCRIPTEN__)
+
 #if defined(__WIN32__)
    HANDLE handle;
 #elif defined(__APPLE__)
@@ -37,11 +37,13 @@ public class Semaphore : struct
 #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__)
@@ -49,12 +51,14 @@ public class Semaphore : struct
 #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__)
@@ -62,12 +66,14 @@ public class Semaphore : struct
 #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__)
@@ -86,11 +92,13 @@ public:
 #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?");
@@ -110,10 +118,12 @@ public:
       sem_wait(&semaphore);
 #endif
 #endif
+#endif
    }
 
    void Release(void)
    {
+#if !defined(__EMSCRIPTEN__)
 #if defined(__WIN32__)
       ReleaseSemaphore(handle, 1, null);
 #elif defined(__APPLE__)
@@ -127,12 +137,14 @@ public:
       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);
@@ -144,6 +156,7 @@ public:
          sem_destroy(&semaphore);
          sem_init(&semaphore, 0, initCount);
 #endif
+#endif
          initCount = value;
       }
       get { return initCount; }
@@ -152,14 +165,14 @@ public:
    {
       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__)
index 33802ec..ae2478b 100644 (file)
@@ -25,8 +25,6 @@ import "instance"
 import "Semaphore"
 #endif
 
-#if !defined(__EMSCRIPTEN__)
-
 public enum ThreadPriority
 {
    normal = 0,
@@ -51,7 +49,7 @@ public class Thread
 #if defined(__WIN32__)
    HANDLE handle;
    uint id;
-#else
+#elif !defined(__EMSCRIPTEN__)
    pthread_t id;
    bool dontDetach;
    Semaphore sem { };
@@ -60,6 +58,7 @@ public class Thread
    uint returnCode;
    bool started;
 
+#if !defined(__EMSCRIPTEN__)
 #if defined(__WIN32__)
    uint ThreadCallBack()
 #else
@@ -84,6 +83,7 @@ public class Thread
       return (void *)(uintptr_t)returnCode;
 #endif
    }
+#endif
 
 public:
    virtual uint Main(void);
@@ -93,11 +93,12 @@ public:
       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)
          {
@@ -114,13 +115,15 @@ public:
             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)
       {
@@ -131,6 +134,7 @@ public:
       if(started)
          pthread_kill(id, SIGQUIT);
 #endif
+#endif
       if(started)
       {
          started = false;
@@ -140,6 +144,7 @@ public:
 
    void Wait()
    {
+#if !defined(__EMSCRIPTEN__)
 #if defined(__WIN32__)
       if(WaitForSingleObject(handle, INFINITE /*2000*/) == WAIT_TIMEOUT)
          PrintLn("Thread not returning?\n");
@@ -152,10 +157,12 @@ public:
       if(started)
          sem.Wait();
 #endif
+#endif
    }
 
    void SetPriority(ThreadPriority priority)
    {
+#if !defined(__EMSCRIPTEN__)
 #if defined(__WIN32__)
       SetThreadPriority(handle, priority);
 #else
@@ -166,9 +173,9 @@ public:
       pthread_setschedparam(id, policy, &param);
       */
 #endif
+#endif
    }
 
    property bool created { get { return started; } };
 }
 
-#endif // !defined(__EMSCRIPTEN__)