Properly link flecs library
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef FLECS_OS_API_BAKE_BAKE_CONFIG_H
|
||||
#define FLECS_OS_API_BAKE_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
#ifdef __BAKE__
|
||||
#include <bake_util.h>
|
||||
#endif
|
||||
|
||||
/* Convenience macro for exporting symbols */
|
||||
#ifndef flecs_os_api_bake_STATIC
|
||||
#if flecs_os_api_bake_EXPORTS && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
#define FLECS_OS_API_BAKE_API __declspec(dllexport)
|
||||
#elif flecs_os_api_bake_EXPORTS
|
||||
#define FLECS_OS_API_BAKE_API __attribute__((__visibility__("default")))
|
||||
#elif defined _MSC_VER
|
||||
#define FLECS_OS_API_BAKE_API __declspec(dllimport)
|
||||
#else
|
||||
#define FLECS_OS_API_BAKE_API
|
||||
#endif
|
||||
#else
|
||||
#define FLECS_OS_API_BAKE_API
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef FLECS_OS_API_BAKE_H
|
||||
#define FLECS_OS_API_BAKE_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "flecs-os_api-bake/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FLECS_OS_API_BAKE_API
|
||||
void bake_set_os_api(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
12
engine/libs/flecs/examples/os_api/bake/project.json
Normal file
12
engine/libs/flecs/examples/os_api/bake/project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "flecs.os_api.bake",
|
||||
"type": "package",
|
||||
"value": {
|
||||
"author": "Sander Mertens",
|
||||
"description": "Bake OS API implementation",
|
||||
"use": [
|
||||
"flecs",
|
||||
"bake.util"
|
||||
]
|
||||
}
|
||||
}
|
||||
176
engine/libs/flecs/examples/os_api/bake/src/main.c
Normal file
176
engine/libs/flecs/examples/os_api/bake/src/main.c
Normal file
@@ -0,0 +1,176 @@
|
||||
#include <flecs_os_api_bake.h>
|
||||
|
||||
static
|
||||
ecs_os_thread_t bake_thread_new(
|
||||
ecs_os_thread_callback_t callback,
|
||||
void *param)
|
||||
{
|
||||
return (ecs_os_thread_t)ut_thread_new(callback, param);
|
||||
}
|
||||
|
||||
static
|
||||
void* bake_thread_join(
|
||||
ecs_os_thread_t thread)
|
||||
{
|
||||
void *arg;
|
||||
ut_thread_join((ut_thread)thread, &arg);
|
||||
return arg;
|
||||
}
|
||||
|
||||
static
|
||||
int32_t bake_ainc(int32_t *value) {
|
||||
return ut_ainc(value);
|
||||
}
|
||||
|
||||
static
|
||||
int32_t bake_adec(int32_t *value) {
|
||||
return ut_adec(value);
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_mutex_t bake_mutex_new(void) {
|
||||
struct ut_mutex_s *m = ecs_os_malloc(sizeof(struct ut_mutex_s));
|
||||
ut_mutex_new(m);
|
||||
return (ecs_os_mutex_t)(uintptr_t)m;
|
||||
}
|
||||
|
||||
static
|
||||
void bake_mutex_free(ecs_os_mutex_t mutex) {
|
||||
ut_mutex_free((struct ut_mutex_s*)mutex);
|
||||
ecs_os_free((struct ut_mutex_s*)mutex);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_mutex_lock(ecs_os_mutex_t mutex) {
|
||||
ut_mutex_lock((struct ut_mutex_s*)mutex);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_mutex_unlock(ecs_os_mutex_t mutex) {
|
||||
ut_mutex_unlock((struct ut_mutex_s*)mutex);
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_cond_t bake_cond_new(void) {
|
||||
struct ut_cond_s *c = ecs_os_malloc(sizeof(struct ut_cond_s));
|
||||
ut_cond_new(c);
|
||||
return (ecs_os_cond_t)(uintptr_t)c;
|
||||
}
|
||||
|
||||
static
|
||||
void bake_cond_free(ecs_os_cond_t cond) {
|
||||
ut_cond_free((struct ut_cond_s *)cond);
|
||||
ecs_os_free((struct ut_cond_s *)cond);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_cond_signal(ecs_os_cond_t cond) {
|
||||
ut_cond_signal((struct ut_cond_s *)cond);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_cond_broadcast(ecs_os_cond_t cond) {
|
||||
ut_cond_broadcast((struct ut_cond_s *)cond);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_cond_wait(ecs_os_cond_t cond, ecs_os_mutex_t mutex) {
|
||||
ut_cond_wait((struct ut_cond_s *)cond, (struct ut_mutex_s *)mutex);
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_dl_t bake_dlopen(
|
||||
const char *dlname)
|
||||
{
|
||||
return (ecs_os_dl_t)ut_dl_open(dlname);
|
||||
}
|
||||
|
||||
static
|
||||
void bake_dlclose(
|
||||
ecs_os_dl_t dl)
|
||||
{
|
||||
ut_dl_close((ut_dl)dl);
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_proc_t bake_dlproc(
|
||||
ecs_os_dl_t dl,
|
||||
const char *procname)
|
||||
{
|
||||
ecs_os_proc_t result = (ecs_os_proc_t)ut_dl_proc((ut_dl)dl, procname);
|
||||
if (!result) {
|
||||
ut_raise();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
char* bake_module_to_dl(
|
||||
const char *module_id)
|
||||
{
|
||||
const char *result = ut_locate(module_id, NULL, UT_LOCATE_LIB);
|
||||
if (result) {
|
||||
return ut_strdup(result);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
char* bake_module_to_etc(
|
||||
const char *module_id)
|
||||
{
|
||||
const char *result = ut_locate(module_id, NULL, UT_LOCATE_ETC);
|
||||
if (result) {
|
||||
return ut_strdup(result);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void bake_init(void)
|
||||
{
|
||||
ut_init(NULL);
|
||||
if (ut_load_init(NULL, NULL, NULL, NULL)) {
|
||||
ecs_err("warning: failed to initialize package loader");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void bake_fini(void)
|
||||
{
|
||||
ut_deinit();
|
||||
}
|
||||
|
||||
void bake_set_os_api(void) {
|
||||
ecs_os_set_api_defaults();
|
||||
|
||||
ecs_os_api_t api = ecs_os_api;
|
||||
|
||||
api.init_ = bake_init;
|
||||
api.fini_ = bake_fini;
|
||||
api.thread_new_ = bake_thread_new;
|
||||
api.thread_join_ = bake_thread_join;
|
||||
api.task_new_ = bake_thread_new;
|
||||
api.task_join_ = bake_thread_join;
|
||||
api.ainc_ = bake_ainc;
|
||||
api.adec_ = bake_adec;
|
||||
api.mutex_new_ = bake_mutex_new;
|
||||
api.mutex_free_ = bake_mutex_free;
|
||||
api.mutex_lock_ = bake_mutex_lock;
|
||||
api.mutex_unlock_ = bake_mutex_unlock;
|
||||
api.cond_new_ = bake_cond_new;
|
||||
api.cond_free_ = bake_cond_free;
|
||||
api.cond_signal_ = bake_cond_signal;
|
||||
api.cond_broadcast_ = bake_cond_broadcast;
|
||||
api.cond_wait_ = bake_cond_wait;
|
||||
api.dlopen_ = bake_dlopen;
|
||||
api.dlproc_ = bake_dlproc;
|
||||
api.dlclose_ = bake_dlclose;
|
||||
api.module_to_dl_ = bake_module_to_dl;
|
||||
api.module_to_etc_ = bake_module_to_etc;
|
||||
|
||||
ecs_os_set_api(&api);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef FLECS_OS_API_STDCPP_BAKE_CONFIG_H
|
||||
#define FLECS_OS_API_STDCPP_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
/* Convenience macro for exporting symbols */
|
||||
#ifndef flecs_os_api_stdcpp_STATIC
|
||||
#if defined(flecs_os_api_stdcpp_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||
#define FLECS_OS_API_STDCPP_API __declspec(dllexport)
|
||||
#elif defined(flecs_os_api_stdcpp_EXPORTS)
|
||||
#define FLECS_OS_API_STDCPP_API __attribute__((__visibility__("default")))
|
||||
#elif defined(_MSC_VER)
|
||||
#define FLECS_OS_API_STDCPP_API __declspec(dllimport)
|
||||
#else
|
||||
#define FLECS_OS_API_STDCPP_API
|
||||
#endif
|
||||
#else
|
||||
#define FLECS_OS_API_STDCPP_API
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef FLECS_OS_API_STDCPP_H
|
||||
#define FLECS_OS_API_STDCPP_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "flecs-os_api-stdcpp/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FLECS_OS_API_STDCPP_API
|
||||
extern void stdcpp_set_os_api(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
17
engine/libs/flecs/examples/os_api/stdcpp/project.json
Normal file
17
engine/libs/flecs/examples/os_api/stdcpp/project.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"id": "flecs.os_api.stdcpp",
|
||||
"type": "package",
|
||||
"value": {
|
||||
"author": "mclevi",
|
||||
"description": "C++ OS API implementation",
|
||||
"language": "c++",
|
||||
"use": [
|
||||
"flecs"
|
||||
]
|
||||
},
|
||||
"lang.cpp": {
|
||||
"${os linux}": {
|
||||
"lib": ["pthread"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "flecs_os_api_stdcpp.h"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <WinSock2.h>
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
static
|
||||
ecs_os_thread_t stdcpp_thread_new(
|
||||
ecs_os_thread_callback_t callback,
|
||||
void *arg)
|
||||
{
|
||||
std::thread *thread = new std::thread{callback,arg};
|
||||
return reinterpret_cast<ecs_os_thread_t>(thread);
|
||||
}
|
||||
|
||||
static
|
||||
void* stdcpp_thread_join(
|
||||
ecs_os_thread_t thread)
|
||||
{
|
||||
void *arg = nullptr;
|
||||
std::thread *thr = reinterpret_cast<std::thread*>(thread);
|
||||
thr->join();
|
||||
delete thr;
|
||||
return arg;
|
||||
}
|
||||
|
||||
static
|
||||
int32_t stdcpp_ainc(int32_t *count) {
|
||||
#ifdef __GNUC__
|
||||
int value = __sync_add_and_fetch (count, 1);
|
||||
return value;
|
||||
#else
|
||||
return InterlockedIncrement((uint32_t*)count);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
int32_t stdcpp_adec(int32_t *count) {
|
||||
#ifdef __GNUC__
|
||||
int value = __sync_sub_and_fetch (count, 1);
|
||||
return value;
|
||||
#else
|
||||
return InterlockedDecrement((uint32_t*)count);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_mutex_t stdcpp_mutex_new(void) {
|
||||
std::mutex *mutex = new std::mutex;
|
||||
return reinterpret_cast<ecs_os_mutex_t>(mutex);
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_mutex_free(ecs_os_mutex_t m) {
|
||||
std::mutex*mutex = reinterpret_cast<std::mutex*>(m);
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_mutex_lock(ecs_os_mutex_t m) {
|
||||
std::mutex*mutex = reinterpret_cast<std::mutex*>(m);
|
||||
mutex->lock();
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_mutex_unlock(ecs_os_mutex_t m) {
|
||||
std::mutex *mutex = reinterpret_cast<std::mutex*>(m);
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
static
|
||||
ecs_os_cond_t stdcpp_cond_new(void) {
|
||||
std::condition_variable_any* cond = new std::condition_variable_any{};
|
||||
return reinterpret_cast<ecs_os_cond_t>(cond);
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_cond_free(ecs_os_cond_t c) {
|
||||
std::condition_variable_any *cond = reinterpret_cast<std::condition_variable_any*>(c);
|
||||
delete cond;
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_cond_signal(ecs_os_cond_t c) {
|
||||
std::condition_variable_any *cond = reinterpret_cast<std::condition_variable_any*>(c);
|
||||
cond->notify_one();
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_cond_broadcast(ecs_os_cond_t c) {
|
||||
std::condition_variable_any*cond = reinterpret_cast<std::condition_variable_any*>(c);
|
||||
cond->notify_all();
|
||||
}
|
||||
|
||||
static
|
||||
void stdcpp_cond_wait(ecs_os_cond_t c, ecs_os_mutex_t m) {
|
||||
std::condition_variable_any* cond = reinterpret_cast<std::condition_variable_any*>(c);
|
||||
std::mutex* mutex = reinterpret_cast<std::mutex*>(m);
|
||||
cond->wait(*mutex);
|
||||
}
|
||||
|
||||
void stdcpp_set_os_api(void) {
|
||||
ecs_os_set_api_defaults();
|
||||
|
||||
ecs_os_api_t api = ecs_os_api;
|
||||
|
||||
api.thread_new_ = stdcpp_thread_new;
|
||||
api.thread_join_ = stdcpp_thread_join;
|
||||
api.task_new_ = stdcpp_thread_new;
|
||||
api.task_join_ = stdcpp_thread_join;
|
||||
api.ainc_ = stdcpp_ainc;
|
||||
api.adec_ = stdcpp_adec;
|
||||
api.mutex_new_ = stdcpp_mutex_new;
|
||||
api.mutex_free_ = stdcpp_mutex_free;
|
||||
api.mutex_lock_ = stdcpp_mutex_lock;
|
||||
api.mutex_unlock_ = stdcpp_mutex_unlock;
|
||||
api.cond_new_ = stdcpp_cond_new;
|
||||
api.cond_free_ = stdcpp_cond_free;
|
||||
api.cond_signal_ = stdcpp_cond_signal;
|
||||
api.cond_broadcast_ = stdcpp_cond_broadcast;
|
||||
api.cond_wait_ = stdcpp_cond_wait;
|
||||
|
||||
ecs_os_set_api(&api);
|
||||
}
|
||||
Reference in New Issue
Block a user