#include <sys.hpp>
#include <stdio.h>
#include <stdarg.h>
#ifdef TCOD_OSUTIL_SUPPORT
void TCODSystem::sleepMilli(uint32_t milliseconds) {
TCOD_sys_sleep_milli(milliseconds);
}
uint32_t TCODSystem::getElapsedMilli() {
return TCOD_sys_elapsed_milli();
}
float TCODSystem::getElapsedSeconds() {
return TCOD_sys_elapsed_seconds();
}
#endif
#ifdef TCOD_SDL2
void TCODSystem::saveScreenshot(const char *filename) {
TCOD_sys_save_screenshot(filename);
}
void TCODSystem::forceFullscreenResolution(int width, int height) {
TCOD_sys_force_fullscreen_resolution(width, height);
}
void TCODSystem::setRenderer(TCOD_renderer_t renderer) {
TCOD_sys_set_renderer(renderer);
}
TCOD_event_t TCODSystem::waitForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush) {
return TCOD_sys_wait_for_event(eventMask,key,mouse,flush);
}
TCOD_event_t TCODSystem::checkForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse) {
return TCOD_sys_check_for_event(eventMask,key,mouse);
}
TCOD_renderer_t TCODSystem::getRenderer() {
return TCOD_sys_get_renderer();
}
#endif
#ifdef TCOD_OSUTIL_SUPPORT
void TCODSystem::setFps(int val) {
TCOD_sys_set_fps(val);
}
int TCODSystem::getFps() {
return TCOD_sys_get_fps();
}
float TCODSystem::getLastFrameLength() {
return TCOD_sys_get_last_frame_length();
}
#endif
#ifdef TCOD_SDL2
void TCODSystem::getCurrentResolution(int *w, int *h) {
TCOD_sys_get_current_resolution(w, h);
}
void TCODSystem::getFullscreenOffsets(int *offx, int *offy) {
TCOD_sys_get_fullscreen_offsets(offx, offy);
}
void TCODSystem::updateChar(int asciiCode, int fontx, int fonty,const TCODImage *img,int x,int y) {
TCOD_sys_update_char(asciiCode,fontx,fonty,img->data,x,y);
}
void TCODSystem::getCharSize(int *w, int *h) {
TCOD_sys_get_char_size(w, h);
}
#endif
bool TCODSystem::createDirectory(const char *path) {
return TCOD_sys_create_directory(path) != 0;
}
bool TCODSystem::deleteFile(const char *path) {
return TCOD_sys_delete_file(path) != 0;
}
bool TCODSystem::deleteDirectory(const char *path) {
return TCOD_sys_delete_directory(path) != 0;
}
bool TCODSystem::isDirectory(const char *path) {
return TCOD_sys_is_directory(path) != 0;
}
TCOD_list_t TCODSystem::getDirectoryContent(const char *path, const char *pattern) {
return TCOD_sys_get_directory_content(path,pattern);
}
bool TCODSystem::fileExists(const char * filename, ...) {
FILE * in;
bool ret = false;
char f[1024];
va_list ap;
va_start(ap,filename);
vsprintf(f,filename,ap);
va_end(ap);
in = fopen(f,"rb");
if (in != NULL) {
ret = true;
fclose(in);
}
return ret;
}
bool TCODSystem::readFile(const char *filename, unsigned char **buf, size_t *size) {
return TCOD_sys_read_file(filename,buf,size) != 0;
}
bool TCODSystem::writeFile(const char *filename, unsigned char *buf, uint32_t size) {
return TCOD_sys_write_file(filename,buf,size) != 0;
}
#ifdef TCOD_SDL2
bool TCODSystem::setClipboard(const char *value) {
return TCOD_sys_clipboard_set(value) != 0;
}
char *TCODSystem::getClipboard() {
return TCOD_sys_clipboard_get();
}
#endif
int TCODSystem::getNumCores() {
return TCOD_sys_get_num_cores();
}
TCOD_thread_t TCODSystem::newThread(int (*func)(void *), void *data) {
return TCOD_thread_new(func,data);
}
void TCODSystem::deleteThread(TCOD_thread_t th) {
TCOD_thread_delete(th);
}
void TCODSystem::waitThread(TCOD_thread_t th) {
TCOD_thread_wait(th);
}
TCOD_mutex_t TCODSystem::newMutex() {
return TCOD_mutex_new();
}
void TCODSystem::mutexIn(TCOD_mutex_t mut) {
TCOD_mutex_in(mut);
}
void TCODSystem::mutexOut(TCOD_mutex_t mut) {
TCOD_mutex_out(mut);
}
void TCODSystem::deleteMutex(TCOD_mutex_t mut) {
TCOD_mutex_delete(mut);
}
TCOD_semaphore_t TCODSystem::newSemaphore(int initVal) {
return TCOD_semaphore_new(initVal);
}
void TCODSystem::lockSemaphore(TCOD_semaphore_t sem) {
TCOD_semaphore_lock(sem);
}
void TCODSystem::unlockSemaphore(TCOD_semaphore_t sem) {
TCOD_semaphore_unlock(sem);
}
void TCODSystem::deleteSemaphore( TCOD_semaphore_t sem) {
TCOD_semaphore_delete(sem);
}
TCOD_cond_t TCODSystem::newCondition() {
return TCOD_condition_new();
}
void TCODSystem::signalCondition(TCOD_cond_t cond) {
TCOD_condition_signal(cond);
}
void TCODSystem::broadcastCondition(TCOD_cond_t cond) {
TCOD_condition_broadcast(cond);
}
void TCODSystem::waitCondition(TCOD_cond_t cond, TCOD_mutex_t mut) {
TCOD_condition_wait(cond, mut);
}
void TCODSystem::deleteCondition( TCOD_cond_t cond) {
TCOD_condition_delete(cond);
}
static ITCODSDLRenderer *renderer=NULL;
extern "C" void TCOD_CRenderer(void *sdl_surface) {
if ( renderer ) renderer->render(sdl_surface);
}
void TCODSystem::registerSDLRenderer(ITCODSDLRenderer *renderer) {
::renderer = renderer;
#ifdef TCOD_SDL2
TCOD_sys_register_SDL_renderer(TCOD_CRenderer);
#endif
}