Skip to content

Commit

Permalink
2024.09.23
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-LouisH committed Sep 23, 2024
1 parent b2c93b7 commit 07ba751
Show file tree
Hide file tree
Showing 440 changed files with 119 additions and 58,584 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import omnific
import sys


project_name_type_pairs = {
Expand Down Expand Up @@ -28,6 +29,7 @@ def __init__(self):
pass

def on_start(self):
print("Python: " + sys.version)
project_print_string = ""

project_selection_letters = list(self.project_paths.keys())
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import omnific
import math

class omnific_script:

Expand All @@ -13,7 +12,7 @@ def on_logic(self):
delta = omnific.get_time_delta()
colourChange = 0.1

renderable = omnific.get_component("RenderableComponent")
renderable = omnific.get_component("Model")

renderable.shader_parameters.set_float_uniform("red", self.red)
renderable.shader_parameters.set_float_uniform("green", self.green)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions src/omnific_engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ else()
find_package(OpenAL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
endif()

add_dependencies (omnific_engine
Expand All @@ -55,7 +58,6 @@ target_include_directories(omnific_engine PUBLIC
${THIRD_PARTY_DIR}/glad/include
${THIRD_PARTY_DIR}/glm
${THIRD_PARTY_DIR}/libretti/include
${THIRD_PARTY_DIR}/pybind11/include
${THIRD_PARTY_DIR}/stb_image
${THIRD_PARTY_DIR}/tinygltf
${THIRD_PARTY_DIR}/tinyobjloader
Expand All @@ -69,7 +71,7 @@ target_link_libraries (omnific_engine
OpenAL::OpenAL
SDL2::SDL2
SDL2_ttf::SDL2_ttf
Python::Python
pybind11::embed
)

if (${LIBRARY_TYPE} STREQUAL "SHARED")
Expand Down
10 changes: 6 additions & 4 deletions src/omnific_engine/foundations/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include "time_conversions.hpp"
#include "physics_constants.hpp"

#define DATA_DIRECTORY_NAME "assets"
#define DATA_DIRECTORY "assets/"
#define DEBUG_STUDIO_ASSETS_DIRECTORY "../../../../../assets/studio_assets/"
#define DEBUG_DEMO_ASSETS_DIRECTORY "../../../../../assets/demo_assets/"
#define DEFAULT_APP_DATA_DIRECTORY_NAME "app_data"
#define DEFAULT_APP_DATA_DIRECTORY "app_data/"
#define DEFAULT_DEBUG_STUDIO_DATA_DIRECTORY "../../../../../app_data/studio_data/"
#define DEFAULT_DEBUG_DEMO_DATA_DIRECTORY "../../../../../app_data/demo_data/"

#ifdef _DEBUG
#define DEBUG_CONSOLE_ENABLED
Expand All @@ -41,6 +41,8 @@
#define DEFAULT_TARGET_COMPUTE_FPS (DEFAULT_TARGET_UPDATE_FPS * 2.0)
#define DEFAULT_TARGET_OUTPUT_FPS DEFAULT_TARGET_FPS

#define DEFAULT_COMPUTE_FRAME_TIME 8

#define BOOT_FILE_NAME "boot.yml"

#define MAIN_THREAD_CLOCK_NAME "main_thread_clock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Omnific::Configuration::load_from_file(std::string boot_filepath)
configuration->performance_settings.target_input_fps = DEFAULT_TARGET_INPUT_FPS;
configuration->performance_settings.target_update_fps = DEFAULT_TARGET_UPDATE_FPS;
configuration->performance_settings.target_output_fps = DEFAULT_TARGET_OUTPUT_FPS;
configuration->performance_settings.compute_frame_time = 8;
configuration->performance_settings.compute_frame_time = DEFAULT_COMPUTE_FRAME_TIME;
configuration->performance_settings.enable_multithreading = true;

for (YAML::const_iterator it0 = yaml_node.begin(); it0 != yaml_node.end(); ++it0)
Expand Down
51 changes: 36 additions & 15 deletions src/omnific_engine/foundations/singletons/platform/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ Omnific::FileAccess::~FileAccess()
file_loading_thread->join();
}

void Omnific::FileAccess::set_data_directory(std::string asset_directory)
void Omnific::FileAccess::set_app_data_directories(std::vector<std::string> app_data_directories)
{
this->data_directory = asset_directory;
Platform::get_logger().write("Data Directory set to \"" + asset_directory + "\"");
this->app_data_directories = app_data_directories;
std::string app_data_directories_string;

for (int i = 0; i < app_data_directories.size(); i++)
{
app_data_directories_string.append(app_data_directories.at(i));
if (i < app_data_directories.size() - 1)
app_data_directories_string.append(", ");
}

Platform::get_logger().write("Data Directory set to \"" + app_data_directories_string + "\"");
}

std::shared_ptr<Omnific::Scene> Omnific::FileAccess::load_scene(std::string filepath)
Expand All @@ -49,6 +58,21 @@ std::shared_ptr<Omnific::Scene> Omnific::FileAccess::load_scene(std::string file
return scene;
}

std::string Omnific::FileAccess::find_path_among_app_data_directories(std::string filepath)
{
std::string combined_filepath;

for (int i = 0; i < this->app_data_directories.size(); i++)
{
std::string app_data_directory = app_data_directories[i];
std::string tentative_combined_filepath = app_data_directory + filepath;
if (this->exists(tentative_combined_filepath))
combined_filepath = tentative_combined_filepath;
}

return combined_filepath;
}

std::string Omnific::FileAccess::get_executable_file_path()
{
return this->executable_filepath;
Expand All @@ -64,11 +88,6 @@ std::string Omnific::FileAccess::get_executable_directory_path()
return this->get_path_before_file(this->executable_filepath);
}

std::string Omnific::FileAccess::get_data_directory_path()
{
return this->data_directory;
}

std::string Omnific::FileAccess::get_file_name_without_extension(std::string filepath)
{
std::string file_name;
Expand Down Expand Up @@ -143,6 +162,8 @@ std::string Omnific::FileAccess::get_path_before_file(std::string filepath)
path += filepath.at(j);
}

path += "/";

return path;
}

Expand All @@ -163,7 +184,7 @@ std::string Omnific::FileAccess::read_string(std::string filepath, bool apply_da
std::vector<uint8_t> Omnific::FileAccess::read_binary(std::string filepath, bool apply_data_directory)
{
std::vector<uint8_t> output_binary;
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_data_directory);
std::FILE* file_pointer = std::fopen(full_filepath.c_str(), "rb");

if (file_pointer)
Expand All @@ -185,39 +206,39 @@ void Omnific::FileAccess::write_binary(std::string filepath, std::vector<uint8_t

void Omnific::FileAccess::request_asynchronous_binary_reading(std::string filepath, bool apply_data_directory)
{
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_data_directory);

if (!this->asynchronously_loaded_binaries.count(full_filepath))
this->io_threads.push_back(new std::thread(&FileAccess::read_binary_asynchronously, this, filepath, apply_data_directory));
}

void Omnific::FileAccess::request_asynchronous_binary_writing(std::string filepath, std::vector<uint8_t> binary, bool apply_data_directory)
{
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_data_directory);
this->io_threads.push_back(new std::thread(&FileAccess::write_binary_asynchronously, this, filepath, binary, apply_data_directory));
}

bool Omnific::FileAccess::has_binary_been_read_asynchronously(std::string filepath, bool apply_data_directory)
{
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_data_directory);
return this->asynchronously_loaded_binaries.count(full_filepath);
}

std::vector<uint8_t> Omnific::FileAccess::fetch_asynchronously_read_binary(std::string filepath, bool apply_data_directory)
{
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_data_directory);
std::vector<uint8_t> binary;
if (this->asynchronously_loaded_binaries.count(full_filepath))
binary = this->asynchronously_loaded_binaries.at(full_filepath);
return binary;
}

std::string Omnific::FileAccess::get_filepath_with_data_directory(std::string filepath, bool apply_data_directory)
std::string Omnific::FileAccess::get_filepath_with_app_data_directory(std::string filepath, bool apply_data_directory)
{
std::string full_filepath;

if (apply_data_directory)
full_filepath = this->get_data_directory_path() + filepath;
full_filepath = this->find_path_among_app_data_directories(filepath);
else
full_filepath = filepath;

Expand Down
50 changes: 25 additions & 25 deletions src/omnific_engine/foundations/singletons/platform/file_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,56 @@ namespace Omnific
public:
FileAccess(std::string executable_filepath);
~FileAccess();
void set_data_directory(std::string asset_directory);
void set_app_data_directories(std::vector<std::string> app_data_directories);
std::shared_ptr<Scene> load_scene(std::string filepath);
std::string find_path_among_app_data_directories(std::string filepath);
std::string get_executable_file_path();
std::string get_executable_name();
std::string get_executable_directory_path();
std::string get_data_directory_path();
std::string get_file_name_without_extension(std::string filepath);
std::string get_file_extension(std::string filepath);
std::string get_path_before_file(std::string filepath);
bool exists(std::string filepath);

std::string read_string(std::string filepath, bool apply_data_directory = true);
std::vector<uint8_t> read_binary(std::string filepath, bool apply_data_directory = true);
void write_binary(std::string filepath, std::vector<uint8_t> binary, bool apply_data_directory = true);
std::string read_string(std::string filepath, bool apply_app_data_directory = true);
std::vector<uint8_t> read_binary(std::string filepath, bool apply_app_data_directory = true);
void write_binary(std::string filepath, std::vector<uint8_t> binary, bool apply_app_data_directory = true);

void request_asynchronous_binary_reading(std::string filepath, bool apply_data_directory = true);
void request_asynchronous_binary_writing(std::string filepath, std::vector<uint8_t> binary, bool apply_data_directory = true);
bool has_binary_been_read_asynchronously(std::string filepath, bool apply_data_directory = true);
std::vector<uint8_t> fetch_asynchronously_read_binary(std::string filepath, bool apply_data_directory = true);
void request_asynchronous_binary_reading(std::string filepath, bool apply_app_data_directory = true);
void request_asynchronous_binary_writing(std::string filepath, std::vector<uint8_t> binary, bool apply_app_data_directory = true);
bool has_binary_been_read_asynchronously(std::string filepath, bool apply_app_data_directory = true);
std::vector<uint8_t> fetch_asynchronously_read_binary(std::string filepath, bool apply_app_data_directory = true);

template <class DerivedAsset>
std::shared_ptr<DerivedAsset> load_asset_by_type(std::string filepath, bool apply_data_directory = true)
template <class DerivedResource>
std::shared_ptr<DerivedResource> load_resource_by_type(std::string filepath, bool apply_app_data_directory = true)
{
std::shared_ptr<DerivedAsset> derived_asset;
std::string full_filepath = this->get_filepath_with_data_directory(filepath, apply_data_directory);
std::shared_ptr<DerivedResource> derived_resource;
std::string full_filepath = this->get_filepath_with_app_data_directory(filepath, apply_app_data_directory);

if (this->assets.count(filepath) != 0)
if (this->resources.count(filepath) != 0)
{
derived_asset = std::dynamic_pointer_cast<DerivedAsset>(this->assets.at(filepath));
derived_resource = std::dynamic_pointer_cast<DerivedResource>(this->resources.at(filepath));
}
else
{
derived_asset = std::shared_ptr<DerivedAsset>(new DerivedAsset(full_filepath));
std::shared_ptr<Resource> asset = std::static_pointer_cast<Resource>(derived_asset);
if (!this->assets.count(asset->get_name()))
this->assets.emplace(asset->get_name(), asset);
derived_resource = std::shared_ptr<DerivedResource>(new DerivedResource(full_filepath));
std::shared_ptr<Resource> resource = std::static_pointer_cast<Resource>(derived_resource);
if (!this->resources.count(resource->get_name()))
this->resources.emplace(resource->get_name(), resource);
}

return derived_asset;
return derived_resource;
}
private:
std::string executable_filepath;
std::string data_directory;
std::unordered_map<std::string, std::shared_ptr<Omnific::Resource>> assets;
std::vector<std::string> app_data_directories;
std::unordered_map<std::string, std::shared_ptr<Omnific::Resource>> resources;

std::vector<std::thread*> io_threads;
std::unordered_map<std::string, std::vector<uint8_t>> asynchronously_loaded_binaries;

std::string get_filepath_with_data_directory(std::string filepath, bool apply_data_directory = true);
void read_binary_asynchronously(std::string filepath, bool apply_data_directory);
void write_binary_asynchronously(std::string filepath, std::vector<uint8_t> binary, bool apply_data_directory);
std::string get_filepath_with_app_data_directory(std::string filepath, bool apply_app_data_directory = true);
void read_binary_asynchronously(std::string filepath, bool apply_app_data_directory);
void write_binary_asynchronously(std::string filepath, std::vector<uint8_t> binary, bool apply_app_data_directory);
};
}
33 changes: 24 additions & 9 deletions src/omnific_engine/omnific_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ void Omnific::Engine::set_callback_functions(
this->application_callback_functions.on_output = on_output;
}

void Omnific::Engine::add_app_data_directory(std::string app_data_directory)
{
this->app_data_directories.push_back(app_data_directory);
}

void Omnific::Engine::add_app_data_directories(std::vector<std::string> app_data_directories)
{
this->app_data_directories.insert(
this->app_data_directories.end(),
app_data_directories.begin(),
app_data_directories.end()
);
}


void Omnific::Engine::run(
int argc,
Expand Down Expand Up @@ -164,7 +178,7 @@ void Omnific::Engine::initialize()
logger.write("Retrieved OS Name: \"" + Platform::get_platform_name() + "\"");
logger.write("Retrieved System RAM: " + std::to_string(Platform::get_system_ram()) + " MB");

std::string data_directory = DATA_DIRECTORY;
std::string app_data_directory = DEFAULT_APP_DATA_DIRECTORY;

#ifdef _DEBUG
while (true)
Expand All @@ -186,12 +200,12 @@ void Omnific::Engine::initialize()
}
else if (input_string == "1")
{
data_directory = DEBUG_DEMO_ASSETS_DIRECTORY;
app_data_directory = DEFAULT_DEBUG_DEMO_DATA_DIRECTORY;
break;
}
else if (input_string == "2")
{
data_directory = DEBUG_STUDIO_ASSETS_DIRECTORY;
app_data_directory = DEFAULT_DEBUG_STUDIO_DATA_DIRECTORY;
break;
}
else
Expand All @@ -200,14 +214,14 @@ void Omnific::Engine::initialize()
}
}
#endif
std::string boot_filepath = data_directory + BOOT_FILE_NAME;
FileAccess& file_access = Platform::get_file_access();
this->app_data_directories.push_back(app_data_directory);
file_access.set_app_data_directories(app_data_directories);

std::string boot_filepath = file_access.find_path_among_app_data_directories(BOOT_FILE_NAME);

if (file_access.exists(boot_filepath))
{
Configuration::load_from_file(boot_filepath);
Platform::get_file_access().set_data_directory(data_directory);
}

#ifdef DEBUG_CONSOLE_ENABLED
std::cout << "\n\nPress '`' in-application to write to command line via console.";
Expand All @@ -219,7 +233,7 @@ void Omnific::Engine::initialize()
Window& window = Platform::get_window();
window.resize(Configuration::get_instance()->window_settings.width, Configuration::get_instance()->window_settings.height);
window.change_title(Configuration::get_instance()->metadata.title.c_str());
logger.write("Loaded application project \"" + Configuration::get_instance()->metadata.title + "\" at: " + data_directory);
logger.write("Loaded application project \"" + Configuration::get_instance()->metadata.title + "\" at: " + app_data_directory);
}
else
{
Expand Down Expand Up @@ -268,7 +282,8 @@ void Omnific::Engine::run_loop()
FileAccess& file_access = Platform::get_file_access();
std::string entry_scene_filepath = configuration->metadata.entry_scene_filepath;

if (file_access.exists(file_access.get_data_directory_path() + entry_scene_filepath))
std::string app_data_entry_scene_filepath = file_access.find_path_among_app_data_directories(entry_scene_filepath);
if (app_data_entry_scene_filepath != "")
SceneStorage::load_scene(std::shared_ptr<Scene>(new Scene(entry_scene_filepath)));

this->state = State::RUNNING;
Expand Down
5 changes: 5 additions & 0 deletions src/omnific_engine/omnific_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace Omnific
void (*on_output)()
);

void add_app_data_directory(std::string app_data_directory);

void add_app_data_directories(std::vector<std::string> app_data_directories);

void run(
int argc,
char* argv[]
Expand All @@ -74,6 +78,7 @@ namespace Omnific
FINALIZING
};

std::vector<std::string> app_data_directories;
State state;
std::unordered_map<std::string, std::shared_ptr<System>> systems;

Expand Down
Loading

0 comments on commit 07ba751

Please sign in to comment.