2011-12-23 22:58:50 +00:00
|
|
|
#ifndef _PAYSAGES_SYSTEM_H_
|
|
|
|
#define _PAYSAGES_SYSTEM_H_
|
|
|
|
|
2012-07-19 15:04:27 +00:00
|
|
|
/* Library dependent features */
|
|
|
|
|
2013-01-19 22:42:50 +00:00
|
|
|
#include "tools/color.h"
|
2012-11-10 17:05:01 +00:00
|
|
|
#include <stdlib.h>
|
2012-07-19 15:04:27 +00:00
|
|
|
|
2011-12-23 22:58:50 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-07-19 15:04:27 +00:00
|
|
|
typedef void* (*ThreadFunction)(void* data);
|
|
|
|
typedef Color (*PictureCallbackSavePixel)(void* data, int x, int y);
|
|
|
|
typedef void (*PictureCallbackLoadStarted)(void* data, int width, int height);
|
|
|
|
typedef void (*PictureCallbackLoadPixel)(void* data, int x, int y, Color col);
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
void systemInit();
|
|
|
|
int systemGetCoreCount();
|
2012-01-07 16:53:23 +00:00
|
|
|
|
2012-07-19 15:04:27 +00:00
|
|
|
int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height);
|
|
|
|
int systemLoadPictureFile(const char* filepath, PictureCallbackLoadStarted callback_start, PictureCallbackLoadPixel callback_pixel, void* data);
|
|
|
|
|
2012-12-01 16:39:47 +00:00
|
|
|
int systemGetFileSize(const char* path);
|
|
|
|
|
2012-07-01 13:27:57 +00:00
|
|
|
#ifdef HAVE_GLIB
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
typedef GThread Thread;
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
static inline Thread* threadCreate(ThreadFunction function, void* data)
|
|
|
|
{
|
2012-11-10 17:05:01 +00:00
|
|
|
#ifdef GLIB_VERSION_2_32
|
|
|
|
return g_thread_new("thread", (GThreadFunc)function, data);
|
|
|
|
#else
|
2011-12-10 13:25:22 +00:00
|
|
|
GError* error;
|
|
|
|
return g_thread_create((GThreadFunc)function, data, 1, &error);
|
2012-11-10 17:05:01 +00:00
|
|
|
#endif
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void* threadJoin(Thread* thread)
|
|
|
|
{
|
|
|
|
return g_thread_join(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef GMutex Mutex;
|
|
|
|
|
|
|
|
static inline Mutex* mutexCreate()
|
|
|
|
{
|
2012-11-10 17:05:01 +00:00
|
|
|
#ifdef GLIB_VERSION_2_32
|
|
|
|
Mutex* mutex = malloc(sizeof(Mutex));
|
|
|
|
g_mutex_init(mutex);
|
|
|
|
return mutex;
|
|
|
|
#else
|
2011-12-10 13:25:22 +00:00
|
|
|
return g_mutex_new();
|
2012-11-10 17:05:01 +00:00
|
|
|
#endif
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mutexDestroy(Mutex* mutex)
|
|
|
|
{
|
2012-11-10 17:05:01 +00:00
|
|
|
#ifdef GLIB_VERSION_2_32
|
|
|
|
g_mutex_clear(mutex);
|
|
|
|
free(mutex);
|
|
|
|
#else
|
2011-12-10 13:25:22 +00:00
|
|
|
g_mutex_free(mutex);
|
2012-11-10 17:05:01 +00:00
|
|
|
#endif
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mutexAcquire(Mutex* mutex)
|
|
|
|
{
|
|
|
|
g_mutex_lock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mutexRelease(Mutex* mutex)
|
|
|
|
{
|
|
|
|
g_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void timeSleepMs(unsigned long ms)
|
|
|
|
{
|
|
|
|
g_usleep(ms * 1000);
|
|
|
|
}
|
2012-07-01 13:27:57 +00:00
|
|
|
#endif
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2011-12-23 22:58:50 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|