New platform APIs and new OpenAL cmake

This commit is contained in:
Eduardo Bart 2013-02-22 16:53:28 -03:00
parent 5b573afdfc
commit e4e3d7d053
6 changed files with 53 additions and 3 deletions

View File

@ -4,7 +4,7 @@
# OPENAL_LIBRARY - the OPENAL library # OPENAL_LIBRARY - the OPENAL library
SET(OPENAL_APPLE_PATHS ~/Library/Frameworks /Library/Frameworks) SET(OPENAL_APPLE_PATHS ~/Library/Frameworks /Library/Frameworks)
FIND_PATH(OPENAL_INCLUDE_DIR NAMES AL/al.h PATHS ${OPENAL_APPLE_PATHS}) FIND_PATH(OPENAL_INCLUDE_DIR al.h PATH_SUFFIXES AL OpenAL PATHS ${OPENAL_APPLE_PATHS})
SET(_OPENAL_STATIC_LIBS libOpenAL.a libal.a libopenal.a libOpenAL32.a) SET(_OPENAL_STATIC_LIBS libOpenAL.a libal.a libopenal.a libOpenAL32.a)
SET(_OPENAL_SHARED_LIBS libOpenAL.dll.a libal.dll.a libopenal.dll.a libOpenAL32.dll.a OpenAL al openal OpenAL32) SET(_OPENAL_SHARED_LIBS libOpenAL.dll.a libal.dll.a libopenal.dll.a libOpenAL32.dll.a OpenAL al openal OpenAL32)
IF(USE_STATIC_LIBS) IF(USE_STATIC_LIBS)

View File

@ -81,7 +81,10 @@ void Application::registerLuaFunctions()
g_lua.registerSingletonClass("g_platform"); g_lua.registerSingletonClass("g_platform");
g_lua.bindSingletonFunction("g_platform", "spawnProcess", &Platform::spawnProcess, &g_platform); g_lua.bindSingletonFunction("g_platform", "spawnProcess", &Platform::spawnProcess, &g_platform);
g_lua.bindSingletonFunction("g_platform", "getProcessId", &Platform::getProcessId, &g_platform); g_lua.bindSingletonFunction("g_platform", "getProcessId", &Platform::getProcessId, &g_platform);
g_lua.bindSingletonFunction("g_platform", "isProcessRunning", &Platform::isProcessRunning, &g_platform);
g_lua.bindSingletonFunction("g_platform", "copyFile", &Platform::copyFile, &g_platform); g_lua.bindSingletonFunction("g_platform", "copyFile", &Platform::copyFile, &g_platform);
g_lua.bindSingletonFunction("g_platform", "fileExists", &Platform::fileExists, &g_platform);
g_lua.bindSingletonFunction("g_platform", "killProcess", &Platform::killProcess, &g_platform);
g_lua.bindSingletonFunction("g_platform", "getTempPath", &Platform::getTempPath, &g_platform); g_lua.bindSingletonFunction("g_platform", "getTempPath", &Platform::getTempPath, &g_platform);
g_lua.bindSingletonFunction("g_platform", "openUrl", &Platform::openUrl, &g_platform); g_lua.bindSingletonFunction("g_platform", "openUrl", &Platform::openUrl, &g_platform);
g_lua.bindSingletonFunction("g_platform", "getCPUName", &Platform::getCPUName, &g_platform); g_lua.bindSingletonFunction("g_platform", "getCPUName", &Platform::getCPUName, &g_platform);

View File

@ -32,8 +32,11 @@ public:
void processArgs(std::vector<std::string>& args); void processArgs(std::vector<std::string>& args);
bool spawnProcess(const std::string& process, const std::vector<std::string>& args); bool spawnProcess(const std::string& process, const std::vector<std::string>& args);
int getProcessId(); int getProcessId();
bool isProcessRunning(const std::string& name);
bool killProcess(const std::string& name);
std::string getTempPath(); std::string getTempPath();
bool copyFile(std::string from, std::string to); bool copyFile(std::string from, std::string to);
bool fileExists(const std::string& file);
void openUrl(std::string url); void openUrl(std::string url);
std::string getCPUName(); std::string getCPUName();
double getTotalSystemMemory(); double getTotalSystemMemory();

View File

@ -64,6 +64,16 @@ int Platform::getProcessId()
return getpid(); return getpid();
} }
bool Platform::isProcessRunning(const std::string& name)
{
return false;
}
bool Platform::killProcess(const std::string& name)
{
return false;
}
std::string Platform::getTempPath() std::string Platform::getTempPath()
{ {
return "/tmp/"; return "/tmp/";
@ -74,6 +84,12 @@ bool Platform::copyFile(std::string from, std::string to)
return system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()) == 0; return system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()) == 0;
} }
bool Platform::fileExists(const std::string& file)
{
struct stat buffer;
return (stat(file.c_str(), &buffer) == 0);
}
void Platform::openUrl(std::string url) void Platform::openUrl(std::string url)
{ {
if(url.find("http://") == std::string::npos) if(url.find("http://") == std::string::npos)

View File

@ -61,6 +61,27 @@ int Platform::getProcessId()
return GetCurrentProcessId(); return GetCurrentProcessId();
} }
bool Platform::isProcessRunning(const std::string& name)
{
if(FindWindowA(name.c_str(), NULL) != NULL)
return true;
return false;
}
bool Platform::killProcess(const std::string& name)
{
HWND window = FindWindowA(name.c_str(), NULL);
if(window == NULL)
return false;
DWORD pid = GetProcessId(window);
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if(handle == NULL)
return false;
bool ok = TerminateProcess(handle, 1) != 0;
CloseHandle(handle);
return ok;
}
std::string Platform::getTempPath() std::string Platform::getTempPath()
{ {
wchar_t path[MAX_PATH]; wchar_t path[MAX_PATH];
@ -68,6 +89,13 @@ std::string Platform::getTempPath()
return stdext::utf16_to_utf8(path); return stdext::utf16_to_utf8(path);
} }
bool Platform::fileExists(const std::string& file)
{
std::wstring wfile = stdext::utf8_to_utf16(file);
DWORD dwAttrib = GetFileAttributesW(wfile.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
bool Platform::copyFile(std::string from, std::string to) bool Platform::copyFile(std::string from, std::string to)
{ {
boost::replace_all(from, "/", "\\"); boost::replace_all(from, "/", "\\");

View File

@ -27,8 +27,8 @@
#define AL_LIBTYPE_STATIC #define AL_LIBTYPE_STATIC
#include <AL/al.h> #include <al.h>
#include <AL/alc.h> #include <alc.h>
class SoundManager; class SoundManager;
class SoundSource; class SoundSource;