diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | bindgen/rust/Cargo.lock | 366 | ||||
-rw-r--r-- | bindgen/rust/Cargo.toml | 9 | ||||
-rw-r--r-- | bindgen/rust/build.rs | 53 | ||||
-rw-r--r-- | bindgen/rust/examples/main_loop.rs | 39 | ||||
-rw-r--r-- | bindgen/rust/src/lib.rs | 5 | ||||
-rw-r--r-- | include/amalgamation.h | 18 | ||||
-rw-r--r-- | scripts/amalgamation/celeritas.h | 54 | ||||
-rw-r--r-- | scripts/amalgamation/gen_amalgamation.py | 55 | ||||
-rw-r--r-- | src/defines.h | 1 | ||||
-rw-r--r-- | src/maths/maths.h | 60 |
11 files changed, 622 insertions, 41 deletions
@@ -11,3 +11,6 @@ node_modules/ # in case we accidentally use something not licensed properly, we will keep demo game assets ignored. assets/demo/ + +# Rust +target/
\ No newline at end of file diff --git a/bindgen/rust/Cargo.lock b/bindgen/rust/Cargo.lock new file mode 100644 index 0000000..63f3b6b --- /dev/null +++ b/bindgen/rust/Cargo.lock @@ -0,0 +1,366 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "celeritas" +version = "0.1.0" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/bindgen/rust/Cargo.toml b/bindgen/rust/Cargo.toml new file mode 100644 index 0000000..879e669 --- /dev/null +++ b/bindgen/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "celeritas" +version = "0.1.0" +edition = "2021" + +[dependencies] + +[build-dependencies] +bindgen = "0.69.4" diff --git a/bindgen/rust/build.rs b/bindgen/rust/build.rs new file mode 100644 index 0000000..113059b --- /dev/null +++ b/bindgen/rust/build.rs @@ -0,0 +1,53 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + // Tell cargo to look for shared libraries in the specified directory + println!("cargo:rustc-link-search=../../build/macosx/arm64/debug"); + + // Tell cargo to tell rustc to link the system bzip2 + // shared library. + println!("cargo:rustc-link-lib=core_static"); + println!("cargo:rustc-link-lib=glfw"); + + // The bindgen::Builder is the main entry point + // to bindgen, and lets you build up options for + // the resulting bindings. + let bindings = bindgen::Builder::default() + // The input header we would like to generate + // bindings for. + .header("../../include/amalgamation.h") + // -- our code + .clang_arg("-I../../src") + .clang_arg("-I../../src/core") + .clang_arg("-I../../src/maths") + .clang_arg("-I../../src/new_render") + .clang_arg("-I../../src/platform") + .clang_arg("-I../../src/ral") + .clang_arg("-I../../src/ral/backends/opengl") + .clang_arg("-I../../src/resources") + .clang_arg("-I../../src/std") + .clang_arg("-I../../src/std/containers") + .clang_arg("-I../../src/systems") + // -- dependencies + .clang_arg("-I../../deps/cgltf") + .clang_arg("-I../../deps/glfw-3.3.8/include/GLFW") + .clang_arg("-I../../deps/glad/include") + .clang_arg("-I../../deps/stb_image") + .clang_arg("-I../../deps/stb_image_write") + .clang_arg("-I../../deps/stb_truetype") + .generate_inline_functions(true) + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + // Finish the builder and generate the bindings. + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/bindgen/rust/examples/main_loop.rs b/bindgen/rust/examples/main_loop.rs new file mode 100644 index 0000000..a74e11c --- /dev/null +++ b/bindgen/rust/examples/main_loop.rs @@ -0,0 +1,39 @@ +use celeritas::*; + +unsafe fn run_game() { + // init + Core_Bringup(); + + // let mut cube_geo = Geo_CreateCuboid(Vec3 { x: 1.0, y: 1.0, z: 1.0 }); + // let cube = Mesh_Create(&mut cube_geo, false); + + let camera_pos = Vec3 { x: 0.0, y: 2.0, z: -3.0 }; + let pos_y = Vec3 { x: 0., y: 1.0, z: 0. }; + let camera = Camera_Create(camera_pos, vec3_normalise(vec3_negate(camera_pos)), pos_y, 45.0); + SetCamera(camera); + // let camera = Camera_Create(camera_pos, vec3_normalise(vec3_negate(camera_pos)), VEC3_Y, 45.0); + // SetCamera(cam); // update the camera in RenderScene + + let whatever = Vec3 { x: 1.0, y: 1.0, z: 1.0 }; + let sun = DirectionalLight { direction: whatever, ambient: whatever, diffuse: whatever, specular: whatever }; + SetMainLight(sun); + + // Skybox skybox = Skybox_Create(faces, 6); + let skybox = Skybox_Create(face_paths, 6); + + while !ShouldExit() { + Frame_Begin(); + + + + Frame_End(); + } +} + +fn main() { + println!("Running from Rust!"); + + unsafe { + run_game(); + } +} diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs new file mode 100644 index 0000000..a38a13a --- /dev/null +++ b/bindgen/rust/src/lib.rs @@ -0,0 +1,5 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/include/amalgamation.h b/include/amalgamation.h index fec3ebb..03e1c95 100644 --- a/include/amalgamation.h +++ b/include/amalgamation.h @@ -1,2 +1,18 @@ // TODO: Create a SQLite-like amalgamation header to include the whole -// API with one include and link the compiled code.
\ No newline at end of file +// API with one include and link the compiled code. + +#define CEL_PLATFORM_WINDOWS + +#include "defines.h" +#define c_static_inline // remove inlined functions so we can generate bindings + +#include "core.h" +#include "render.h" +#include "render_scene.h" +#include "ral.h" +#include "input.h" +#include "primitives.h" +#include "maths_types.h" +#include "maths.h" +#include "skybox.h" +#include "shadows.h"
\ No newline at end of file diff --git a/scripts/amalgamation/celeritas.h b/scripts/amalgamation/celeritas.h new file mode 100644 index 0000000..b432915 --- /dev/null +++ b/scripts/amalgamation/celeritas.h @@ -0,0 +1,54 @@ +void GPU_Renderpass_Destroy(GPU_Renderpass* pass); +void GraphicsPipeline_Destroy(GPU_Pipeline* pipeline); +GPU_CmdEncoder GPU_CmdEncoder_Create(); +void GPU_CmdEncoder_Destroy(GPU_CmdEncoder* encoder); +void GPU_CmdEncoder_Begin(GPU_CmdEncoder* encoder); +void GPU_CmdEncoder_Finish(GPU_CmdEncoder* encoder); +void GPU_CmdEncoder_BeginRender(GPU_CmdEncoder* encoder, GPU_Renderpass* renderpass); +void GPU_CmdEncoder_EndRender(GPU_CmdEncoder* encoder); +void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer); +void GPU_BufferDestroy(BufferHandle handle); +void GPU_BufferUpload(BufferHandle buffer, size_t n_bytes, const void* data); +TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void* data); +void GPU_TextureDestroy(TextureHandle handle); +void GPU_TextureUpload(TextureHandle handle, size_t n_bytes, const void* data); +void GPU_EncodeBindPipeline(GPU_CmdEncoder* encoder, GPU_Pipeline* pipeline); +void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData data); +void GPU_EncodeSetVertexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf); +void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf); +void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count); +void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count); +bool GPU_Backend_BeginFrame(); +void GPU_Backend_EndFrame(); +Skybox Skybox_Create(const char** face_paths, int n); +void Skybox_Draw(Skybox* skybox, Camera camera); +void SetCamera(Camera camera); +void SetMainLight(DirectionalLight light); +void PBR_Init(PBR_Storage* storage); +void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_height); +void Shadow_Run(RenderEnt* entities, size_t entity_count); +void Shadow_DrawDebugQuad(); +TextureHandle Shadow_GetShadowMapTexture(Shadow_Storage* storage); +void Immdraw_Init(Immdraw_Storage* storage); +void Immdraw_Shutdown(Immdraw_Storage* storage); +void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe); +void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe); +void Immdraw_Sphere(Transform tf, f32 size, Vec4 colour, bool wireframe); +void Immdraw_TransformGizmo(Transform tf, f32 size); +void EncodeDrawModel(Handle model, Mat4 transform); +void EncodeDrawMesh(Mesh* mesh, Material* material, Mat4 affine); +bool Renderer_Init(RendererConfig config, Renderer* renderer, GLFWwindow** out_window); +void Renderer_Shutdown(Renderer* renderer); +size_t Renderer_GetMemReqs(); +void Render_FrameBegin(Renderer* renderer); +void Render_FrameEnd(Renderer* renderer); +void Render_RenderEntities(RenderEnt* entities, size_t entity_count); +TextureData TextureDataLoad(const char* path, bool invert_y); +void TextureUpload(TextureHandle handle, size_t n_bytes, const void* data); +TextureHandle TextureLoadFromFile(const char* path); +ModelHandle ModelLoad(const char* debug_name, const char* filepath); +Mesh Mesh_Create(Geometry* geometry, bool free_on_upload); +void Mesh_Delete(Mesh* mesh); +void DrawMesh(Mesh* mesh, Material* material, Mat4 model); +void Render_DrawTerrain(); +static inline Vec3 vec3_create(f32 x, f32 y, f32 z); diff --git a/scripts/amalgamation/gen_amalgamation.py b/scripts/amalgamation/gen_amalgamation.py index 45a1c21..4a4d946 100644 --- a/scripts/amalgamation/gen_amalgamation.py +++ b/scripts/amalgamation/gen_amalgamation.py @@ -2,23 +2,58 @@ # # This makes including and linking Celeritas very easy. import re -import sys +import os +from pathlib import Path -def find_pub_functions(filepath): +categories = { + "RAL": "src/ral", + "Render": "src/new_render", + "Maths": "src/maths" +} + +def find_pub_functions_in_folder(folder_path): + functions = [] + for filename in os.listdir(folder_path): + filepath = os.path.join(folder_path, filename) + if os.path.isfile(filepath): + file_funcs = find_pub_functions_in_file(filepath) + functions.extend(file_funcs) + + return functions + +def find_pub_functions_in_file(file_path): pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)' - with open(filepath, 'r') as file: + with open(file_path, 'r') as file: content = file.read() matches = re.finditer(pattern, content, re.MULTILINE) + # Collect all the functions into an array + functions = [] for match in matches: - print(match.group(0)) + signature = match.group(0) + if signature.startswith("PUB "): + signature = signature[4:] -if __name__ == "__main__": - if len(sys.argv) != 2: - print("Usage: python script.py <path_to_c_file>") - sys.exit(1) + print(signature) + functions.append(signature) + + return functions - file_path = sys.argv[1] - find_pub_functions(file_path) +def generate_header(): + header_path = "celeritas.h" + + script_dir = Path(__file__).resolve().parent + grandparent_dir = script_dir.parents[1] + + with open(header_path, 'w') as export_file: + for category in categories.keys(): + folder = os.path.join(grandparent_dir, categories[category]) + category_funcs = find_pub_functions_in_folder(folder) + for func in category_funcs: + export_file.write(func) + export_file.write(';\n') + +if __name__ == "__main__": + generate_header() diff --git a/src/defines.h b/src/defines.h index 689eeca..19ffa98 100644 --- a/src/defines.h +++ b/src/defines.h @@ -55,6 +55,7 @@ CORE_DEFINE_HANDLE( Handle); // Untyped handle that can be casted to a strongly typed resource handle #define PUB // For collecting public APIs to expose in an amalgamation header file +#define c_static_inline static inline #define KB(x) ((size_t)x * 1000) #define MB(x) ((size_t)x * 1000 * 1000) diff --git a/src/maths/maths.h b/src/maths/maths.h index cd5b7b9..ec6e90a 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -21,23 +21,23 @@ // --- Vector Implementations // Dimension 3 -PUB static inline Vec3 vec3_create(f32 x, f32 y, f32 z) { return (Vec3){ x, y, z }; } +PUB c_static_inline Vec3 vec3_create(f32 x, f32 y, f32 z) { return (Vec3){ x, y, z }; } #define vec3(x, y, z) ((Vec3){ x, y, z }) -static inline Vec3 vec3_add(Vec3 a, Vec3 b) { return (Vec3){ a.x + b.x, a.y + b.y, a.z + b.z }; } -static inline Vec3 vec3_sub(Vec3 a, Vec3 b) { return (Vec3){ a.x - b.x, a.y - b.y, a.z - b.z }; } -static inline Vec3 vec3_mult(Vec3 a, f32 s) { return (Vec3){ a.x * s, a.y * s, a.z * s }; } -static inline Vec3 vec3_div(Vec3 a, f32 s) { return (Vec3){ a.x / s, a.y / s, a.z / s }; } - -static inline f32 vec3_len_squared(Vec3 a) { return (a.x * a.x) + (a.y * a.y) + (a.z * a.z); } -static inline f32 vec3_len(Vec3 a) { return sqrtf(vec3_len_squared(a)); } -static inline Vec3 vec3_negate(Vec3 a) { return (Vec3){ -a.x, -a.y, -a.z }; } -static inline Vec3 vec3_normalise(Vec3 a) { +c_static_inline Vec3 vec3_add(Vec3 a, Vec3 b) { return (Vec3){ a.x + b.x, a.y + b.y, a.z + b.z }; } +c_static_inline Vec3 vec3_sub(Vec3 a, Vec3 b) { return (Vec3){ a.x - b.x, a.y - b.y, a.z - b.z }; } +c_static_inline Vec3 vec3_mult(Vec3 a, f32 s) { return (Vec3){ a.x * s, a.y * s, a.z * s }; } +c_static_inline Vec3 vec3_div(Vec3 a, f32 s) { return (Vec3){ a.x / s, a.y / s, a.z / s }; } + +c_static_inline f32 vec3_len_squared(Vec3 a) { return (a.x * a.x) + (a.y * a.y) + (a.z * a.z); } +c_static_inline f32 vec3_len(Vec3 a) { return sqrtf(vec3_len_squared(a)); } +c_static_inline Vec3 vec3_negate(Vec3 a) { return (Vec3){ -a.x, -a.y, -a.z }; } +PUB c_static_inline Vec3 vec3_normalise(Vec3 a) { f32 length = vec3_len(a); return vec3_div(a, length); } -static inline f32 vec3_dot(Vec3 a, Vec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } -static inline Vec3 vec3_cross(Vec3 a, Vec3 b) { +c_static_inline f32 vec3_dot(Vec3 a, Vec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } +c_static_inline Vec3 vec3_cross(Vec3 a, Vec3 b) { return ( Vec3){ .x = a.y * b.z - a.z * b.y, .y = a.z * b.x - a.x * b.z, .z = a.x * b.y - a.y * b.x }; } @@ -50,31 +50,31 @@ static inline Vec3 vec3_cross(Vec3 a, Vec3 b) { #define VEC3_Z ((Vec3){ .x = 0.0, .y = 0.0, .z = 1.0 }) #define VEC3_NEG_Z ((Vec3){ .x = 0.0, .y = 0.0, .z = -1.0 }) -static inline void print_vec3(Vec3 v) { +c_static_inline void print_vec3(Vec3 v) { printf("{ x: %f, y: %f, z: %f )\n", (f64)v.x, (f64)v.y, (f64)v.z); } // TODO: Dimension 2 -static inline Vec2 vec2_create(f32 x, f32 y) { return (Vec2){ x, y }; } +c_static_inline Vec2 vec2_create(f32 x, f32 y) { return (Vec2){ x, y }; } #define vec2(x, y) ((Vec2){ x, y }) -static inline Vec2 vec2_div(Vec2 a, f32 s) { return (Vec2){ a.x / s, a.y / s }; } +c_static_inline Vec2 vec2_div(Vec2 a, f32 s) { return (Vec2){ a.x / s, a.y / s }; } // TODO: Dimension 4 -static inline Vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ x, y, z, w }; } +c_static_inline Vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ x, y, z, w }; } #define vec4(x, y, z, w) (vec4_create(x, y, z, w)) #define VEC4_ZERO ((Vec4){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 0.0 }) // --- Quaternion Implementations -static inline f32 quat_dot(Quat a, Quat b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } +c_static_inline f32 quat_dot(Quat a, Quat b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } -static inline Quat quat_normalise(Quat a) { +c_static_inline Quat quat_normalise(Quat a) { f32 length = sqrtf(quat_dot(a, a)); // same as len squared return (Quat){ a.x / length, a.y / length, a.z / length, a.w / length }; } -static inline Quat quat_ident() { return (Quat){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 1.0 }; } +c_static_inline Quat quat_ident() { return (Quat){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 1.0 }; } static Quat quat_from_axis_angle(Vec3 axis, f32 angle, bool normalize) { const f32 half_angle = 0.5f * angle; @@ -89,7 +89,7 @@ static Quat quat_from_axis_angle(Vec3 axis, f32 angle, bool normalize) { } // TODO: grok this. -static inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { +c_static_inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { Quat out_quaternion; Quat q0 = quat_normalise(a); @@ -139,11 +139,11 @@ static inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { // --- Matrix Implementations -static inline Mat4 mat4_ident() { +c_static_inline Mat4 mat4_ident() { return (Mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; } -static inline Mat4 mat4_translation(Vec3 position) { +c_static_inline Mat4 mat4_translation(Vec3 position) { Mat4 out_matrix = mat4_ident(); out_matrix.data[12] = position.x; out_matrix.data[13] = position.y; @@ -151,7 +151,7 @@ static inline Mat4 mat4_translation(Vec3 position) { return out_matrix; } -static inline Mat4 mat4_scale(f32 scale) { +c_static_inline Mat4 mat4_scale(f32 scale) { Mat4 out_matrix = mat4_ident(); out_matrix.data[0] = scale; out_matrix.data[5] = scale; @@ -160,7 +160,7 @@ static inline Mat4 mat4_scale(f32 scale) { } // TODO: double check this -static inline Mat4 mat4_rotation(Quat rotation) { +c_static_inline Mat4 mat4_rotation(Quat rotation) { Mat4 out_matrix = mat4_ident(); Quat n = quat_normalise(rotation); @@ -179,7 +179,7 @@ static inline Mat4 mat4_rotation(Quat rotation) { return out_matrix; } -static inline Mat4 mat4_mult(Mat4 lhs, Mat4 rhs) { +c_static_inline Mat4 mat4_mult(Mat4 lhs, Mat4 rhs) { Mat4 out_matrix = mat4_ident(); const f32 *m1_ptr = lhs.data; @@ -221,7 +221,7 @@ static Mat4 mat4_transposed(Mat4 matrix) { #if defined(CEL_REND_BACKEND_VULKAN) /** @brief Creates a perspective projection matrix compatible with Vulkan */ -static inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, +c_static_inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip) { f32 half_tan_fov = tanf(fov_radians * 0.5f); Mat4 out_matrix = { .data = { 0 } }; @@ -236,7 +236,7 @@ static inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_ } #else /** @brief Creates a perspective projection matrix */ -static inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, +c_static_inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip) { f32 half_tan_fov = tanf(fov_radians * 0.5f); Mat4 out_matrix = { .data = { 0 } }; @@ -250,7 +250,7 @@ static inline Mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_ #endif /** @brief Creates an orthographic projection matrix */ -static inline Mat4 mat4_orthographic(f32 left, f32 right, f32 bottom, f32 top, f32 near_clip, +c_static_inline Mat4 mat4_orthographic(f32 left, f32 right, f32 bottom, f32 top, f32 near_clip, f32 far_clip) { // source: kohi game engine. Mat4 out_matrix = mat4_ident(); @@ -270,7 +270,7 @@ static inline Mat4 mat4_orthographic(f32 left, f32 right, f32 bottom, f32 top, f return out_matrix; } -static inline Mat4 mat4_look_at(Vec3 position, Vec3 target, Vec3 up) { +c_static_inline Mat4 mat4_look_at(Vec3 position, Vec3 target, Vec3 up) { Mat4 out_matrix; Vec3 z_axis; z_axis.x = target.x - position.x; @@ -315,7 +315,7 @@ static Transform transform_create(Vec3 pos, Quat rot, f32 scale) { return (Transform){ .position = pos, .rotation = rot, .scale = scale, .is_dirty = true }; } -static inline Mat4 transform_to_mat(Transform *tf) { +c_static_inline Mat4 transform_to_mat(Transform *tf) { Mat4 scale = mat4_scale(tf->scale); Mat4 rotation = mat4_rotation(tf->rotation); Mat4 translation = mat4_translation(tf->position); |