]> git.jsancho.org Git - lugaru.git/blobdiff - Source/MacCompatibility.cpp
Lots of input work...demo is now fully playable.
[lugaru.git] / Source / MacCompatibility.cpp
index 86d8dff2d45922f144f755142a5e29eac6b0d952..b05d2b91bc27541fbc6ebec0459dce6a648b6685 100644 (file)
@@ -1,10 +1,41 @@
+#if !PLATFORM_MACOSX
+
 /**> HEADER FILES <**/
 #include "MacCompatibility.h"
+
+#ifdef WIN32
 #include <windows.h>
+#endif
+
 #include <errno.h>
 #include <time.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if PLATFORM_UNIX
+#include <unistd.h>
+#include <sys/time.h>
+#include <assert.h>
+typedef long long __int64;
+typedef __int64 LARGE_INTEGER;
+static int QueryPerformanceFrequency(LARGE_INTEGER *liptr)
+{
+    assert(sizeof (__int64) == 8);
+    assert(sizeof (LARGE_INTEGER) == 8);
+    *liptr = 1000;
+    return(1);
+}
 
+static int QueryPerformanceCounter(LARGE_INTEGER *liptr)
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    *liptr = ( (((LARGE_INTEGER) tv.tv_sec) * 1000) +
+               (((LARGE_INTEGER) tv.tv_usec) / 1000) );
+    return(1);
+}
+#endif
 
 class AppTime
 {
@@ -22,7 +53,6 @@ public:
 static AppTime g_appTime;
 
 
-
 void CopyCStringToPascal( const char* src, unsigned char dst[256])
 {
        int len = strlen( src);
@@ -90,6 +120,78 @@ Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b)
 }
 
 
+#if PLATFORM_UNIX
+#include <sys/types.h>
+#include <dirent.h>
+
+// public domain code from PhysicsFS: http://icculus.org/physfs/
+static int locateOneElement(char *buf)
+{
+    char *ptr;
+    char **rc;
+    char **i;
+    DIR *dirp;
+
+    //if (PHYSFS_exists(buf))
+    if (access(buf, F_OK) == 0)
+        return(1);  /* quick rejection: exists in current case. */
+
+    ptr = strrchr(buf, '/');  /* find entry at end of path. */
+    if (ptr == NULL)
+    {
+        dirp = opendir(".");
+        ptr = buf;
+    } /* if */
+    else
+    {
+        *ptr = '\0';
+        dirp = opendir(buf);
+        *ptr = '/';
+        ptr++;  /* point past dirsep to entry itself. */
+    } /* else */
+
+    struct dirent *dent;
+    while ((dent = readdir(dirp)) != NULL)
+    {
+        if (stricmp(dent->d_name, ptr) == 0)
+        {
+            strcpy(ptr, dent->d_name); /* found a match. Overwrite with this case. */
+            closedir(dirp);
+            return(1);
+        } /* if */
+    } /* for */
+
+    /* no match at all... */
+    closedir(dirp);
+    return(0);
+} /* locateOneElement */
+
+
+static inline int PHYSFSEXT_locateCorrectCase(char *buf)
+{
+    int rc;
+    char *ptr;
+    char *prevptr;
+
+    ptr = prevptr = buf;
+    if (*ptr == '\0')
+        return(0);  /* Uh...I guess that's success. */
+
+    while (ptr = strchr(ptr + 1, '/'))
+    {
+        *ptr = '\0';  /* block this path section off */
+        rc = locateOneElement(buf);
+        *ptr = '/'; /* restore path separator */
+        if (!rc)
+            return(-2);  /* missing element in path. */
+    } /* while */
+
+    /* check final element... */
+    return(locateOneElement(buf) ? 0 : -1);
+} /* PHYSFSEXT_locateCorrectCase */
+#endif
+
+
 static char g_filename[ 256];
 char* ConvertFileName( const char* orgfilename)
 {
@@ -104,5 +206,13 @@ char* ConvertFileName( const char* orgfilename)
                        g_filename[ n] = '/';
        }
 
+    #if PLATFORM_UNIX
+    PHYSFSEXT_locateCorrectCase(g_filename);
+    #endif
+
        return g_filename;
 }
+
+#endif
+
+