Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [1.2.0] - 2023-04-24
- Add plugin API support to allow users to extend the application with their own code.

## [1.1.2] - 2023-04-23
- Add `system_save_file_dialog` on OSX
- Fix `build_setting` bash function on OSX
- Fix `MEM_DELETE` when pointer is null
- Fix OSX compilation issues
- Improve `./run` script
- Remove `FOUNDATION_CONSTCALL` usage which is causing issues on OSX

## [1.1.1] - 2023-04-22
- Add `./run package` (through `build-package.sh`) script to build and package the library for distribution.
- Add `BUILD_ENABLE_BACKEND` build switch
Expand Down
50 changes: 43 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Root directory path")
# Set build output dir
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build CACHE PATH "Build directory path")

# Set plugins dir path
set(PLUGINS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plugins CACHE PATH "Plugins directory path")

# Set plugin build output dir
set(PLUGIN_BUILD_DIR ${BUILD_DIR}/plugins CACHE PATH "Build plugins path")

# Cache the shared module path
# Then each nested CMakeLists.txt can include the shared.cmake file using the following command:
# include(${SHARED_MODULE_PATH})
Expand Down Expand Up @@ -248,7 +254,17 @@ if(MSVC)
# Set /OPT:REF for static libraries as well
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")

elseif(XCODE)
# Set DLL output build directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEPLOY ${BUILD_DIR})

# Set PDB output build directory
set(CMAKE_PDB_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIR})
set(CMAKE_PDB_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIR})
set(CMAKE_PDB_OUTPUT_DIRECTORY_DEPLOY ${BUILD_DIR})

elseif(APPLE)

# Use fast floating point math
add_compile_options(-ffast-math)
Expand Down Expand Up @@ -286,6 +302,9 @@ elseif(XCODE)
add_compile_options(-Wno-tautological-constant-compare -Wno-unguarded-availability-new)
endif()

# Define -Wno-varargs
add_compile_options(-Wno-varargs)

endif()

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_FLAGS_RELEASE}")
Expand All @@ -298,6 +317,12 @@ set(CMAKE_CXX_FLAGS_DEPLOY "${CMAKE_CXX_FLAGS_DEPLOY} ${CMAKE_CXX_FLAGS_RELEASE}
# Copy release linker flags to deploy
set(CMAKE_EXE_LINKER_FLAGS_DEPLOY "${CMAKE_EXE_LINKER_FLAGS_DEPLOY} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")

if (MSVC)
# Generate PDB files for debug and release builds
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Load BX library
Expand Down Expand Up @@ -330,9 +355,20 @@ endif()
# Load main exectuable project under sources/
add_subdirectory(${ROOT_DIR}/sources)

# Add subdirectories for all cmakelist under tools/
file(GLOB_RECURSE CMAKE_LISTS ${ROOT_DIR}/tools/*CMakeLists.txt)
foreach(CMAKE_LIST ${CMAKE_LISTS})
get_filename_component(CMAKE_LIST_DIR ${CMAKE_LIST} DIRECTORY)
add_subdirectory(${CMAKE_LIST_DIR})
endforeach()
if (BUILD_ENABLE_TOOLS)
# Add subdirectories for all cmakelists under tools/
file(GLOB_RECURSE TOOLS_LISTS ${ROOT_DIR}/tools/*CMakeLists.txt)
foreach(CMAKE_LIST ${TOOLS_LISTS})
get_filename_component(CMAKE_LIST_DIR ${CMAKE_LIST} DIRECTORY)
add_subdirectory(${CMAKE_LIST_DIR})
endforeach()
endif()

if (BUILD_ENABLE_PLUGINS)
# Add subdirectories for all cmakelists under plugins/
file(GLOB_RECURSE PLUGINS_LISTS ${ROOT_DIR}/plugins/*CMakeLists.txt)
foreach(CMAKE_LIST ${PLUGINS_LISTS})
get_filename_component(CMAKE_LIST_DIR ${CMAKE_LIST} DIRECTORY)
add_subdirectory(${CMAKE_LIST_DIR})
endforeach()
endif()
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ Then you usually want to start editing sources under `sources/`. As a starting p

Basically, you need to have a `cpp` file that implements minimally the following functions:
- `app_title` - Returns the application title.
- `app_exception_handler` - Defines how the application handles crashes.
- `app_configure` - Defines how the application and foundation is configured.
- `app_initialize` - Defines how the application is initialized (i.e. initialize services and modules once, etc).
- `app_shutdown` - Defines how the application is finalized (i.e. shutdown services and modules once, etc).
- `app_update` - Defines how the application is updated prior to render each frames.
- `app_render` - Defines how the application is rendered each frame.
- `app_render_3rdparty_libs` - Entry point to render additional 3rd party libraries used for your specific application.

### Build and run

Expand Down
4 changes: 3 additions & 1 deletion config/build.settings
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PRODUCT_URL=https://equals-forty-two.com
# Version info
VERSION_MAJOR=1
VERSION_MINOR=1
VERSION_PATCH=1
VERSION_PATCH=2

# Build settings (Usually passed to Cmake)
BUILD_SERVICE_EXE=OFF
Expand All @@ -22,3 +22,5 @@ BUILD_ENABLE_LOCALIZATION=ON
BUILD_MAX_JOB_THREADS=2
BUILD_MAX_QUERY_THREADS=2
BUILD_ENABLE_BACKEND=OFF
BUILD_ENABLE_PLUGINS=ON
BUILD_ENABLE_TOOLS=OFF
6 changes: 6 additions & 0 deletions config/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ option(BUILD_ENABLE_TESTS "Build tests" ON)

# Set the build backend option to OFF by default.
option(BUILD_ENABLE_BACKEND "Build backend" OFF)

# Set options to build or not tools
option(BUILD_ENABLE_TOOLS "Build tools" ON)

# Set option to build or not plugins
option(BUILD_ENABLE_PLUGINS "Build plugins" ON)
2 changes: 1 addition & 1 deletion config/shared.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function(set_executable_framework_linker_flags CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_
# Ignore specific default libraries msvcrt.lib;libcmt.lib in debug for MSVC
set(${CMAKE_EXE_LINKER_FLAGS_DEBUG} "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmt.lib")

elseif(XCODE)
elseif(APPLE)

# Link with core libraries
set(${CMAKE_EXE_LINKER_FLAGS} "${CMAKE_EXE_LINKER_FLAGS} -framework CoreFoundation -framework CoreServices")
Expand Down
25 changes: 16 additions & 9 deletions external/bgfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_definitions(BGFX_CONFIG_USE_TINYSTL=0)

# Disable vulkan backend renderer for all platforms
add_compile_definitions(BGFX_CONFIG_RENDERER_AGC=0)
add_compile_definitions(BGFX_CONFIG_RENDERER_VULKAN=0)
add_compile_definitions(BGFX_CONFIG_RENDERER_OPENGLES=0)
add_compile_definitions(BGFX_CONFIG_RENDERER_AGC=0)
add_compile_definitions(BGFX_CONFIG_RENDERER_OPENGL=0)

add_compile_definitions(BGFX_CONFIG_MAX_DRAW_CALLS=1024)
add_compile_definitions(BGFX_CONFIG_MAX_OCCLUSION_QUERIES=32)
add_compile_definitions(BGFX_CONFIG_MAX_VIEW_NAME=64)
# BGFX tweaks for our needs
add_compile_definitions(BGFX_CONFIG_MAX_SHADERS=16)
add_compile_definitions(BGFX_CONFIG_MAX_VIEW_NAME=16)
add_compile_definitions(BGFX_CONFIG_MAX_DRAW_CALLS=2047)
add_compile_definitions(BGFX_CONFIG_MAX_VERTEX_DECLS=32)
add_compile_definitions(BGFX_CONFIG_MAX_INDEX_BUFFERS=512)
add_compile_definitions(BGFX_CONFIG_MAX_INDEX_BUFFERS=256)
add_compile_definitions(BGFX_CONFIG_MAX_OCCLUSION_QUERIES=8)
add_compile_definitions(BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS=8192)
add_compile_definitions(BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS=8192)

# Disable debug features
add_compile_definitions(BGFX_CONFIG_DEBUG_UNIFORM=0)
add_compile_definitions(BGFX_CONFIG_DEBUG_ANNOTATION=0)
add_compile_definitions(BGFX_CONFIG_DEBUG_OCCLUSION=0)

if (WIN32)

Expand All @@ -63,17 +72,15 @@ if (WIN32)

# Enable directx backend renderers
add_compile_definitions(BGFX_CONFIG_RENDERER_DIRECT3D11=1)
add_compile_definitions(BGFX_CONFIG_RENDERER_DIRECT3D12=1)

add_compile_definitions(BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT=4)
add_compile_definitions(BGFX_CONFIG_RENDERER_DIRECT3D12=0)

elseif (APPLE)

# Disable CPP exceptions and RTTI
add_compile_options(-fno-rtti)
add_compile_options(-fno-exceptions)

# Force METAL renderer with BGFX_CONFIG_RENDERER_METAL=1
# Force METAL renderer
add_compile_definitions(BGFX_CONFIG_RENDERER_METAL=1)

endif()
Expand Down
14 changes: 8 additions & 6 deletions external/foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ add_compile_definitions(_LIB)

# Use compiler flags from parent project
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

# Use compiler flags from parent project
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

# Export foundation functions
if (BUILD_ENABLE_PLUGINS)
add_compile_definitions(FOUNDATION_COMPILE=1)
add_compile_definitions(BUILD_DYNAMIC_LINK=1)
endif()

# Project library
add_library(foundation STATIC ${foundation_src} ${foundation_includes})

Expand All @@ -45,9 +49,7 @@ target_include_directories(foundation PUBLIC ${ROOT_DIR}/external/)
# Export a few defines to the project
target_compile_definitions(foundation PUBLIC -DFOUNDATION_SIZE_REAL=8)

if (APPLE)
if (XCODE)
# Set Xcode project properties
set_target_properties(foundation
PROPERTIES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK YES)
set_target_properties(foundation PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK YES)
endif()
19 changes: 10 additions & 9 deletions external/foundation/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef BOOL(STDCALL* MiniDumpWriteDumpFn)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,
CONST PMINIDUMP_CALLBACK_INFORMATION);

static void
create_mini_dump(EXCEPTION_POINTERS* pointers, const char* name, size_t namelen, char* dump_file, size_t* capacity) {
create_mini_dump(EXCEPTION_POINTERS* pointers, const char* name, size_t namelen, char* dump_file, size_t* capacity, bool print_dump_written_log) {
MINIDUMP_EXCEPTION_INFORMATION info;
HANDLE file;
SYSTEMTIME local_time;
Expand Down Expand Up @@ -109,8 +109,9 @@ create_mini_dump(EXCEPTION_POINTERS* pointers, const char* name, size_t namelen,
STRING_FORMAT(errmsg));
}
if (success) {
log_errorf(0, ERROR_EXCEPTION, STRING_CONST("Exception occurred! Minidump written to: %.*s"),
STRING_FORMAT(filename));
if (print_dump_written_log) {
log_errorf(0, ERROR_EXCEPTION, STRING_CONST("Exception occurred! Minidump written to: %.*s"), STRING_FORMAT(filename));
}
FlushFileBuffers(file);
}
CloseHandle(file);
Expand Down Expand Up @@ -156,9 +157,9 @@ exception_filter(LPEXCEPTION_POINTERS pointers) {
char dump_file_buffer[MAX_PATH];
size_t dump_file_len = sizeof(dump_file_buffer);
exception_closure.triggered = true;
create_mini_dump(pointers, STRING_ARGS(exception_closure.name), dump_file_buffer, &dump_file_len);
create_mini_dump(pointers, STRING_ARGS(exception_closure.name), dump_file_buffer, &dump_file_len, true);
if (exception_closure.handler)
exception_closure.handler(dump_file_buffer, dump_file_len);
exception_closure.handler(nullptr, dump_file_buffer, dump_file_len);
if (_RtlRestoreContext)
_RtlRestoreContext(&exception_closure.context, 0);
else
Expand Down Expand Up @@ -229,10 +230,10 @@ FOUNDATION_ATTRIBUTE(noreturn) exception_sigaction(int sig, siginfo_t* info, voi
char file_name_buffer[BUILD_MAX_PATHLEN];
const char* name = get_thread_dump_name();
string_t dump_file = (string_t){file_name_buffer, sizeof(file_name_buffer)};
dump_file = create_mini_dump(arg, (string_const_t){name, string_length(name)}, dump_file);
dump_file = create_mini_dump(arg, (string_const_t){name, string_length(name)}, dump_file, true);
exception_handler_fn handler = get_thread_exception_handler();
if (handler)
handler(dump_file.str, dump_file.length);
handler(arg, dump_file.str, dump_file.length);

// Log dump file name
log_warnf(0, WARNING_SUSPICIOUS, STRING_CONST("Minidump written to: %.*s"), STRING_FORMAT(dump_file));
Expand Down Expand Up @@ -274,10 +275,10 @@ exception_try(exception_try_fn fn, void* data, exception_handler_fn handler, con
__try {
ret = fn(data);
} /*lint -e534*/
__except (create_mini_dump(GetExceptionInformation(), name, length, buffer, &capacity), EXCEPTION_EXECUTE_HANDLER) {
__except (create_mini_dump(GetExceptionInformation(), name, length, buffer, &capacity, false), EXCEPTION_EXECUTE_HANDLER) {
ret = FOUNDATION_EXCEPTION_CAUGHT;
if (handler)
handler(buffer, capacity);
handler(data, buffer, capacity);

error_context_clear();
}
Expand Down
6 changes: 3 additions & 3 deletions external/foundation/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ thread local storage to ensure maximum portability across supported platforms */
#undef FOUNDATION_PLATFORM_ANDROID
#define FOUNDATION_PLATFORM_ANDROID 1

// Compatibile platforms
// Compatible platforms
#undef FOUNDATION_PLATFORM_POSIX
#define FOUNDATION_PLATFORM_POSIX 1

Expand Down Expand Up @@ -200,7 +200,7 @@ thread local storage to ensure maximum portability across supported platforms */
#undef FOUNDATION_PLATFORM_TIZEN
#define FOUNDATION_PLATFORM_TIZEN 1

// Compatibile platforms
// Compatible platforms
#undef FOUNDATION_PLATFORM_POSIX
#define FOUNDATION_PLATFORM_POSIX 1

Expand Down Expand Up @@ -1796,7 +1796,7 @@ Expand to three arguments, string pointer, length and capacity, as in
<code>s.str, s.length, s.length+1</code>

\def STRING_FORMAT
Expand to two arguments, legnth and string pointer, as in <code>(int)s.length, s.str</code>.
Expand to two arguments, length and string pointer, as in <code>(int)s.length, s.str</code>.
Useful when passing a string_t to a string format argument, for example
<code>string_t mystr = ...; log_infof(0, STRING_CONST("Mystring: %.*s"), STRING_FORMAT(mystr));</code>

Expand Down
5 changes: 3 additions & 2 deletions external/foundation/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ an implementation specific code which is then returned from the call to error_re
\return Implementation specific code which is passed back as return from error_report */
typedef int (*error_handler_fn)(error_level_t level, error_t error);

/*! Assert handler which is passed assert data and should do impementation specific
/*! Assert handler which is passed assert data and should do implementation specific
processing and return a code indicating if execution can continue or need to be aborted.
\param context Error context
\param condition String expressing the condition that failed
Expand Down Expand Up @@ -743,9 +743,10 @@ typedef int (*exception_try_fn)(void* arg);

/*! Exception handler function prototype, used to notify that an exception occurred
and the process state was saved to a dump file
\param arg Implementation specific argument passed to exception_try
\param file Dump file path
\param length Length of file path */
typedef void (*exception_handler_fn)(const char* file, size_t length);
typedef void (*exception_handler_fn)(void* arg, const char* file, size_t length);

/*! Object deallocation function prototype, used to deallocate an object of a specific type
\param object Object pointer */
Expand Down
7 changes: 7 additions & 0 deletions external/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ source_group("includes" FILES ${imgui_includes})
# Add _LIB only for static library
add_compile_definitions(_LIB)

if (BUILD_ENABLE_PLUGINS)
if (MSVC)
# Define IMGUI_API to export symbols
add_compile_definitions("IMGUI_API=__declspec(dllexport)")
endif()
endif()

# Use compiler flags from parent project
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

Expand Down
14 changes: 13 additions & 1 deletion external/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@

#pragma once

#include <foundation/assert.h>

// ###############################################################################
#include "IconsMaterialDesign.h"
#define THIN_SPACE "\xe2\x80\x89" // U+2009
// ###############################################################################

//---- Define assertion handler. Defaults to calling assert().
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts

#ifdef NDEBUG
#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
#else
#define IM_ASSERT(_EXPR) FOUNDATION_ASSERT(_EXPR)
#endif

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
Expand Down
4 changes: 0 additions & 4 deletions external/imgui/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ Index of this file:
#include IMGUI_USER_CONFIG
#endif
#include "imconfig.h"
// ###############################################################################
#include "IconsMaterialDesign.h"
#define THIN_SPACE "\xe2\x80\x89" // U+2009
// ###############################################################################

#ifndef IMGUI_DISABLE

Expand Down
Loading