This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from flecs-hub/examples
Hello world example
- Loading branch information
Showing
22 changed files
with
1,257 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "ext/flecs"] | ||
path = ext/flecs | ||
url = https://github.com/SanderMertens/flecs | ||
[submodule "ext/scripts"] | ||
path = ext/scripts | ||
url = https://github.com/bottlenoselabs/scripts.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule flecs
updated
16 files
+33,766 −33,819 | flecs.c | |
+0 −4 | flecs.h | |
+0 −4 | include/flecs/addons/log.h | |
+41 −76 | src/addons/pipeline/pipeline.c | |
+11 −11 | src/addons/pipeline/pipeline.h | |
+30 −47 | src/addons/pipeline/worker.c | |
+4 −10 | src/addons/system/system.c | |
+18 −18 | src/entity.c | |
+1 −2 | src/query.c | |
+83 −74 | src/stage.c | |
+2 −2 | src/stage.h | |
+2 −5 | src/world.c | |
+1 −2 | test/addons/project.json | |
+0 −30 | test/addons/src/MultiThread.c | |
+0 −4 | test/addons/src/Parser.c | |
+1 −6 | test/addons/src/main.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,10 @@ | ||
#!/bin/bash | ||
# NOTE: This script builds a target C/C++ library using CMake as a shared library (`.dll`/`.so`/`.dylib`) for the purposes of P/Invoke with C#. | ||
# INPUT: | ||
# $1: The target operating system to build the shared library for. Possible values are "host", "windows", "linux", "macos". | ||
# $2: The taget architecture to build the shared library for. Possible values are "default", "x86_64", "arm64". | ||
# OUTPUT: The built shared library if successful, or nothing upon first failure. | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
echo "Started building native libraries... Directory: $DIR" | ||
LIB_DIR="$DIR/lib" | ||
mkdir -p $LIB_DIR | ||
echo "Started '$0' $1 $2 $3 $4" | ||
|
||
if [[ ! -z "$1" ]]; then | ||
TARGET_BUILD_OS="$1" | ||
fi | ||
|
||
if [[ ! -z "$2" ]]; then | ||
TARGET_BUILD_ARCH="$2" | ||
fi | ||
|
||
function set_target_build_os { | ||
if [[ -z "$TARGET_BUILD_OS" || $TARGET_BUILD_OS == "host" ]]; then | ||
uname_str="$(uname -a)" | ||
case "${uname_str}" in | ||
*Microsoft*) TARGET_BUILD_OS="windows";; | ||
*microsoft*) TARGET_BUILD_OS="windows";; | ||
Linux*) TARGET_BUILD_OS="linux";; | ||
Darwin*) TARGET_BUILD_OS="macos";; | ||
CYGWIN*) TARGET_BUILD_OS="linux";; | ||
MINGW*) TARGET_BUILD_OS="windows";; | ||
*Msys) TARGET_BUILD_OS="windows";; | ||
*) TARGET_BUILD_OS="UNKNOWN:${uname_str}" | ||
esac | ||
|
||
if [[ | ||
"$TARGET_BUILD_OS" != "windows" && | ||
"$TARGET_BUILD_OS" != "macos" && | ||
"$TARGET_BUILD_OS" != "linux" | ||
]]; then | ||
echo "Unknown target build operating system: $TARGET_BUILD_OS" | ||
exit 1 | ||
fi | ||
|
||
echo "Target build operating system: '$TARGET_BUILD_OS' (host)" | ||
else | ||
if [[ | ||
"$TARGET_BUILD_OS" == "windows" || | ||
"$TARGET_BUILD_OS" == "macos" || | ||
"$TARGET_BUILD_OS" == "linux" | ||
]]; then | ||
echo "Target build operating system: '$TARGET_BUILD_OS' (override)" | ||
else | ||
echo "Unknown '$TARGET_BUILD_OS' passed as first argument. Use 'host' to use the host build platform or use either: 'windows', 'macos', 'linux'." | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
function set_target_build_arch { | ||
if [[ -z "$TARGET_BUILD_ARCH" || $TARGET_BUILD_ARCH == "default" ]]; then | ||
if [[ "$TARGET_BUILD_OS" == "macos" ]]; then | ||
TARGET_BUILD_ARCH="x86_64;arm64" | ||
else | ||
TARGET_BUILD_ARCH="$(uname -m)" | ||
fi | ||
|
||
echo "Target build CPU architecture: '$TARGET_BUILD_ARCH' (default)" | ||
else | ||
if [[ "$TARGET_BUILD_ARCH" == "x86_64" || "$TARGET_BUILD_ARCH" == "arm64" ]]; then | ||
echo "Target build CPU architecture: '$TARGET_BUILD_ARCH' (override)" | ||
else | ||
echo "Unknown '$TARGET_BUILD_ARCH' passed as second argument. Use 'default' to use the host CPU architecture or use either: 'x86_64', 'arm64'." | ||
exit 1 | ||
fi | ||
fi | ||
if [[ "$TARGET_BUILD_OS" == "macos" ]]; then | ||
CMAKE_ARCH_ARGS="-DCMAKE_OSX_ARCHITECTURES=$TARGET_BUILD_ARCH" | ||
fi | ||
} | ||
|
||
set_target_build_os | ||
set_target_build_arch | ||
|
||
function exit_if_last_command_failed() { | ||
error=$? | ||
if [ $error -ne 0 ]; then | ||
echo "Last command failed: $error" | ||
exit $error | ||
fi | ||
} | ||
|
||
function build_library() { | ||
echo "Building native library..." | ||
BUILD_DIR="$DIR/cmake-build-release" | ||
rm -rf BUILD_DIR | ||
|
||
cmake -S $DIR/ext/flecs -B $BUILD_DIR $CMAKE_ARCH_ARGS \ | ||
`# change output directories` \ | ||
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=$BUILD_DIR -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$BUILD_DIR -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$BUILD_DIR -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=$BUILD_DIR \ | ||
`# project specific` \ | ||
-DFLECS_STATIC_LIBS=OFF | ||
exit_if_last_command_failed | ||
cmake --build $BUILD_DIR --config Release | ||
exit_if_last_command_failed | ||
|
||
if [[ "$TARGET_BUILD_OS" == "linux" ]]; then | ||
LIBRARY_FILENAME="libflecs.so" | ||
LIBRARY_FILE_PATH_BUILD="$(readlink -f $BUILD_DIR/$LIBRARY_FILENAME)" | ||
elif [[ "$TARGET_BUILD_OS" == "macos" ]]; then | ||
LIBRARY_FILENAME="libflecs.dylib" | ||
LIBRARY_FILE_PATH_BUILD="$(perl -MCwd -e 'print Cwd::abs_path shift' $BUILD_DIR/$LIBRARY_FILENAME)" | ||
elif [[ "$TARGET_BUILD_OS" == "windows" ]]; then | ||
LIBRARY_FILENAME="flecs.dll" | ||
LIBRARY_FILE_PATH_BUILD="$BUILD_DIR/$LIBRARY_FILENAME" | ||
fi | ||
LIBRARY_FILE_PATH="$LIB_DIR/$LIBRARY_FILENAME" | ||
|
||
if [[ ! -f "$LIBRARY_FILE_PATH_BUILD" ]]; then | ||
echo "The file '$LIBRARY_FILE_PATH_BUILD' does not exist!" | ||
exit 1 | ||
fi | ||
|
||
mv "$LIBRARY_FILE_PATH_BUILD" "$LIBRARY_FILE_PATH" | ||
exit_if_last_command_failed | ||
echo "Copied '$LIBRARY_FILE_PATH_BUILD' to '$LIBRARY_FILE_PATH'" | ||
|
||
rm -r $BUILD_DIR | ||
exit_if_last_command_failed | ||
echo "Building native library finished!" | ||
} | ||
|
||
build_library | ||
ls -d "$LIB_DIR"/* | ||
|
||
echo "Finished '$0'!" | ||
$DIR/ext/scripts/c/library/main.sh \ | ||
$DIR/src/c/production/flecs \ | ||
$DIR/lib \ | ||
"flecs" \ | ||
"flecs" \ | ||
"" \ | ||
"" \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(flecs C) | ||
set(CMAKE_C_STANDARD 11) | ||
|
||
get_filename_component(FLECS_DIRECTORY_PATH "../../../../ext/flecs" REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
include(${FLECS_DIRECTORY_PATH}/cmake/target_default_compile_warnings.cmake) | ||
include(${FLECS_DIRECTORY_PATH}/cmake/target_default_compile_options.cmake) | ||
file(GLOB_RECURSE INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${FLECS_DIRECTORY_PATH}/include/*.h) | ||
file(GLOB_RECURSE SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c ${FLECS_DIRECTORY_PATH}/src/*.c) | ||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${FLECS_DIRECTORY_PATH}/include) | ||
|
||
message("FILES: ${INC} ${SRC}") | ||
|
||
add_library(flecs SHARED ${INC} ${SRC}) | ||
|
||
set_target_properties(flecs PROPERTIES LINKER_LANGUAGE C) | ||
|
||
if(WIN32) | ||
target_link_libraries(flecs wsock32 ws2_32) | ||
endif() | ||
|
||
#target_default_compile_options_c(flecs) | ||
#target_default_compile_warnings_c(flecs) | ||
#target_include_directories(flecs PUBLIC ${FLECS_DIRECTORY_PATH}/include ${CMAKE_CURRENT_SOURCE_DIR}/include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "pinvoke.h" | ||
#include "flecs.h" | ||
|
||
PINVOKE_API_DECL ecs_id_t pinvoke_ECS_PAIR(); | ||
PINVOKE_API_DECL ecs_entity_t pinvoke_EcsOnUpdate(); | ||
PINVOKE_API_DECL ecs_entity_t pinvoke_EcsDependsOn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Provides macros, types, and functions that make P/Invoke with C# easier. | ||
#pragma once | ||
|
||
#if defined(__APPLE__) && __has_include("TargetConditionals.h") | ||
#include <TargetConditionals.h> | ||
|
||
#define PINVOKE_TARGET_CPU_X64 TARGET_CPU_X86_64 | ||
#define PINVOKE_TARGET_CPU_X86 TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_CPU_ARM64 TARGET_CPU_ARM64 | ||
|
||
#define PINVOKE_TARGET_OS_WINDOWS 0 | ||
#define PINVOKE_TARGET_OS_LINUX 0 | ||
#define PINVOKE_TARGET_OS_MACOS TARGET_OS_OSX | ||
#define PINVOKE_TARGET_OS_IOS TARGET_OS_IOS | ||
|
||
#define PINVOKE_TARGET_ENV_MSVC 0 | ||
#define PINVOKE_TARGET_ENV_GNU 0 | ||
#else | ||
#define PINVOKE_TARGET_CPU_X64 defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) | ||
#define PINVOKE_TARGET_CPU_X86 defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) | ||
#define PINVOKE_TARGET_CPU_ARM64 defined(__aarch64__) || defined(_M_ARM64) | ||
|
||
#define PINVOKE_TARGET_OS_WINDOWS defined(WIN32) || defined(_WIN32) || defined(__WIN32__) | ||
#define PINVOKE_TARGET_OS_LINUX defined(__linux__) | ||
#define PINVOKE_TARGET_OS_MACOS 0 | ||
#define PINVOKE_TARGET_OS_IOS 0 | ||
|
||
#define PINVOKE_TARGET_ENV_MSVC defined(_MSC_VER) | ||
#define PINVOKE_TARGET_ENV_GNU defined(__GNUC__) | ||
#endif | ||
|
||
#if PINVOKE_TARGET_OS_WINDOWS && PINVOKE_TARGET_ENV_GNU | ||
#if PINVOKE_TARGET_CPU_X64 | ||
#define PINVOKE_TARGET_NAME "x86_64-pc-windows-gnu" | ||
#elif PINVOKE_TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_NAME "i686-pc-windows-gnu" | ||
#elif PINVOKE_TARGET_CPU_ARM64 | ||
#define PINVOKE_TARGET_NAME "aarch64-pc-windows-gnu" | ||
#else | ||
#error "Unknown computer architecture for Windows (GNU)." | ||
#endif | ||
#elif PINVOKE_TARGET_OS_WINDOWS && PINVOKE_TARGET_ENV_MSVC | ||
#if PINVOKE_TARGET_CPU_X64 | ||
#define PINVOKE_TARGET_NAME "x86_64-pc-windows-msvc" | ||
#elif PINVOKE_TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_NAME "i686-pc-windows-msvc" | ||
#elif PINVOKE_TARGET_CPU_ARM64 | ||
#define PINVOKE_TARGET_NAME "aarch64-pc-windows-msvc" | ||
#else | ||
#error "Unknown computer architecture for Windows (Microsoft Visual C++)." | ||
#endif | ||
#elif PINVOKE_TARGET_OS_LINUX | ||
#if PINVOKE_TARGET_CPU_X64 | ||
#define PINVOKE_TARGET_NAME "x86_64-unknown-linux-gnu" | ||
#elif PINVOKE_TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_NAME "i686-unknown-linux-gnu" | ||
#elif PINVOKE_TARGET_CPU_ARM64 | ||
#define PINVOKE_TARGET_NAME "aarch64-unknown-linux-gnu" | ||
#else | ||
#error "Unknown computer architecture for Linux." | ||
#endif | ||
#elif PINVOKE_TARGET_OS_MACOS | ||
#if PINVOKE_TARGET_CPU_X64 | ||
#define PINVOKE_TARGET_NAME "x86_64-apple-darwin" | ||
#elif PINVOKE_TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_NAME "i686-apple-darwin" | ||
#elif PINVOKE_TARGET_CPU_ARM64 | ||
#define PINVOKE_TARGET_NAME "aarch64-apple-darwin" | ||
#else | ||
#error "Unknown computer architecture for macOS." | ||
#endif | ||
#elif PINVOKE_TARGET_OS_IOS | ||
#if PINVOKE_TARGET_CPU_X64 | ||
#define PINVOKE_TARGET_NAME "x86_64-apple-ios" | ||
#elif PINVOKE_TARGET_CPU_X86 | ||
#define PINVOKE_TARGET_NAME "i686-apple-ios" | ||
#elif PINVOKE_TARGET_CPU_ARM64 | ||
#define PINVOKE_TARGET_NAME "aarch64-apple-ios" | ||
#else | ||
#error "Unknown computer architecture for iOS." | ||
#endif | ||
#else | ||
#define PINVOKE_TARGET_NAME 0 | ||
#endif | ||
|
||
#if PINVOKE_TARGET_OS_WINDOWS | ||
#define PINVOKE_API_DECL __declspec(dllexport) | ||
#else | ||
#define PINVOKE_API_DECL extern | ||
#endif | ||
|
||
PINVOKE_API_DECL const char* pinvoke_get_platform_name() | ||
{ | ||
return PINVOKE_TARGET_NAME; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "pinvoke.h" | ||
#include "flecs.h" | ||
|
||
ecs_id_t pinvoke_ECS_PAIR() | ||
{ | ||
return ECS_PAIR; | ||
} | ||
|
||
ecs_entity_t pinvoke_EcsOnUpdate() | ||
{ | ||
return EcsOnUpdate; | ||
} | ||
|
||
ecs_entity_t pinvoke_EcsDependsOn() | ||
{ | ||
return EcsDependsOn; | ||
} |
Oops, something went wrong.