Skip to content

Commit

Permalink
[add] support for factory plugins
Browse files Browse the repository at this point in the history
[add] terrain plugin
  • Loading branch information
begla committed Jul 30, 2023
1 parent 6bc3ecb commit 5f0308f
Show file tree
Hide file tree
Showing 29 changed files with 8,319 additions and 197 deletions.
14 changes: 14 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Checks: '-*,readability-identifier-naming'
HeaderFilterRegex: '.*Iolite.*'

CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: lower_case }
- { key: readability-identifier-naming.ClassSuffix, value: _t }
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
- { key: readability-identifier-naming.StructCase, value: lower_case }
- { key: readability-identifier-naming.StructSuffix, value: _t }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build_lua_plugin
name: build_plugins
on: [push]
jobs:
build:
Expand All @@ -13,12 +13,12 @@ jobs:
submodules: true
- name : "Build plugins"
run: |
cd iolite_lua_plugin
cd iolite_plugins
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
- name : "Archive plugins"
uses: actions/upload-artifact@v3
with:
name: lua_plugin
name: plugins
path: |
iolite_lua_plugin/IoliteLuaPlugin.*
iolite_plugins/Iolite*Plugin.*
17 changes: 8 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ iolite_samples/imgui.ini
iolite_samples/keybindings_editor.json
iolite_samples/keybindings_global.json
iolite_samples/property_metadata.json
iolite_samples/Iolite_Pro_RelWithDebInfo
iolite_samples/Iolite_Pro_RelWithDebInfo.exe
iolite_samples/IoliteLuaPlugin.so
iolite_samples/IoliteLuaPlugin.dll
iolite_samples/*.exe
iolite_samples/*.so
iolite_samples/*.dll
iolite_samples/settings.json

iolite_c_api/sample_plugins/build
iolite_c_api/sample_plugins/.cache
iolite_c_api/sample_plugins/*.so
iolite_c_api/sample_plugins/*.dll
iolite_c_api/sample_plugins/*.pdb
iolite_lua_plugin/build
iolite_lua_plugin/.cache
iolite_lua_plugin/*.so
iolite_lua_plugin/*.dll
iolite_lua_plugin/*.pdb
iolite_plugins/build
iolite_plugins/.cache
iolite_plugins/*.so
iolite_plugins/*.dll
iolite_plugins/*.pdb

hohenzollern_castle_and_kingdom.vox
95 changes: 56 additions & 39 deletions iolite_c_api/iolite_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,13 +810,6 @@ typedef struct
io_ref_t entity; // The entity that was hit.
} io_physics_raycast_result;

// A single pixel of a heightmap
//----------------------------------------------------------------------------//
typedef struct
{
io_uint32_t internal;
} io_terrain_heightmap_pixel;

// Header for a single event
//----------------------------------------------------------------------------//
typedef struct
Expand Down Expand Up @@ -881,20 +874,6 @@ io_pathfinding_init_path_settings(io_pathfinding_path_settings* settings)
settings->num_max_steps = 128u;
}

//----------------------------------------------------------------------------//
inline io_terrain_heightmap_pixel io_terrain_create_heightmap_pixel(
io_float32_t height, io_float32_t grass_height, io_uint8_t palette_index)
{
const io_uint32_t v_height = io_min(height * 255.0f, 255u);
const io_uint32_t v_grass_height = io_min(grass_height * 255.0f, 255u);
const io_uint32_t v_palette_index = palette_index;

io_terrain_heightmap_pixel p;
p.internal = v_height | (v_grass_height << 8u) | (palette_index << 16u);

return p;
}

//----------------------------------------------------------------------------//
inline const void* io_events_get_data(const io_events_header* current)
{
Expand Down Expand Up @@ -1127,6 +1106,16 @@ struct io_base_i
// Gets the value of the variant as a uvec3.
io_uvec3_t (*variant_get_uvec3)(io_variant_t variant);

// Creates a new variant from a 8-bit uvec3.
io_variant_t (*variant_from_u8vec3)(io_u8vec3_t value);
// Gets the value of the variant as a 8-bit uvec3.
io_u8vec3_t (*variant_get_u8vec3)(io_variant_t variant);

// Creates a new variant from a 16-bit uvec3.
io_variant_t (*variant_from_u16vec3)(io_u16vec3_t value);
// Gets the value of the variant as a 16-bit uvec3.
io_u16vec3_t (*variant_get_u16vec3)(io_variant_t variant);

// Creates a new variant from a uvec4.
io_variant_t (*variant_from_uvec4)(io_uvec4_t value);
// Gets the value of the variant as a uvec4.
Expand Down Expand Up @@ -1459,24 +1448,6 @@ struct io_input_system_i
void (*request_mouse_cursor)();
};

//----------------------------------------------------------------------------//
#define IO_TERRAIN_API_NAME "io_terrain_i"
//----------------------------------------------------------------------------//

// Provides access to the terrain subsystem
//----------------------------------------------------------------------------//
struct io_terrain_i
{
// Generates heightmap based terrain from the provided data.
void (*generate_from_data)(const io_terrain_heightmap_pixel* heightmap,
io_uint32_t size, const char* palette_name,
io_float32_t max_height, io_float32_t voxel_size);
// Generate heightmap based terrain from the provided image.
void (*generate_from_image)(const char* heightmap_filename,
const char* palette_name, io_float32_t max_height,
io_float32_t voxel_size);
};

//----------------------------------------------------------------------------//
#define IO_PHYSICS_API_NAME "io_physics_i"
//----------------------------------------------------------------------------//
Expand Down Expand Up @@ -2101,4 +2072,50 @@ struct io_resource_palette_i
io_uint8_t palette_index);
};

// Interfaces and types exposed by the factory plugins
//----------------------------------------------------------------------------//

// A single pixel of a heightmap
//----------------------------------------------------------------------------//
typedef struct
{
io_uint32_t internal;
} io_plugin_terrain_heightmap_pixel;

//----------------------------------------------------------------------------//
inline io_plugin_terrain_heightmap_pixel
io_plugin_terrain_create_heightmap_pixel(io_float32_t height,
io_float32_t grass_height,
io_uint8_t palette_index)
{
const io_uint32_t v_height = io_min(height * 255.0f, 255u);
const io_uint32_t v_grass_height = io_min(grass_height * 255.0f, 255u);
const io_uint32_t v_palette_index = palette_index;

io_plugin_terrain_heightmap_pixel p;
p.internal = v_height | (v_grass_height << 8u) | (palette_index << 16u);

return p;
}

//----------------------------------------------------------------------------//
#define IO_PLUGIN_TERRAIN_API_NAME "io_plugin_terrain_i"
//----------------------------------------------------------------------------//

// Inteface exposed by the terrain (generator) plugin
//----------------------------------------------------------------------------//
struct io_plugin_terrain_i
{
// Generates heightmap based terrain from the provided data.
io_ref_t (*generate_from_data)(
const io_plugin_terrain_heightmap_pixel* heightmap, io_uint32_t size,
const char* palette_name, io_float32_t max_height,
io_float32_t voxel_size);
// Generate heightmap based terrain from the provided image.
io_ref_t (*generate_from_image)(const char* heightmap_filename,
const char* palette_name,
io_float32_t max_height,
io_float32_t voxel_size);
};

#endif
50 changes: 25 additions & 25 deletions iolite_c_api/sample_plugins/sample_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void on_build_plugin_menu()
// Add a new menu item to the menu
if (ImGui::MenuItem("Spawn Voxel Cubes"))
{
constexpr io_uint32_t numNodes = 500u;
constexpr io_uint32_t num_nodes = 500u;

// Create a new palette and set a single blueish color
const io_ref_t palette = io_resource_palette->base.create("my_palette");
Expand All @@ -167,7 +167,7 @@ static void on_build_plugin_menu()
io_resource_palette->base.commit_changes(palette);

// Spawn voxel cubes
for (uint32_t i = 0u; i < numNodes; ++i)
for (uint32_t i = 0u; i < num_nodes; ++i)
{
// Create a new node (and entity)
const io_ref_t node = io_component_node->create("cube");
Expand Down Expand Up @@ -195,10 +195,10 @@ static void on_build_plugin_menu()
// Add a new menu item to the menu
if (ImGui::MenuItem("Spawn Boids"))
{
constexpr io_uint32_t numBoids = 2000u;
constexpr io_uint32_t num_boids = 2000u;

// Spawn boids
for (uint32_t i = 0u; i < numBoids; ++i)
for (uint32_t i = 0u; i < num_boids; ++i)
{
// Create a new node (and entity)
const io_ref_t node = io_component_node->create("boid");
Expand All @@ -222,31 +222,31 @@ static void on_build_plugin_menu()
}

//----------------------------------------------------------------------------//
static bool draw_ui_sample_main_menu_button(const char* text,
io_float32_t& offset)
static auto draw_ui_sample_main_menu_button(const char* text,
io_float32_t& offset) -> bool
{
constexpr float buttonHeight = 50.0f;
constexpr float button_height = 50.0f;
constexpr float spacing = 10.0f;

bool clicked = false;

io_ui->push_transform({0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, offset},
{0.0f, offset + buttonHeight}, 0.0f);
{0.0f, offset + button_height}, 0.0f);
{
// Draw button background
{
constexpr io_vec4_t colorDefault = {0.1f, 0.1f, 0.1f, 0.5f};
constexpr io_vec4_t colorHovered = {0.25f, 0.25f, 0.25f, 0.5f};
constexpr io_vec4_t colorPressed = {0.5f, 0.5f, 0.5f, 0.5f};
constexpr io_vec4_t color_default = {0.1f, 0.1f, 0.1f, 0.5f};
constexpr io_vec4_t color_hovered = {0.25f, 0.25f, 0.25f, 0.5f};
constexpr io_vec4_t color_pressed = {0.5f, 0.5f, 0.5f, 0.5f};

io_vec4_t color = colorDefault;
io_vec4_t color = color_default;

if (io_ui->intersects(io_input_system->get_mouse_pos()))
{
color = colorHovered;
color = color_hovered;
if (io_input_system->get_key_state(io_input_key_mouse_left, 0) ==
io_input_key_state_pressed)
color = colorPressed;
color = color_pressed;
else if (io_input_system->get_key_state(io_input_key_mouse_left, 0) ==
io_input_key_state_clicked)
clicked = true;
Expand All @@ -272,7 +272,7 @@ static bool draw_ui_sample_main_menu_button(const char* text,
}
io_ui->pop_transform();

offset += spacing + buttonHeight;
offset += spacing + button_height;

return clicked;
}
Expand All @@ -294,17 +294,17 @@ static void draw_ui_sample_main_menu(io_float32_t delta_t)
io_ui->push_transform({0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f},
{0.0f, 100.0f}, 0.0f);
{
io_vec2_t splashSize = io_ui->get_image_size("splash");
const float aspect = splashSize.y / splashSize.x;
splashSize.x = 200.0f;
splashSize.y = splashSize.x * aspect;
io_vec2_t splash_size = io_ui->get_image_size("splash");
const float aspect = splash_size.y / splash_size.x;
splash_size.x = 200.0f;
splash_size.y = splash_size.x * aspect;

// Draw logo
io_ui->push_transform_preset(io_ui_anchor_preset_center,
{-splashSize.x * 0.5f, splashSize.x * 0.5f,
-splashSize.y * 0.5f,
splashSize.y * 0.5f},
0.0f);
io_ui->push_transform_preset(
io_ui_anchor_preset_center,
{-splash_size.x * 0.5f, splash_size.x * 0.5f, -splash_size.y * 0.5f,
splash_size.y * 0.5f},
0.0f);
{
io_ui->draw_image("splash", {1.0f, 1.0f, 1.0f, 1.0f});
}
Expand Down Expand Up @@ -480,7 +480,7 @@ IO_API_EXPORT io_uint32_t IO_API_CALL get_api_version()
//----------------------------------------------------------------------------//
IO_API_EXPORT io_int32_t IO_API_CALL load_plugin(void* api_manager)
{
io_api_manager = (io_api_manager_i*)api_manager;
io_api_manager = (const io_api_manager_i*)api_manager;

// Retrieve API interfaces
io_logging =
Expand Down
2 changes: 0 additions & 2 deletions iolite_lua_plugin/build_plugins.bat

This file was deleted.

24 changes: 12 additions & 12 deletions iolite_lua_plugin/CMakeLists.txt → iolite_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
cmake_minimum_required(VERSION 3.26)

project(IOLITE_LUA_PLUGIN)
project(IOLITE_PLUGINS)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_SHARED_LIBRARY_PREFIX "")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(IO_LUA_PLUGIN_ID)
add_definitions("-DIO_LUA_PLUGIN_ID=${IO_LUA_PLUGIN_ID}")
if(IO_PLUGIN_ID)
add_definitions("-DIO_PLUGIN_ID=${IO_PLUGIN_ID}")
else()
remove_definitions(-DIO_LUA_PLUGIN_ID)
remove_definitions(-DIO_PLUGIN_ID)
endif()

unset(IO_LUA_PLUGIN_ID CACHE)

# LuaJIT
add_definitions("-DSOL_LUAJIT=1")
add_definitions("-DSOL_ALL_SAFETIES_ON=1")
unset(IO_PLUGIN_ID CACHE)

if(WIN32)
find_library(LUA_JIT_LIBRARIES NAMES lua51 PATHS "dependencies/lua/lib")
elseif(UNIX)
find_library(LUA_JIT_LIBRARIES NAMES luajit PATHS "dependencies/lua/lib")
endif()

include_directories(../iolite_c_api/sample_plugins/dependencies/glm/glm ../iolite_c_api dependencies dependencies/lua/include ./)
include_directories(../iolite_c_api/sample_plugins/dependencies/glm/glm ../iolite_c_api dependencies dependencies/lua/include lua_plugin terrain_plugin)

add_library(IoliteLuaPlugin SHARED
lua_plugin.cpp
lua_plugin/lua_plugin.cpp
)
add_library(IoliteTerrainPlugin SHARED
terrain_plugin/terrain_plugin.cpp
)

target_compile_definitions(IoliteLuaPlugin PUBLIC DSOL_LUAJIT=1 SOL_ALL_SAFETIES_ON=1)
target_link_libraries(IoliteLuaPlugin ${LUA_JIT_LIBRARIES})

foreach(EXECUTABLE IoliteLuaPlugin)
foreach(EXECUTABLE IoliteLuaPlugin IoliteTerrainPlugin)
set_target_properties(${EXECUTABLE} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions iolite_plugins/build_plugins.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DIO_PLUGIN_ID="0xC3084E0B98241894ull" -GNinja
cmake --build build --config Release
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5f0308f

Please sign in to comment.