Browse Source

Renamed gameplay::printError to gameplay::print.
Added FileSystem::isAbsolutePath.

Darryl Gough 13 years ago
parent
commit
64c6f19902

+ 11 - 8
gameplay/src/Base.h

@@ -49,8 +49,11 @@ using std::modf;
 
 namespace gameplay
 {
-/** Print logging (implemented per platform). */
-extern void printError(const char* format, ...);
+/**
+ * Print logging (implemented per platform).
+ * @script{ignore}
+ */
+extern void print(const char* format, ...);
 }
 
 // Current function macro.
@@ -73,9 +76,9 @@ extern void printError(const char* format, ...);
 #else
 #define GP_ERROR(...) do \
     { \
-        printError("%s -- ", __current__func__); \
-        printError(__VA_ARGS__); \
-        printError("\n"); \
+        gameplay::print("%s -- ", __current__func__); \
+        gameplay::print(__VA_ARGS__); \
+        gameplay::print("\n"); \
         assert(0); \
         std::exit(-1); \
     } while (0)
@@ -84,9 +87,9 @@ extern void printError(const char* format, ...);
 // Warning macro.
 #define GP_WARN(...) do \
     { \
-        printError("%s -- ", __current__func__); \
-        printError(__VA_ARGS__); \
-        printError("\n"); \
+        gameplay::print("%s -- ", __current__func__); \
+        gameplay::print(__VA_ARGS__); \
+        gameplay::print("\n"); \
     } while (0)
 
 // Bullet Physics

+ 10 - 10
gameplay/src/DebugNew.cpp

@@ -122,7 +122,7 @@ void* debugAlloc(std::size_t size, const char* file, int line)
         if (!initialized)
         {
             if (!SymInitialize(GetCurrentProcess(), NULL, true))
-                gameplay::printError("Stack trace tracking will not work.\n");
+                gameplay::print("Stack trace tracking will not work.\n");
             initialized = true;
         }
     
@@ -181,7 +181,7 @@ void debugFree(void* p)
     // Sanity check: ensure that address in record matches passed in address
     if (rec->address != (unsigned long)p)
     {
-        gameplay::printError("[memory] CORRUPTION: Attempting to free memory address with invalid memory allocation record.\n");
+        gameplay::print("[memory] CORRUPTION: Attempting to free memory address with invalid memory allocation record.\n");
         return;
     }
 
@@ -221,7 +221,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
         symbol->MaxNameLength = bufferSize;
         if (!SymGetSymFromAddr64(GetCurrentProcess(), pc, &displacement, symbol))
         {
-            gameplay::printError("[memory] STACK TRACE: <unknown location>\n");
+            gameplay::print("[memory] STACK TRACE: <unknown location>\n");
         }
         else
         {
@@ -243,7 +243,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
                     line.SizeOfStruct = sizeof(line);
                     if (!SymGetLineFromAddr64(GetCurrentProcess(), pc, &displacement, &line))
                     {
-                        gameplay::printError("[memory] STACK TRACE: %s - <unknown file>:<unknown line number>\n", symbol->Name);
+                        gameplay::print("[memory] STACK TRACE: %s - <unknown file>:<unknown line number>\n", symbol->Name);
                     }
                     else
                     {
@@ -253,7 +253,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
                         else
                             file++;
                         
-                        gameplay::printError("[memory] STACK TRACE: %s - %s:%d\n", symbol->Name, file, line.LineNumber);
+                        gameplay::print("[memory] STACK TRACE: %s - %s:%d\n", symbol->Name, file, line.LineNumber);
                     }
                 }
             }
@@ -267,24 +267,24 @@ extern void printMemoryLeaks()
     // Dump general heap memory leaks
     if (__memoryAllocationCount == 0)
     {
-        gameplay::printError("[memory] All HEAP allocations successfully cleaned up (no leaks detected).\n");
+        gameplay::print("[memory] All HEAP allocations successfully cleaned up (no leaks detected).\n");
     }
     else
     {
-        gameplay::printError("[memory] WARNING: %d HEAP allocations still active in memory.\n", __memoryAllocationCount);
+        gameplay::print("[memory] WARNING: %d HEAP allocations still active in memory.\n", __memoryAllocationCount);
         MemoryAllocationRecord* rec = __memoryAllocations;
         while (rec)
         {
 #ifdef WIN32
             if (rec->trackStackTrace)
             {
-                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d:\n", rec->address, rec->size);
+                gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d:\n", rec->address, rec->size);
                 printStackTrace(rec);
             }
             else
-                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
+                gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
 #else
-            gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
+            gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
 #endif
             rec = rec->next;
         }

+ 17 - 0
gameplay/src/FileSystem.cpp

@@ -305,6 +305,23 @@ char* FileSystem::readAll(const char* filePath, int* fileSize)
     return buffer;
 }
 
+bool FileSystem::isAbsolutePath(const char* filePath)
+{
+    if (filePath == 0 || filePath[0] == '\0')
+        return false;
+#ifdef WIN32
+    if (strlen(filePath) >= 2)
+    {
+        char first = filePath[0];
+        if (filePath[1] == ':' && ((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')))
+            return true;
+    }
+    return false;
+#else
+    return filePath[0] == '/';
+#endif
+}
+
 void createFileFromAsset(const char* path)
 {
 #ifdef __ANDROID__

+ 9 - 0
gameplay/src/FileSystem.h

@@ -129,6 +129,15 @@ public:
      */
     static char* readAll(const char* filePath, int* fileSize = NULL);
 
+    /**
+     * Determines if the file path is an absolute path for the current platform.
+     * 
+     * @param filePath The file path to test.
+     * 
+     * @return True if the path is an absolute path or false otherwise.
+     */
+    static bool isAbsolutePath(const char* filePath);
+
 private:
 
     /**

+ 2 - 2
gameplay/src/PlatformAndroid.cpp

@@ -54,7 +54,7 @@ static double timespec2millis(struct timespec *a)
     return (1000.0 * a->tv_sec) + (0.000001 * a->tv_nsec);
 }
 
-extern void printError(const char* format, ...)
+extern void print(const char* format, ...)
 {
     GP_ASSERT(format);
     va_list argptr;
@@ -85,7 +85,7 @@ static EGLenum checkErrorEGL(const char* msg)
         "EGL power management event has occurred",
     };
     EGLenum error = eglGetError();
-    printError("%s: %s.", msg, errmsg[error - EGL_SUCCESS]);
+    print("%s: %s.", msg, errmsg[error - EGL_SUCCESS]);
     return error;
 }
 

+ 1 - 1
gameplay/src/PlatformMacOSX.mm

@@ -618,7 +618,7 @@ int getKey(unsigned short keyCode, unsigned int modifierFlags)
 namespace gameplay
 {
 
-extern void printError(const char* format, ...)
+extern void print(const char* format, ...)
 {
     GP_ASSERT(format);
     va_list argptr;

+ 1 - 1
gameplay/src/PlatformQNX.cpp

@@ -400,7 +400,7 @@ static int getUnicode(int qnxKeyCode)
     return qnxKeyCode;
 }
 
-extern void printError(const char* format, ...)
+extern void print(const char* format, ...)
 {
     GP_ASSERT(format);
     va_list argptr;

+ 2 - 2
gameplay/src/PlatformWin32.cpp

@@ -9,7 +9,7 @@
 #include <GL/wglew.h>
 #include <windowsx.h>
 
-using gameplay::printError;
+using gameplay::print;
 
 // Default to 720p
 static int __width = 1280;
@@ -444,7 +444,7 @@ LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 namespace gameplay
 {
 
-extern void printError(const char* format, ...)
+extern void print(const char* format, ...)
 {
     va_list argptr;
     va_start(argptr, format);

+ 2 - 2
gameplay/src/PlatformiOS.mm

@@ -107,7 +107,7 @@ int getKey(unichar keyCode);
         }
         else
         {
-            printError("Invalid OS Version: %s\n", (currSysVer == NULL?"NULL":[currSysVer cStringUsingEncoding:NSASCIIStringEncoding]));
+            print("Invalid OS Version: %s\n", (currSysVer == NULL?"NULL":[currSysVer cStringUsingEncoding:NSASCIIStringEncoding]));
             [self release];
             return nil;
         }
@@ -813,7 +813,7 @@ int getKey(unichar keyCode)
 namespace gameplay
 {
     
-extern void printError(const char* format, ...)
+extern void print(const char* format, ...)
 {
     GP_ASSERT(format);
     va_list argptr;

+ 5 - 5
gameplay/src/Ref.cpp

@@ -68,17 +68,17 @@ void Ref::printLeaks()
     // Dump Ref object memory leaks
     if (__refAllocationCount == 0)
     {
-        printError("[memory] All Ref objects successfully cleaned up (no leaks detected).\n");
+        print("[memory] All Ref objects successfully cleaned up (no leaks detected).\n");
     }
     else
     {
-        printError("[memory] WARNING: %d Ref objects still active in memory.\n", __refAllocationCount);
+        print("[memory] WARNING: %d Ref objects still active in memory.\n", __refAllocationCount);
         for (RefAllocationRecord* rec = __refAllocations; rec != NULL; rec = rec->next)
         {
             Ref* ref = rec->ref;
             GP_ASSERT(ref);
             const char* type = typeid(*ref).name();
-            printError("[memory] LEAK: Ref object '%s' still active with reference count %d.\n", (type ? type : ""), ref->getRefCount());
+            print("[memory] LEAK: Ref object '%s' still active with reference count %d.\n", (type ? type : ""), ref->getRefCount());
         }
     }
 }
@@ -105,14 +105,14 @@ void untrackRef(Ref* ref, void* record)
 {
     if (!record)
     {
-        printError("[memory] ERROR: Attempting to free null ref tracking record.\n");
+        print("[memory] ERROR: Attempting to free null ref tracking record.\n");
         return;
     }
 
     RefAllocationRecord* rec = (RefAllocationRecord*)record;
     if (rec->ref != ref)
     {
-        printError("[memory] CORRUPTION: Attempting to free Ref with invalid ref tracking record.\n");
+        print("[memory] CORRUPTION: Attempting to free Ref with invalid ref tracking record.\n");
         return;
     }
 

+ 3 - 3
gameplay/src/ScriptController.cpp

@@ -518,12 +518,12 @@ void ScriptController::setString(const char* name, const char* v)
 
 void ScriptController::print(const char* str)
 {
-    printError("%s", str);
+    gameplay::print("%s", str);
 }
 
 void ScriptController::print(const char* str1, const char* str2)
 {
-    printError("%s%s", str1, str2);
+    gameplay::print("%s%s", str1, str2);
 }
 
 ScriptController::ScriptController() : _lua(NULL)
@@ -552,7 +552,7 @@ void ScriptController::initialize()
     luaL_openlibs(_lua);
     lua_RegisterAllBindings();
 
-    // Create our own print() function that uses gameplay::printError.
+    // Create our own print() function that uses gameplay::print.
     if (luaL_dostring(_lua, lua_print_function))
         GP_ERROR("Failed to load custom print() function with error: '%s'.", lua_tostring(_lua, -1));
 }

+ 40 - 0
gameplay/src/lua/lua_FileSystem.cpp

@@ -18,6 +18,7 @@ void luaRegister_FileSystem()
     {
         {"fileExists", lua_FileSystem_static_fileExists},
         {"getResourcePath", lua_FileSystem_static_getResourcePath},
+        {"isAbsolutePath", lua_FileSystem_static_isAbsolutePath},
         {"loadResourceAliases", lua_FileSystem_static_loadResourceAliases},
         {"readAll", lua_FileSystem_static_readAll},
         {"resolvePath", lua_FileSystem_static_resolvePath},
@@ -143,6 +144,45 @@ int lua_FileSystem_static_getResourcePath(lua_State* state)
     return 0;
 }
 
+int lua_FileSystem_static_isAbsolutePath(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = ScriptUtil::getString(1, false);
+
+                bool result = FileSystem::isAbsolutePath(param1);
+
+                // Push the return value onto the stack.
+                lua_pushboolean(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "lua_FileSystem_static_isAbsolutePath - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_FileSystem_static_loadResourceAliases(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 0
gameplay/src/lua/lua_FileSystem.h

@@ -8,6 +8,7 @@ namespace gameplay
 int lua_FileSystem__gc(lua_State* state);
 int lua_FileSystem_static_fileExists(lua_State* state);
 int lua_FileSystem_static_getResourcePath(lua_State* state);
+int lua_FileSystem_static_isAbsolutePath(lua_State* state);
 int lua_FileSystem_static_loadResourceAliases(lua_State* state);
 int lua_FileSystem_static_readAll(lua_State* state);
 int lua_FileSystem_static_resolvePath(lua_State* state);

+ 0 - 37
gameplay/src/lua/lua_Global.cpp

@@ -6,7 +6,6 @@ namespace gameplay
 
 void luaRegister_lua_Global()
 {
-    ScriptUtil::registerFunction("printError", lua__printError);
     ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Button");
     ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "CheckBox");
     ScriptUtil::setGlobalHierarchyPair("AnimationTarget", "Container");
@@ -764,42 +763,6 @@ void luaRegister_lua_Global()
     }
 }
 
-int lua__printError(lua_State* state)
-{
-    // Get the number of parameters.
-    int paramCount = lua_gettop(state);
-
-    // Attempt to match the parameters to a valid binding.
-    switch (paramCount)
-    {
-        case 1:
-        {
-            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
-            {
-                // Get parameter 1 off the stack.
-                const char* param1 = ScriptUtil::getString(1, false);
-
-                printError(param1);
-                
-                return 0;
-            }
-            else
-            {
-                lua_pushstring(state, "lua__printError - Failed to match the given parameters to a valid function signature.");
-                lua_error(state);
-            }
-            break;
-        }
-        default:
-        {
-            lua_pushstring(state, "Invalid number of parameters (expected 1).");
-            lua_error(state);
-            break;
-        }
-    }
-    return 0;
-}
-
 static const char* enumStringEmpty = "";
 
 const char* lua_stringFromEnumGlobal(std::string& enumname, unsigned int value)

+ 0 - 3
gameplay/src/lua/lua_Global.h

@@ -44,9 +44,6 @@
 namespace gameplay
 {
 
-// Lua bindings for global functions.
-int lua__printError(lua_State* state);
-
 // Global enum to string conversion function (used to pass enums to Lua from C++).
 const char* lua_stringFromEnumGlobal(std::string& enumname, unsigned int value);