├── .gitignore ├── test_cases ├── c014_ifelse_glue.cpp ├── c004_templates_glue.cpp ├── c009_enum_flags_glue.cpp ├── include │ ├── c018_includes.h │ ├── c010_using.h │ ├── c001_c_structs.h │ ├── c017_template_functions.h │ ├── c024_cpp_bitfields.cpp │ ├── c020_destructor.h │ ├── c002_cpp_structs.h │ ├── c008_delete_method.h │ ├── c002_cpp_structs.cpp │ ├── c019_size_t.h │ ├── c023_cpp_nested_structs.cpp │ ├── c022_cpp_string.h │ ├── c005_inheritance.cpp │ ├── c013_cpp_vector.h │ ├── c005_inheritance.h │ ├── c014_ifelse.h │ ├── c015_call.h │ ├── c003_unions.h │ ├── c004_templates.h │ ├── c024_cpp_bitfields.h │ ├── c012_callback_typedefs.h │ ├── c016_for.h │ ├── c006_multiple_inheritance.h │ ├── c007_multiple_inheritance.h │ ├── c013_cpp_vector.cpp │ ├── c021_operator_overload.h │ ├── c011_index_this.h │ ├── c022_cpp_string.cpp │ └── c023_cpp_nested_structs.h ├── c012_callback_typedefs_glue.cpp ├── c016_for_glue.cpp ├── c011_index_this_glue.cpp ├── c001_c_structs_glue.cpp ├── c017_template_functions_glue.cpp ├── c024_cpp_bitfields_glue.cpp ├── c015_call_glue.cpp ├── c003_unions_glue.cpp ├── c002_cpp_structs_glue.cpp ├── c001_c_structs.zig ├── c023_cpp_nested_structs_glue.cpp ├── c017_template_functions.zig ├── c005_inheritance.cpp ├── c002_cpp_structs.zig ├── c005_inheritance_glue.cpp ├── c014_ifelse.zig ├── c022_cpp_string_glue.cpp ├── c011_index_this.zig ├── c013_cpp_vector_glue.cpp ├── c022_cpp_string.zig ├── c013_cpp_vector.zig ├── c015_call.zig ├── c004_templates.zig ├── c003_unions.zig ├── c012_callback_typedefs.zig ├── c005_inheritance.zig ├── c016_for.zig ├── c021_operator_overload_glue.cpp ├── c024_cpp_bitfields.zig └── c023_cpp_nested_structs.zig ├── use_cases ├── dotherside │ ├── DOtherSide_glue.cpp │ └── include │ │ └── DOtherSide │ │ ├── DosQDeclarative.h │ │ ├── DosQQuickImageProvider.h │ │ ├── DosIQObjectImpl.h │ │ └── DosQObject.h ├── msdfgen │ ├── include │ │ ├── resource.h │ │ ├── core │ │ │ ├── equation-solver.h │ │ │ ├── EdgeColor.h │ │ │ ├── pixel-conversion.hpp │ │ │ ├── save-tiff.h │ │ │ ├── shape-description.h │ │ │ ├── save-bmp.h │ │ │ ├── SignedDistance.h │ │ │ ├── bitmap-interpolation.hpp │ │ │ ├── Contour.h │ │ │ ├── EdgeHolder.h │ │ │ ├── contour-combiners.h │ │ │ ├── render-sdf.h │ │ │ ├── Projection.h │ │ │ ├── Bitmap.h │ │ │ ├── ShapeDistanceFinder.h │ │ │ ├── BitmapRef.hpp │ │ │ ├── edge-coloring.h │ │ │ ├── arithmetics.hpp │ │ │ ├── rasterization.h │ │ │ ├── Scanline.h │ │ │ └── msdf-error-correction.h │ │ ├── ext │ │ │ ├── resolve-shape-geometry.h │ │ │ ├── save-png.h │ │ │ └── import-svg.h │ │ └── msdfgen-ext.h │ ├── EdgeColor.zig │ ├── BitmapRef.zig │ ├── Contour.zig │ └── SignedDistance.zig ├── raylib │ └── raylib_translate_c.zig ├── SDL2 │ └── include │ │ ├── SDL_revision.h │ │ ├── SDL_opengles2_gl2platform.h │ │ ├── SDL_types.h │ │ ├── SDL_name.h │ │ ├── SDL_opengles.h │ │ ├── close_code.h │ │ ├── SDL_opengles2.h │ │ └── SDL_test_memory.h ├── JoltPhysics │ └── include │ │ ├── RegisterTypes.h │ │ ├── Physics │ │ ├── Collision │ │ │ ├── CollectFacesMode.h │ │ │ ├── BackFaceMode.h │ │ │ ├── AABoxCast.h │ │ │ ├── ActiveEdgeMode.h │ │ │ ├── CollidePointResult.h │ │ │ ├── CastResult.h │ │ │ ├── PhysicsMaterialSimple.h │ │ │ ├── GroupFilter.h │ │ │ ├── SortReverseAndStore.h │ │ │ └── PhysicsMaterial.h │ │ ├── Body │ │ │ ├── MotionType.h │ │ │ ├── BodyActivationListener.h │ │ │ ├── BodyPair.h │ │ │ ├── BodyAccess.h │ │ │ └── MotionQuality.h │ │ ├── EActivation.h │ │ ├── Vehicle │ │ │ └── VehicleAntiRollBar.h │ │ ├── PhysicsStepListener.h │ │ ├── StateRecorder.h │ │ ├── StateRecorderImpl.h │ │ └── EPhysicsUpdateError.h │ │ ├── Core │ │ ├── NonCopyable.h │ │ ├── UnorderedSet.h │ │ ├── UnorderedMap.h │ │ ├── FPFlushDenormals.h │ │ ├── Factory.h │ │ ├── Atomics.h │ │ ├── TickCounter.h │ │ ├── STLAlignedAllocator.h │ │ ├── StreamWrapper.h │ │ ├── InsertionSort.h │ │ ├── Semaphore.h │ │ ├── IssueReporting.h │ │ ├── StringTools.h │ │ ├── STLTempAllocator.h │ │ └── ByteBuffer.h │ │ ├── Jolt.h │ │ ├── Math │ │ ├── Swizzle.h │ │ ├── MathTypes.h │ │ ├── Float4.h │ │ ├── DynMatrix.h │ │ ├── Float2.h │ │ ├── Real.h │ │ ├── FindRoot.h │ │ ├── Double3.h │ │ ├── Float3.h │ │ └── Trigonometry.h │ │ ├── TriangleGrouper │ │ ├── TriangleGrouperMorton.h │ │ ├── TriangleGrouperClosestCentroid.h │ │ └── TriangleGrouper.h │ │ ├── Geometry │ │ ├── Indexify.h │ │ ├── Triangle.h │ │ ├── MortonCode.h │ │ ├── OrientedBox.h │ │ └── RayCapsule.h │ │ ├── ObjectStream │ │ ├── ObjectStreamTypes.h │ │ ├── GetPrimitiveTypeOfType.h │ │ ├── TypeDeclarations.h │ │ ├── SerializableAttributeTyped.h │ │ └── SerializableAttributeEnum.h │ │ ├── TriangleSplitter │ │ ├── TriangleSplitterMean.h │ │ ├── TriangleSplitterLongestAxis.h │ │ ├── TriangleSplitterMorton.h │ │ ├── TriangleSplitterBinning.h │ │ └── TriangleSplitterFixedLeafSize.h │ │ ├── JoltViewer.h │ │ ├── Renderer │ │ └── DebugRendererPlayback.h │ │ └── ConfigurationString.h ├── imgui │ ├── imgui_impl_opengl3_glue.cpp │ ├── include │ │ ├── LICENSE.txt │ │ └── backends │ │ │ ├── imgui_impl_dx9.h │ │ │ ├── imgui_impl_dx10.h │ │ │ ├── imgui_impl_dx11.h │ │ │ ├── imgui_impl_wgpu.h │ │ │ ├── imgui_impl_sdlrenderer.h │ │ │ ├── imgui_impl_android.h │ │ │ └── imgui_impl_allegro5.h │ ├── imgui_impl_sdl2_glue.cpp │ ├── imgui_impl_opengl3.zig │ └── imgui_impl_sdl2.zig ├── box2d │ └── include │ │ ├── b2_types.h │ │ ├── b2_timer.h │ │ ├── b2_api.h │ │ ├── b2_contact_manager.h │ │ └── box2d.h └── xatlas │ └── xatlas_glue.cpp ├── .vscode └── tasks.json └── .github └── workflows └── build.yml /.gitignore: -------------------------------------------------------------------------------- 1 | zig-out 2 | zig-cache 3 | use_cases/**/*.json 4 | .zig-cache 5 | -------------------------------------------------------------------------------- /test_cases/c014_ifelse_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c014_ifelse.h" 3 | 4 | -------------------------------------------------------------------------------- /test_cases/c004_templates_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c004_templates.h" 3 | 4 | -------------------------------------------------------------------------------- /test_cases/c009_enum_flags_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c009_enum_flags.h" 3 | 4 | -------------------------------------------------------------------------------- /use_cases/dotherside/DOtherSide_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "DOtherSide.h" 3 | 4 | -------------------------------------------------------------------------------- /test_cases/include/c018_includes.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | vec2_t sub(vec2_t a, vec2_t b); 4 | 5 | -------------------------------------------------------------------------------- /test_cases/c012_callback_typedefs_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c012_callback_typedefs.h" 3 | 4 | -------------------------------------------------------------------------------- /test_cases/include/c010_using.h: -------------------------------------------------------------------------------- 1 | // Standard types 2 | using uint = unsigned int; 3 | 4 | uint add(uint, uint); 5 | 6 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lassade/c2z/HEAD/use_cases/msdfgen/include/resource.h -------------------------------------------------------------------------------- /use_cases/raylib/raylib_translate_c.zig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lassade/c2z/HEAD/use_cases/raylib/raylib_translate_c.zig -------------------------------------------------------------------------------- /test_cases/c016_for_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c016_for.h" 3 | 4 | extern "C" void _1_foo_(int __arg0) { ::foo(__arg0); } 5 | -------------------------------------------------------------------------------- /test_cases/include/c001_c_structs.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | float x; 3 | float y; 4 | } vec2_t; 5 | 6 | vec2_t add(vec2_t a, vec2_t b); 7 | -------------------------------------------------------------------------------- /test_cases/include/c017_template_functions.h: -------------------------------------------------------------------------------- 1 | void free(void*); 2 | 3 | template void IM_DELETE(T* p) { if (p) { p->~T(); free(p); } } 4 | -------------------------------------------------------------------------------- /test_cases/include/c024_cpp_bitfields.cpp: -------------------------------------------------------------------------------- 1 | #include "c024_cpp_bitfields.h" 2 | 3 | int size_of_Bitfields(){ 4 | return sizeof(Bitfields); 5 | } 6 | -------------------------------------------------------------------------------- /test_cases/include/c020_destructor.h: -------------------------------------------------------------------------------- 1 | 2 | struct ByteBlob { 3 | unsigned char* Data; 4 | int Size; 5 | int Capacity; 6 | 7 | ~ByteBlob(); 8 | }; -------------------------------------------------------------------------------- /test_cases/c011_index_this_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c011_index_this.h" 3 | 4 | extern "C" void _1_ImAssert_(bool __arg0) { ::ImAssert(__arg0); } 5 | -------------------------------------------------------------------------------- /test_cases/c001_c_structs_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c001_c_structs.h" 3 | 4 | extern "C" vec2_t _1_add_(vec2_t a, vec2_t b) { return ::add(a, b); } 5 | -------------------------------------------------------------------------------- /test_cases/c017_template_functions_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c017_template_functions.h" 3 | 4 | extern "C" void _1_free_(void * __arg0) { ::free(__arg0); } 5 | -------------------------------------------------------------------------------- /test_cases/include/c002_cpp_structs.h: -------------------------------------------------------------------------------- 1 | struct vec2_t { 2 | static const vec2_t sZero; 3 | 4 | float x; 5 | float y; 6 | vec2_t add(vec2_t other) const; 7 | }; 8 | 9 | typedef vec2_t Vec2; -------------------------------------------------------------------------------- /test_cases/c024_cpp_bitfields_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include 3 | #include "c024_cpp_bitfields.h" 4 | 5 | extern "C" int _1_size_of_Bitfields_() { return ::size_of_Bitfields(); } 6 | -------------------------------------------------------------------------------- /test_cases/include/c008_delete_method.h: -------------------------------------------------------------------------------- 1 | class NonCopyable 2 | { 3 | public: 4 | NonCopyable() = default; 5 | NonCopyable(const NonCopyable &) = delete; 6 | void operator = (const NonCopyable &) = delete; 7 | }; 8 | -------------------------------------------------------------------------------- /test_cases/include/c002_cpp_structs.cpp: -------------------------------------------------------------------------------- 1 | #include "c002_cpp_structs.h" 2 | 3 | const vec2_t vec2_t::sZero = { 0, 0 }; 4 | 5 | vec2_t vec2_t::add(vec2_t other) const { 6 | return vec2_t { this->x + other.x, this->y + other.y }; 7 | } -------------------------------------------------------------------------------- /test_cases/c015_call_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c015_call.h" 3 | 4 | extern "C" void * _1_malloc_(unsigned long long __arg0) { return ::malloc(__arg0); } 5 | extern "C" void _1_free_(void * __arg0) { ::free(__arg0); } 6 | -------------------------------------------------------------------------------- /test_cases/include/c019_size_t.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct A { 5 | size_t a; 6 | static const A sA; 7 | 8 | A(int a); 9 | A(size_t a); 10 | ~A() {} 11 | 12 | void foo(size_t b); 13 | size_t boo(); 14 | }; -------------------------------------------------------------------------------- /test_cases/c003_unions_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c003_unions.h" 3 | 4 | extern "C" const ColorClass *_1_ColorClass_sBlack_() { return &::ColorClass::sBlack; } 5 | extern "C" const ColorClass *_1_ColorClass_sWhite_() { return &::ColorClass::sWhite; } 6 | -------------------------------------------------------------------------------- /test_cases/include/c023_cpp_nested_structs.cpp: -------------------------------------------------------------------------------- 1 | #include "c023_cpp_nested_structs.h" 2 | 3 | int test_sizeof_RootStruct() 4 | { 5 | return (int)sizeof(RootStruct); 6 | } 7 | 8 | int test_sizeof_RootUnion() 9 | { 10 | return (int)sizeof(RootUnion); 11 | } 12 | -------------------------------------------------------------------------------- /test_cases/c002_cpp_structs_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c002_cpp_structs.h" 3 | 4 | extern "C" const vec2_t *_1_vec2_t_sZero_() { return &::vec2_t::sZero; } 5 | extern "C" vec2_t _1_vec2_t_add_(const ::vec2_t *self, vec2_t other) { return self->add(other); } 6 | -------------------------------------------------------------------------------- /test_cases/c001_c_structs.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const vec2_t = extern struct { 6 | x: f32, 7 | y: f32, 8 | }; 9 | 10 | extern fn _1_add_(a: vec2_t, b: vec2_t) vec2_t; 11 | pub const add = _1_add_; 12 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_revision.h: -------------------------------------------------------------------------------- 1 | /* Generated by updaterev.sh, do not edit */ 2 | #ifdef SDL_VENDOR_INFO 3 | #define SDL_REVISION "SDL-release-2.26.5-0-gac13ca9ab (" SDL_VENDOR_INFO ")" 4 | #else 5 | #define SDL_REVISION "SDL-release-2.26.5-0-gac13ca9ab" 6 | #endif 7 | #define SDL_REVISION_NUMBER 0 8 | -------------------------------------------------------------------------------- /test_cases/c023_cpp_nested_structs_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include 3 | #include "c023_cpp_nested_structs.h" 4 | 5 | extern "C" int _1_test_sizeof_RootStruct_() { return ::test_sizeof_RootStruct(); } 6 | extern "C" int _1_test_sizeof_RootUnion_() { return ::test_sizeof_RootUnion(); } 7 | -------------------------------------------------------------------------------- /test_cases/include/c022_cpp_string.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int size_of_string(); 4 | const char *data(const std::string &input); 5 | const char *cstr(const std::string &input); 6 | int cap(const std::string &input); 7 | std::string get_str(); 8 | bool write_numbers(std::string &output, size_t count); 9 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/equation-solver.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace msdfgen { 5 | 6 | // ax^2 + bx + c = 0 7 | int solveQuadratic(double x[2], double a, double b, double c); 8 | 9 | // ax^3 + bx^2 + cx + d = 0 10 | int solveCubic(double x[3], double a, double b, double c, double d); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /test_cases/c017_template_functions.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | extern fn _1_free_(__arg0: ?*anyopaque) void; 6 | pub const free = _1_free_; 7 | 8 | pub fn IM_DELETE(comptime T: type, p: [*c]T) void { 9 | if (p) { 10 | p.deinit(); 11 | free(p); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test_cases/include/c005_inheritance.cpp: -------------------------------------------------------------------------------- 1 | #include "c005_inheritance.h" 2 | 3 | circle_t::circle_t() { this->radius = 0; } 4 | circle_t::circle_t(float radius) { this->radius = radius; } 5 | circle_t::~circle_t() { } 6 | float circle_t::area() const { return 3.14 * radius * radius; } 7 | 8 | 9 | float area(const shape_t &shape) { 10 | return shape.area(); 11 | } -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/EdgeColor.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace msdfgen { 5 | 6 | /// Edge color specifies which color channels an edge belongs to. 7 | enum EdgeColor { 8 | BLACK = 0, 9 | RED = 1, 10 | GREEN = 2, 11 | YELLOW = 3, 12 | BLUE = 4, 13 | MAGENTA = 5, 14 | CYAN = 6, 15 | WHITE = 7 16 | }; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test_cases/include/c013_cpp_vector.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::vector create(); 4 | size_t sizeof_vector_uint8_t(); 5 | const uint8_t *vector_data(const std::vector &vec); 6 | size_t vector_size(const std::vector &vec); 7 | size_t vector_capacity(const std::vector &vec); 8 | bool enumerate(std::vector& out_buf, size_t count); 9 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/pixel-conversion.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "arithmetics.hpp" 5 | 6 | namespace msdfgen { 7 | 8 | typedef unsigned char byte; 9 | 10 | inline byte pixelFloatToByte(float x) { 11 | return byte(clamp(256.f*x, 255.f)); 12 | } 13 | 14 | inline float pixelByteToFloat(byte x) { 15 | return 1.f/255.f*float(x); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test_cases/c005_inheritance.cpp: -------------------------------------------------------------------------------- 1 | // auto-generated 2 | 3 | #include "include/c005_inheritance.h" 4 | 5 | struct shape_tZimpl: public shape_t { 6 | public: 7 | float (*area_callback)(const void*) = nullptr; 8 | 9 | virtual float area() const { 10 | if (area_callback == nullptr) return shape_t::area(); 11 | else return area_callback((void*)this); 12 | } 13 | }; -------------------------------------------------------------------------------- /use_cases/msdfgen/include/ext/resolve-shape-geometry.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../core/Shape.h" 5 | 6 | #ifdef MSDFGEN_USE_SKIA 7 | 8 | namespace msdfgen { 9 | 10 | /// Resolves any intersections within the shape by subdividing its contours using the Skia library and makes sure its contours have a consistent winding. 11 | bool resolveShapeGeometry(Shape &shape); 12 | 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/save-tiff.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "BitmapRef.hpp" 5 | 6 | namespace msdfgen { 7 | 8 | /// Saves the bitmap as an uncompressed floating-point TIFF file. 9 | bool saveTiff(const BitmapConstRef &bitmap, const char *filename); 10 | bool saveTiff(const BitmapConstRef &bitmap, const char *filename); 11 | bool saveTiff(const BitmapConstRef &bitmap, const char *filename); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /test_cases/include/c005_inheritance.h: -------------------------------------------------------------------------------- 1 | struct vec2_t { 2 | float x; 3 | float y; 4 | }; 5 | 6 | struct shape_t { 7 | public: 8 | vec2_t aabb; 9 | virtual float area() const = 0; 10 | }; 11 | 12 | struct circle_t: public shape_t { 13 | public: 14 | circle_t(); 15 | circle_t(float radius); 16 | ~circle_t(); 17 | virtual float area() const; 18 | 19 | private: 20 | float radius; 21 | }; 22 | 23 | float area(const shape_t &shape); -------------------------------------------------------------------------------- /test_cases/include/c014_ifelse.h: -------------------------------------------------------------------------------- 1 | void If(int value) { 2 | if (value < 0) { 3 | return; 4 | } 5 | } 6 | 7 | bool IfElse(int value) { 8 | if (value < 0) { 9 | return false; 10 | } else { 11 | return true; 12 | } 13 | } 14 | 15 | bool IfElseIfElse(int value) { 16 | if (value < -5) { 17 | return false; 18 | } else if (value > 5) { 19 | return false; 20 | } else { 21 | return true; 22 | } 23 | } -------------------------------------------------------------------------------- /test_cases/include/c015_call.h: -------------------------------------------------------------------------------- 1 | void* malloc(unsigned long long); 2 | 3 | void free(void*); 4 | 5 | void run() { 6 | void* a = malloc(1); 7 | free(a); 8 | } 9 | 10 | class Foo { 11 | int* ptr = 0; 12 | 13 | bool init(bool val) { 14 | if (ptr == 0) { 15 | ptr = (int*)malloc(sizeof(int)); 16 | } 17 | return !val; 18 | } 19 | 20 | public: 21 | void inc() { 22 | init(true); 23 | *ptr += 1; 24 | } 25 | }; -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/RegisterTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Register all physics types with the factory 10 | extern void RegisterTypes(); 11 | 12 | /// Unregisters all types with the factory and cleans up the default material 13 | extern void UnregisterTypes(); 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /test_cases/include/c003_unions.h: -------------------------------------------------------------------------------- 1 | union Color32 2 | { 3 | unsigned int mU32; 4 | struct 5 | { 6 | unsigned char r; 7 | unsigned char g; 8 | unsigned char b; 9 | unsigned char a; 10 | }; 11 | }; 12 | 13 | struct ColorClass 14 | { 15 | static const ColorClass sBlack; 16 | static const ColorClass sWhite; 17 | 18 | union 19 | { 20 | unsigned int mU32; 21 | struct 22 | { 23 | unsigned char r; 24 | unsigned char g; 25 | unsigned char b; 26 | unsigned char a; 27 | }; 28 | }; 29 | }; -------------------------------------------------------------------------------- /test_cases/c002_cpp_structs.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const vec2_t = extern struct { 6 | x: f32, 7 | y: f32, 8 | 9 | extern fn _1_vec2_t_sZero_() *const vec2_t; 10 | pub inline fn sZero() *const vec2_t { 11 | return _1_vec2_t_sZero_(); 12 | } 13 | 14 | extern fn _1_vec2_t_add_(self: *const vec2_t, other: vec2_t) vec2_t; 15 | pub const add = _1_vec2_t_add_; 16 | }; 17 | 18 | pub const Vec2 = vec2_t; 19 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/shape-description.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include "Shape.h" 6 | 7 | namespace msdfgen { 8 | 9 | /// Deserializes a text description of a vector shape into output. 10 | bool readShapeDescription(FILE *input, Shape &output, bool *colorsSpecified = NULL); 11 | bool readShapeDescription(const char *input, Shape &output, bool *colorsSpecified = NULL); 12 | /// Serializes a shape object into a text description. 13 | bool writeShapeDescription(FILE *output, const Shape &shape); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/CollectFacesMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Whether or not to collect faces, used by CastShape and CollideShape 10 | enum class ECollectFacesMode : uint8 11 | { 12 | CollectFaces, ///< mShape1/2Face is desired 13 | NoFaces ///< mShape1/2Face is not desired 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/NonCopyable.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that makes another class non-copyable. Usage: Inherit from NonCopyable. 10 | class NonCopyable 11 | { 12 | public: 13 | NonCopyable() = default; 14 | NonCopyable(const NonCopyable &) = delete; 15 | void operator = (const NonCopyable &) = delete; 16 | }; 17 | 18 | JPH_NAMESPACE_END 19 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Jolt.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | // Project includes 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/UnorderedSet.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | template , class KeyEqual = std::equal_to> using UnorderedSet = std::unordered_set>; 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Body/MotionType.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Motion type of a physics body 10 | enum class EMotionType : uint8 11 | { 12 | Static, ///< Non movable 13 | Kinematic, ///< Movable using velocities only, does not respond to forces 14 | Dynamic, ///< Responds to forces as a normal physics object 15 | }; 16 | 17 | JPH_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/EActivation.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Enum used by AddBody to determine if the body needs to be initially active 10 | enum class EActivation 11 | { 12 | Activate, ///< Activate the body, making it part of the simulation 13 | DontActivate ///< Leave activation state as it is (will not deactivate an active body) 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /test_cases/c005_inheritance_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c005_inheritance.h" 3 | 4 | extern "C" float _1_shape_t_area_(const ::shape_t *self) { return self->area(); } 5 | extern "C" ::circle_t _1_circle_t_init_() { return ::circle_t(); } 6 | extern "C" ::circle_t _2_circle_t_init_(float radius) { return ::circle_t(radius); } 7 | extern "C" void _1_circle_t_deinit_(::circle_t *self) { self->~circle_t(); } 8 | extern "C" float _1_circle_t_area_(const ::circle_t *self) { return self->area(); } 9 | extern "C" float _1_area_(const shape_t & shape) { return ::area(shape); } 10 | -------------------------------------------------------------------------------- /test_cases/include/c004_templates.h: -------------------------------------------------------------------------------- 1 | 2 | template 3 | struct Vector { 4 | T* Data; 5 | int Size; 6 | int Capacity; 7 | 8 | inline bool empty() const { return Size == 0; } 9 | inline int size() const { return Size; } 10 | inline int size_in_bytes() const { return Size * (int)sizeof(T); } 11 | 12 | inline T& operator[](int i) { return Data[i]; } 13 | inline const T& operator[](int i) const { return Data[i]; } 14 | }; -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/UnorderedMap.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | template , class KeyEqual = std::equal_to> using UnorderedMap = std::unordered_map>>; 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /test_cases/c014_ifelse.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub fn If(value: c_int) void { 6 | if (value < 0) { 7 | return; 8 | } 9 | } 10 | pub fn IfElse(value: c_int) bool { 11 | if (value < 0) { 12 | return false; 13 | } else { 14 | return true; 15 | } 16 | } 17 | pub fn IfElseIfElse(value: c_int) bool { 18 | if (value < -5) { 19 | return false; 20 | } else if (value > 5) { 21 | return false; 22 | } else { 23 | return true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/BackFaceMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// How collision detection functions will treat back facing triangles 10 | enum class EBackFaceMode : uint8 11 | { 12 | IgnoreBackFaces, ///< Ignore collision with back facing surfaces/triangles 13 | CollideWithBackFaces, ///< Collide with back facing surfaces/triangles 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /test_cases/c022_cpp_string_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c022_cpp_string.h" 3 | 4 | extern "C" int _1_size_of_string_() { return ::size_of_string(); } 5 | extern "C" const char *_1_data_(const std::string &input) { return ::data(input); } 6 | extern "C" const char *_1_cstr_(const std::string &input) { return ::cstr(input); } 7 | extern "C" int _1_cap_(const std::string &input) { return ::cap(input); } 8 | extern "C" std::string _1_get_str_() { return ::get_str(); } 9 | extern "C" bool _1_write_numbers_(std::string &output, size_t count) { return ::write_numbers(output, count); } 10 | -------------------------------------------------------------------------------- /test_cases/include/c024_cpp_bitfields.h: -------------------------------------------------------------------------------- 1 | typedef struct Bitfields 2 | { 3 | unsigned long long bitfield1 : 10; 4 | unsigned long long bitfield2 : 10; 5 | unsigned long bitfield3 : 5; 6 | signed long bitfield4 : 5; 7 | bool bitfield5 : 2; 8 | char bitfield6 : 2; 9 | unsigned char bitfield7 : 2; 10 | int bitfield8 : 31; 11 | long long bitfield9 : 30; 12 | // TODO: Add test of 0-length bitfield here 13 | // long long : 0; 14 | long long bitfield11 : 30; 15 | } Bitfields; 16 | 17 | int size_of_Bitfields(); 18 | -------------------------------------------------------------------------------- /test_cases/include/c012_callback_typedefs.h: -------------------------------------------------------------------------------- 1 | #include "stdlib.h" 2 | 3 | struct a; 4 | struct SomeStruct; 5 | 6 | typedef int (*NoArgsCallback)(); 7 | typedef int (*SingleLetterCallback)(a); 8 | typedef void (*NamedParam)(const SomeStruct const* data); 9 | 10 | struct ImGuiInputTextCallbackData; 11 | struct ImGuiSizeCallbackData; 12 | 13 | typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData* data); 14 | typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); 15 | typedef void* (*ImGuiMemAllocFunc)(size_t sz, void* user_data); 16 | typedef void (*ImGuiMemFreeFunc)(void* ptr, void* user_data); -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "buildDebug", 8 | "type": "shell", 9 | "command": "zig build --summary failures -freference-trace", 10 | "group": "build", 11 | "problemMatcher": [ 12 | "$gcc" 13 | ], 14 | "presentation": { 15 | "clear": true, 16 | // "revealProblems": "onProblem" 17 | } 18 | }, 19 | ] 20 | } -------------------------------------------------------------------------------- /test_cases/c011_index_this.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | extern fn _1_ImAssert_(__arg0: bool) void; 6 | pub const ImAssert = _1_ImAssert_; 7 | 8 | pub const ImVec2 = extern struct { 9 | x: f32, 10 | y: f32, 11 | 12 | pub fn getPtr(self: *ImVec2, idx: usize) *f32 { 13 | //ImAssert(idx == 0 or idx == 1); 14 | return &(@as([*]f32, @ptrCast(self))[idx]); 15 | } 16 | pub fn get(self: *const ImVec2, idx: usize) f32 { 17 | //ImAssert(idx == 0 or idx == 1); 18 | return @as([*]const f32, @ptrCast(self))[idx]; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/save-bmp.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "BitmapRef.hpp" 5 | 6 | namespace msdfgen { 7 | 8 | /// Saves the bitmap as a BMP file. 9 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 10 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 11 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 12 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 13 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 14 | bool saveBmp(const BitmapConstRef &bitmap, const char *filename); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/AABoxCast.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Structure that holds AABox moving linearly through 3d space 12 | struct AABoxCast 13 | { 14 | JPH_OVERRIDE_NEW_DELETE 15 | 16 | AABox mBox; ///< Axis aligned box at starting location 17 | Vec3 mDirection; ///< Direction and length of the cast (anything beyond this length will not be reported as a hit) 18 | }; 19 | 20 | JPH_NAMESPACE_END 21 | -------------------------------------------------------------------------------- /test_cases/c013_cpp_vector_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c013_cpp_vector.h" 3 | 4 | extern "C" std::vector _1_create_() { return ::create(); } 5 | extern "C" size_t _1_sizeof_vector_uint8_t_() { return ::sizeof_vector_uint8_t(); } 6 | extern "C" const uint8_t * _1_vector_data_(const std::vector & vec) { return ::vector_data(vec); } 7 | extern "C" size_t _1_vector_size_(const std::vector & vec) { return ::vector_size(vec); } 8 | extern "C" size_t _1_vector_capacity_(const std::vector & vec) { return ::vector_capacity(vec); } 9 | extern "C" bool _1_enumerate_(std::vector & out_buf, size_t count) { return ::enumerate(out_buf, count); } 10 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/SignedDistance.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace msdfgen { 5 | 6 | /// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment. 7 | class SignedDistance { 8 | 9 | public: 10 | double distance; 11 | double dot; 12 | 13 | SignedDistance(); 14 | SignedDistance(double dist, double d); 15 | 16 | friend bool operator<(SignedDistance a, SignedDistance b); 17 | friend bool operator>(SignedDistance a, SignedDistance b); 18 | friend bool operator<=(SignedDistance a, SignedDistance b); 19 | friend bool operator>=(SignedDistance a, SignedDistance b); 20 | 21 | }; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test_cases/c022_cpp_string.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | const cpp = @import("cpp"); 4 | 5 | extern fn _1_size_of_string_() c_int; 6 | pub const size_of_string = _1_size_of_string_; 7 | 8 | extern fn _1_data_(input: *const cpp.String) [*c]const u8; 9 | pub const data = _1_data_; 10 | 11 | extern fn _1_cstr_(input: *const cpp.String) [*c]const u8; 12 | pub const cstr = _1_cstr_; 13 | 14 | extern fn _1_cap_(input: *const cpp.String) c_int; 15 | pub const cap = _1_cap_; 16 | 17 | extern fn _1_get_str_() cpp.String; 18 | pub const get_str = _1_get_str_; 19 | 20 | extern fn _1_write_numbers_(output: *cpp.String, count: usize) bool; 21 | pub const write_numbers = _1_write_numbers_; 22 | -------------------------------------------------------------------------------- /test_cases/include/c016_for.h: -------------------------------------------------------------------------------- 1 | void foo(int); 2 | 3 | void for1() { 4 | for (int i = 0; i < 5; i++) foo(i); 5 | } 6 | 7 | void for2() { 8 | for (int i = 0; i < 5; i++) { 9 | foo(i); 10 | } 11 | } 12 | 13 | void for3() { 14 | for (int i = 0; i < 5; i++) { 15 | foo(i); 16 | } 17 | for (int i = 5; i < 10; i++) { 18 | foo(i); 19 | } 20 | } 21 | 22 | void for4() { 23 | for (int i = 0, j = 8; i < 5; i++, j--) { 24 | foo(i); 25 | } 26 | } 27 | 28 | void for5() { 29 | int i = 0, j = 0; 30 | 31 | for (; i < 5; i++) { 32 | for (; j < 5; j+=2) foo(i * j); 33 | } 34 | 35 | for (i = 0; i < 5; i++) foo(i); 36 | 37 | i += j += 2; 38 | } -------------------------------------------------------------------------------- /use_cases/msdfgen/include/ext/save-png.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../core/BitmapRef.hpp" 5 | 6 | #ifndef MSDFGEN_DISABLE_PNG 7 | 8 | namespace msdfgen { 9 | 10 | /// Saves the bitmap as a PNG file. 11 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 12 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 13 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 14 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 15 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 16 | bool savePng(const BitmapConstRef &bitmap, const char *filename); 17 | 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Swizzle.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Enum indicating which component to use when swizzling 10 | enum 11 | { 12 | SWIZZLE_X = 0, ///< Use the X component 13 | SWIZZLE_Y = 1, ///< Use the Y component 14 | SWIZZLE_Z = 2, ///< Use the Z component 15 | SWIZZLE_W = 3, ///< Use the W component 16 | SWIZZLE_UNUSED = 2, ///< We always use the Z component when we don't specifically want to initialize a value, this is consistent with what is done in Vec3(x, y, z), Vec3(Float3 &) and Vec3::sLoadFloat3Unsafe 17 | }; 18 | 19 | JPH_NAMESPACE_END 20 | -------------------------------------------------------------------------------- /use_cases/msdfgen/EdgeColor.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub const EdgeColor = extern struct { 4 | bits: c_int = 0, 5 | 6 | pub const BLACK: EdgeColor = .{ .bits = @intCast(c_uint, 0) }; 7 | pub const RED: EdgeColor = .{ .bits = @intCast(c_uint, 1) }; 8 | pub const GREEN: EdgeColor = .{ .bits = @intCast(c_uint, 2) }; 9 | pub const YELLOW: EdgeColor = .{ .bits = @intCast(c_uint, 3) }; 10 | pub const BLUE: EdgeColor = .{ .bits = @intCast(c_uint, 4) }; 11 | pub const MAGENTA: EdgeColor = .{ .bits = @intCast(c_uint, 5) }; 12 | pub const CYAN: EdgeColor = .{ .bits = @intCast(c_uint, 6) }; 13 | pub const WHITE: EdgeColor = .{ .bits = @intCast(c_uint, 7) }; 14 | 15 | // pub usingnamespace cpp.FlagsMixin(EdgeColor); 16 | }; 17 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleGrouper/TriangleGrouperMorton.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N according to morton code of centroid. 12 | /// Time complexity: O(N log(N)) 13 | class TriangleGrouperMorton : public TriangleGrouper 14 | { 15 | public: 16 | // See: TriangleGrouper::Group 17 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) override; 18 | }; 19 | 20 | JPH_NAMESPACE_END 21 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/ActiveEdgeMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// How to treat active/inactive edges. 10 | /// An active edge is an edge that either has no neighbouring edge or if the angle between the two connecting faces is too large, see: ActiveEdges 11 | enum class EActiveEdgeMode : uint8 12 | { 13 | CollideOnlyWithActive, ///< Do not collide with inactive edges. For physics simulation, this gives less ghost collisions. 14 | CollideWithAll, ///< Collide with all edges. Use this when you're interested in all collisions. 15 | }; 16 | 17 | JPH_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /test_cases/include/c006_multiple_inheritance.h: -------------------------------------------------------------------------------- 1 | // pub const shape_t = extern struct { 2 | // vtable: *const anyopaque, 3 | // id: c_int, 4 | // }; 5 | struct shape_t { 6 | public: 7 | int id; 8 | virtual float area() const = 0; 9 | }; 10 | 11 | // pub const renderable_t = extern struct { 12 | // vtable: *const anyopaque, 13 | // mat: c_int, 14 | // }; 15 | struct renderable_t { 16 | public: 17 | int mat; 18 | virtual float render() const = 0; 19 | }; 20 | 21 | // pub const circle_t = extern struct { 22 | // base0: shape_t, 23 | // base1: renderable_t, 24 | // radius: f32, 25 | // } 26 | struct circle_t: public shape_t, public renderable_t { 27 | public: 28 | float radius; 29 | virtual float render() const; 30 | virtual float area() const; 31 | }; -------------------------------------------------------------------------------- /test_cases/c013_cpp_vector.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | const cpp = @import("cpp"); 4 | 5 | extern fn _1_create_() cpp.Vector(u8); 6 | pub const create = _1_create_; 7 | 8 | extern fn _1_sizeof_vector_uint8_t_() usize; 9 | pub const sizeof_vector_uint8_t = _1_sizeof_vector_uint8_t_; 10 | 11 | extern fn _1_vector_data_(vec: *const cpp.Vector(u8)) [*c]const u8; 12 | pub const vector_data = _1_vector_data_; 13 | 14 | extern fn _1_vector_size_(vec: *const cpp.Vector(u8)) usize; 15 | pub const vector_size = _1_vector_size_; 16 | 17 | extern fn _1_vector_capacity_(vec: *const cpp.Vector(u8)) usize; 18 | pub const vector_capacity = _1_vector_capacity_; 19 | 20 | extern fn _1_enumerate_(out_buf: *cpp.Vector(u8), count: usize) bool; 21 | pub const enumerate = _1_enumerate_; 22 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_opengles2_gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* 5 | ** Copyright 2017-2020 The Khronos Group Inc. 6 | ** SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 10 | * 11 | * Adopters may modify khrplatform.h and this file to suit their platform. 12 | * Please contribute modifications back to Khronos as pull requests on the 13 | * public github repository: 14 | * https://github.com/KhronosGroup/OpenGL-Registry 15 | */ 16 | 17 | /*#include */ 18 | 19 | #ifndef GL_APICALL 20 | #define GL_APICALL KHRONOS_APICALL 21 | #endif 22 | 23 | #ifndef GL_APIENTRY 24 | #define GL_APIENTRY KHRONOS_APIENTRY 25 | #endif 26 | 27 | #endif /* __gl2platform_h_ */ 28 | -------------------------------------------------------------------------------- /test_cases/c015_call.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | extern fn _1_malloc_(__arg0: c_ulonglong) ?*anyopaque; 6 | pub const malloc = _1_malloc_; 7 | 8 | extern fn _1_free_(__arg0: ?*anyopaque) void; 9 | pub const free = _1_free_; 10 | 11 | pub fn run() void { 12 | var a: ?*anyopaque = malloc(@as(c_ulonglong, @intCast(1))); 13 | free(a); 14 | } 15 | pub const Foo = extern struct { 16 | ptr: [*c]c_int, 17 | 18 | pub fn init(self: *Foo, val: bool) bool { 19 | if (self.ptr == null) { 20 | self.ptr = @as([*c]c_int, @ptrCast(malloc(@sizeOf(c_int)))); 21 | } 22 | return !val; 23 | } 24 | pub fn inc(self: *Foo) void { 25 | self.init(true); 26 | self.ptr.* += 1; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/bitmap-interpolation.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "arithmetics.hpp" 5 | #include "Vector2.h" 6 | #include "BitmapRef.hpp" 7 | 8 | namespace msdfgen { 9 | 10 | template 11 | static void interpolate(T *output, const BitmapConstRef &bitmap, Point2 pos) { 12 | pos -= .5; 13 | int l = (int) floor(pos.x); 14 | int b = (int) floor(pos.y); 15 | int r = l+1; 16 | int t = b+1; 17 | double lr = pos.x-l; 18 | double bt = pos.y-b; 19 | l = clamp(l, bitmap.width-1), r = clamp(r, bitmap.width-1); 20 | b = clamp(b, bitmap.height-1), t = clamp(t, bitmap.height-1); 21 | for (int i = 0; i < N; ++i) 22 | output[i] = mix(mix(bitmap(l, b)[i], bitmap(r, b)[i], lr), mix(bitmap(l, t)[i], bitmap(r, t)[i], lr), bt); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /test_cases/include/c007_multiple_inheritance.h: -------------------------------------------------------------------------------- 1 | // pub const shape_t = extern struct { 2 | // vtable: *const anyopaque, 3 | // id: c_int, 4 | // }; 5 | struct shape_t { 6 | public: 7 | int id; 8 | }; 9 | 10 | // pub const renderable_t = extern struct { 11 | // vtable: *const anyopaque, 12 | // mat: c_int, 13 | // }; 14 | struct renderable_t { 15 | public: 16 | int mat; 17 | virtual float render() const = 0; 18 | }; 19 | 20 | // pub const circle_t = extern struct { 21 | // base1: renderable_t, // polymorphic classes always start frist, despite the declaration order 22 | // base0: shape_t, 23 | // radius: f32, 24 | // } 25 | struct circle_t: public shape_t, public renderable_t { 26 | public: 27 | float radius; 28 | virtual float render() const; 29 | virtual float area() const; 30 | }; -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/MathTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class Vec3; 10 | class DVec3; 11 | class Vec4; 12 | class UVec4; 13 | class Vec8; 14 | class UVec8; 15 | class Quat; 16 | class Mat44; 17 | class DMat44; 18 | 19 | // Types to use for passing arguments to functions 20 | using Vec3Arg = Vec3; 21 | #ifdef JPH_USE_AVX 22 | using DVec3Arg = DVec3; 23 | #else 24 | using DVec3Arg = const DVec3 &; 25 | #endif 26 | using Vec4Arg = Vec4; 27 | using UVec4Arg = UVec4; 28 | using Vec8Arg = Vec8; 29 | using UVec8Arg = UVec8; 30 | using QuatArg = Quat; 31 | using Mat44Arg = const Mat44 &; 32 | using DMat44Arg = const DMat44 &; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleGrouper/TriangleGrouperClosestCentroid.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N. 12 | /// Starts with centroid with lowest X coordinate and finds N closest centroids, this repeats until all groups have been found. 13 | /// Time complexity: O(N^2) 14 | class TriangleGrouperClosestCentroid : public TriangleGrouper 15 | { 16 | public: 17 | // See: TriangleGrouper::Group 18 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) override; 19 | }; 20 | 21 | JPH_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /test_cases/include/c013_cpp_vector.cpp: -------------------------------------------------------------------------------- 1 | #include "c013_cpp_vector.h" 2 | 3 | std::vector create() 4 | { 5 | auto tmp = std::vector(); 6 | tmp.push_back(0); 7 | tmp.push_back(1); 8 | tmp.push_back(2); 9 | return tmp; 10 | } 11 | 12 | size_t sizeof_vector_uint8_t() 13 | { 14 | return sizeof(std::vector); 15 | } 16 | 17 | const uint8_t *vector_data(const std::vector &vec) 18 | { 19 | return vec.data(); 20 | } 21 | 22 | size_t vector_size(const std::vector &vec) 23 | { 24 | return vec.size(); 25 | } 26 | 27 | size_t vector_capacity(const std::vector &vec) 28 | { 29 | return vec.capacity(); 30 | } 31 | 32 | bool enumerate(std::vector& out_buf, size_t count) 33 | { 34 | for (size_t i = 0; i < count; i++) 35 | { 36 | out_buf.push_back(i); 37 | } 38 | return true; 39 | } 40 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/msdfgen-ext.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | * MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR 6 | * --------------------------------------------- 7 | * A utility by Viktor Chlumsky, (c) 2014 - 2023 8 | * 9 | * The extension module provides ways to easily load input and save output using popular formats. 10 | * 11 | * Third party dependencies in extension module: 12 | * - Skia by Google 13 | * (to resolve self-intersecting paths) 14 | * - FreeType 2 15 | * (to load input font files) 16 | * - TinyXML 2 by Lee Thomason 17 | * (to aid in parsing input SVG files) 18 | * - libpng by the PNG Development Group 19 | * - or LodePNG by Lode Vandevenne 20 | * (to save output PNG images) 21 | * 22 | */ 23 | 24 | #include "ext/resolve-shape-geometry.h" 25 | #include "ext/save-png.h" 26 | #include "ext/import-svg.h" 27 | #include "ext/import-font.h" 28 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Geometry/Indexify.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Take a list of triangles and get the unique set of vertices and use them to create indexed triangles. 13 | /// Vertices that are less than inVertexWeldDistance apart will be combined to a single vertex. 14 | void Indexify(const TriangleList &inTriangles, VertexList &outVertices, IndexedTriangleList &outTriangles, float inVertexWeldDistance = 1.0e-4f); 15 | 16 | /// Take a list of indexed triangles and unpack them 17 | void Deindexify(const VertexList &inVertices, const IndexedTriangleList &inTriangles, TriangleList &outTriangles); 18 | 19 | JPH_NAMESPACE_END 20 | -------------------------------------------------------------------------------- /use_cases/msdfgen/BitmapRef.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub const byte = u8; 4 | 5 | pub fn BitmapRef(comptime T: type, comptime N: c_int) type { 6 | return extern struct { 7 | const Self = @This(); 8 | 9 | pixels: [*c]T, 10 | width: c_int, 11 | height: c_int, 12 | 13 | pub inline fn call(self: *const Self, x: c_int, y: c_int) [*c]T { 14 | return self.pixels + N * (self.width * y + x); 15 | } 16 | }; 17 | } 18 | 19 | pub fn BitmapConstRef(comptime T: type, comptime N: c_int) type { 20 | return extern struct { 21 | const Self = @This(); 22 | 23 | pixels: [*c]const T, 24 | width: c_int, 25 | height: c_int, 26 | 27 | pub inline fn call(self: *const Self, x: c_int, y: c_int) [*c]const T { 28 | return self.pixels + N * (self.width * y + x); 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ObjectStream/ObjectStreamTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | // Note: Order is important, an enum is created and its value is stored in a binary stream! 6 | JPH_DECLARE_PRIMITIVE(uint8) 7 | JPH_DECLARE_PRIMITIVE(uint16) 8 | JPH_DECLARE_PRIMITIVE(int) 9 | JPH_DECLARE_PRIMITIVE(uint32) 10 | JPH_DECLARE_PRIMITIVE(uint64) 11 | JPH_DECLARE_PRIMITIVE(float) 12 | JPH_DECLARE_PRIMITIVE(bool) 13 | JPH_DECLARE_PRIMITIVE(String) 14 | JPH_DECLARE_PRIMITIVE(Float3) 15 | JPH_DECLARE_PRIMITIVE(Vec3) 16 | JPH_DECLARE_PRIMITIVE(Vec4) 17 | JPH_DECLARE_PRIMITIVE(Quat) 18 | JPH_DECLARE_PRIMITIVE(Mat44) 19 | JPH_DECLARE_PRIMITIVE(double) 20 | JPH_DECLARE_PRIMITIVE(DVec3) 21 | JPH_DECLARE_PRIMITIVE(DMat44) 22 | JPH_DECLARE_PRIMITIVE(Double3) 23 | 24 | #undef JPH_DECLARE_PRIMITIVE 25 | -------------------------------------------------------------------------------- /test_cases/include/c021_operator_overload.h: -------------------------------------------------------------------------------- 1 | 2 | struct ImVec2 { 3 | float x, y; 4 | 5 | ImVec2(); 6 | ImVec2(float x, float y); 7 | 8 | float& operator[](int idx); 9 | float operator[](int idx) const; 10 | 11 | ImVec2 operator*(const float rhs) const; 12 | ImVec2& operator*=(const float rhs); 13 | 14 | ImVec2 operator/(const float rhs) const; 15 | ImVec2& operator/=(const float rhs); 16 | 17 | ImVec2 operator+(const ImVec2& rhs) const; 18 | ImVec2& operator+=(const ImVec2& rhs); 19 | 20 | ImVec2 operator-(const ImVec2& rhs) const; 21 | ImVec2& operator-=(const ImVec2& rhs); 22 | }; 23 | 24 | struct ImVec4 { 25 | float x, y, y, z; 26 | }; 27 | 28 | static ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs); 29 | static ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs); 30 | static ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs); 31 | -------------------------------------------------------------------------------- /test_cases/c004_templates.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub fn Vector(comptime T: type) type { 6 | return extern struct { 7 | const Self = @This(); 8 | 9 | Data: [*c]T, 10 | Size: c_int, 11 | Capacity: c_int, 12 | 13 | pub inline fn empty(self: *const Self) bool { 14 | return self.Size == 0; 15 | } 16 | pub inline fn size(self: *const Self) c_int { 17 | return self.Size; 18 | } 19 | pub inline fn size_in_bytes(self: *const Self) c_int { 20 | return self.Size * @as(c_int, @sizeOf(T)); 21 | } 22 | pub inline fn getPtr(self: *Self, i: c_int) *T { 23 | return self.Data[i]; 24 | } 25 | pub inline fn get(self: *const Self, i: c_int) *const T { 26 | return self.Data[i]; 27 | } 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /test_cases/c003_unions.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const Color32 = extern struct { 6 | mU32: c_uint, 7 | __field0: extern struct { 8 | r: u8, 9 | g: u8, 10 | b: u8, 11 | a: u8, 12 | }, 13 | }; 14 | 15 | pub const ColorClass = extern struct { 16 | __field0: extern union { 17 | mU32: c_uint, 18 | __field0: extern struct { 19 | r: u8, 20 | g: u8, 21 | b: u8, 22 | a: u8, 23 | }, 24 | }, 25 | 26 | extern fn _1_ColorClass_sBlack_() *const ColorClass; 27 | pub inline fn sBlack() *const ColorClass { 28 | return _1_ColorClass_sBlack_(); 29 | } 30 | 31 | extern fn _1_ColorClass_sWhite_() *const ColorClass; 32 | pub inline fn sWhite() *const ColorClass { 33 | return _1_ColorClass_sWhite_(); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /test_cases/c012_callback_typedefs.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const NoArgsCallback = ?*const fn () callconv(.C) c_int; 6 | 7 | pub const SingleLetterCallback = ?*const fn (a) callconv(.C) c_int; 8 | 9 | pub const NamedParam = ?*const fn ([*c]const SomeStruct) callconv(.C) void; 10 | 11 | pub const ImGuiInputTextCallback = ?*const fn ([*c]ImGuiInputTextCallbackData) callconv(.C) c_int; 12 | 13 | pub const ImGuiSizeCallback = ?*const fn ([*c]ImGuiSizeCallbackData) callconv(.C) void; 14 | 15 | pub const ImGuiMemAllocFunc = ?*const fn (usize, ?*anyopaque) callconv(.C) ?*anyopaque; 16 | 17 | pub const ImGuiMemFreeFunc = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void; 18 | 19 | // opaques 20 | 21 | const a = anyopaque; 22 | const SomeStruct = anyopaque; 23 | const ImGuiInputTextCallbackData = anyopaque; 24 | const ImGuiSizeCallbackData = anyopaque; 25 | -------------------------------------------------------------------------------- /test_cases/include/c011_index_this.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void ImAssert(bool); 5 | #define IM_ASSERT(_EXPR) ImAssert(_EXPR) 6 | 7 | struct ImVec2 8 | { 9 | float x, y; 10 | constexpr ImVec2() : x(0.0f), y(0.0f) { } 11 | constexpr ImVec2(float _x, float _y) : x(_x), y(_y) { } 12 | float& operator[] (size_t idx) { IM_ASSERT(idx == 0 || idx == 1); return ((float*)(void*)(char*)this)[idx]; } // We very rarely use this [] operator, so the assert overhead is fine. 13 | float operator[] (size_t idx) const { IM_ASSERT(idx == 0 || idx == 1); return ((const float*)(const void*)(const char*)this)[idx]; } 14 | #ifdef IM_VEC2_CLASS_EXTRA 15 | IM_VEC2_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2. 16 | #endif 17 | }; 18 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/CollidePointResult.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds the result of colliding a point against a shape 13 | class CollidePointResult 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For point queries there is no sensible return value. 19 | inline float GetEarlyOutFraction() const { return 0.0f; } 20 | 21 | BodyID mBodyID; ///< Body that was hit 22 | SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against 23 | }; 24 | 25 | JPH_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleSplitter/TriangleSplitterMean.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using mean of axis with biggest centroid deviation 12 | class TriangleSplitterMean : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterMean(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterMean"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleSplitter/TriangleSplitterLongestAxis.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using center of bounding box with longest axis 12 | class TriangleSplitterLongestAxis : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterLongestAxis(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterLongestAxis"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Float4.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that holds 4 float values. Convert to Vec4 to perform calculations. 10 | class [[nodiscard]] Float4 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | Float4() = default; ///< Intentionally not initialized for performance reasons 16 | Float4(const Float4 &inRHS) = default; 17 | Float4(float inX, float inY, float inZ, float inW) : x(inX), y(inY), z(inZ), w(inW) { } 18 | 19 | float operator [] (int inCoordinate) const 20 | { 21 | JPH_ASSERT(inCoordinate < 4); 22 | return *(&x + inCoordinate); 23 | } 24 | 25 | float x; 26 | float y; 27 | float z; 28 | float w; 29 | }; 30 | 31 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 32 | 33 | JPH_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /use_cases/imgui/imgui_impl_opengl3_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "imgui_impl_opengl3.h" 3 | 4 | extern "C" bool _1_ImGui_ImplOpenGL3_Init_(const char * glsl_version) { return ::ImGui_ImplOpenGL3_Init(glsl_version); } 5 | extern "C" void _1_ImGui_ImplOpenGL3_Shutdown_() { ::ImGui_ImplOpenGL3_Shutdown(); } 6 | extern "C" void _1_ImGui_ImplOpenGL3_NewFrame_() { ::ImGui_ImplOpenGL3_NewFrame(); } 7 | extern "C" void _1_ImGui_ImplOpenGL3_RenderDrawData_(ImDrawData * draw_data) { ::ImGui_ImplOpenGL3_RenderDrawData(draw_data); } 8 | extern "C" bool _1_ImGui_ImplOpenGL3_CreateFontsTexture_() { return ::ImGui_ImplOpenGL3_CreateFontsTexture(); } 9 | extern "C" void _1_ImGui_ImplOpenGL3_DestroyFontsTexture_() { ::ImGui_ImplOpenGL3_DestroyFontsTexture(); } 10 | extern "C" bool _1_ImGui_ImplOpenGL3_CreateDeviceObjects_() { return ::ImGui_ImplOpenGL3_CreateDeviceObjects(); } 11 | extern "C" void _1_ImGui_ImplOpenGL3_DestroyDeviceObjects_() { ::ImGui_ImplOpenGL3_DestroyDeviceObjects(); } 12 | -------------------------------------------------------------------------------- /test_cases/include/c022_cpp_string.cpp: -------------------------------------------------------------------------------- 1 | #include "c022_cpp_string.h" 2 | 3 | int size_of_string() 4 | { 5 | return sizeof(std::string); 6 | } 7 | 8 | const char *data(const std::string &input) 9 | { 10 | return input.data(); 11 | } 12 | 13 | const char *cstr(const std::string &input) 14 | { 15 | return input.c_str(); 16 | } 17 | 18 | int cap(const std::string &input) 19 | { 20 | return (int)input.capacity(); 21 | } 22 | 23 | std::string get_str() 24 | { 25 | return std::string("Hello, World!"); 26 | } 27 | 28 | bool write_numbers(std::string &output, size_t count) 29 | { 30 | if (output.length() > 0) 31 | { 32 | output.push_back(','); 33 | output.push_back(' '); 34 | } 35 | 36 | for (size_t i = 0; i < count; i++) 37 | { 38 | output.push_back('0' + i); 39 | if (i < (count - 1)) 40 | { 41 | output.push_back(','); 42 | output.push_back(' '); 43 | } 44 | } 45 | 46 | return true; 47 | } 48 | -------------------------------------------------------------------------------- /test_cases/c005_inheritance.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const vec2_t = extern struct { 6 | x: f32, 7 | y: f32, 8 | }; 9 | 10 | pub const shape_t = extern struct { 11 | vtable: *const anyopaque, 12 | 13 | aabb: vec2_t, 14 | 15 | extern fn _1_shape_t_area_(self: *const shape_t) f32; 16 | pub const area = _1_shape_t_area_; 17 | }; 18 | 19 | pub const circle_t = extern struct { 20 | base: shape_t, 21 | 22 | radius: f32, 23 | 24 | extern fn _1_circle_t_init_() circle_t; 25 | pub const init = _1_circle_t_init_; 26 | 27 | extern fn _2_circle_t_init_(radius: f32) circle_t; 28 | pub const initRadius = _2_circle_t_init_; 29 | 30 | extern fn _1_circle_t_deinit_(self: *circle_t) void; 31 | pub const deinit = _1_circle_t_deinit_; 32 | 33 | extern fn _1_circle_t_area_(self: *const circle_t) f32; 34 | pub const area = _1_circle_t_area_; 35 | }; 36 | 37 | extern fn _1_area_(shape: *const shape_t) f32; 38 | pub const area = _1_area_; 39 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/DynMatrix.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Dynamic resizable matrix class 10 | class [[nodiscard]] DynMatrix 11 | { 12 | public: 13 | /// Constructor 14 | DynMatrix(const DynMatrix &) = default; 15 | DynMatrix(uint inRows, uint inCols) : mRows(inRows), mCols(inCols) { mElements.resize(inRows * inCols); } 16 | 17 | /// Access an element 18 | float operator () (uint inRow, uint inCol) const { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; } 19 | float & operator () (uint inRow, uint inCol) { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; } 20 | 21 | /// Get dimensions 22 | uint GetCols() const { return mCols; } 23 | uint GetRows() const { return mRows; } 24 | 25 | private: 26 | uint mRows; 27 | uint mCols; 28 | Array mElements; 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleSplitter/TriangleSplitterMorton.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using Morton codes, see: http://devblogs.nvidia.com/parallelforall/thinking-parallel-part-iii-tree-construction-gpu/ 12 | class TriangleSplitterMorton : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterMorton(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterMorton"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | 27 | private: 28 | // Precalculated Morton codes 29 | Array mMortonCodes; 30 | }; 31 | 32 | JPH_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Float2.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that holds 2 floats, used as a storage class mainly. 10 | class [[nodiscard]] Float2 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | Float2() = default; ///< Intentionally not initialized for performance reasons 16 | Float2(const Float2 &inRHS) = default; 17 | Float2(float inX, float inY) : x(inX), y(inY) { } 18 | 19 | bool operator == (const Float2 &inRHS) const { return x == inRHS.x && y == inRHS.y; } 20 | bool operator != (const Float2 &inRHS) const { return x != inRHS.x || y != inRHS.y; } 21 | 22 | /// To String 23 | friend ostream & operator << (ostream &inStream, const Float2 &inV) 24 | { 25 | inStream << inV.x << ", " << inV.y; 26 | return inStream; 27 | } 28 | 29 | float x; 30 | float y; 31 | }; 32 | 33 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 34 | 35 | JPH_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/Contour.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include "EdgeHolder.h" 6 | 7 | namespace msdfgen { 8 | 9 | /// A single closed contour of a shape. 10 | class Contour { 11 | 12 | public: 13 | /// The sequence of edges that make up the contour. 14 | std::vector edges; 15 | 16 | /// Adds an edge to the contour. 17 | void addEdge(const EdgeHolder &edge); 18 | #ifdef MSDFGEN_USE_CPP11 19 | void addEdge(EdgeHolder &&edge); 20 | #endif 21 | /// Creates a new edge in the contour and returns its reference. 22 | EdgeHolder & addEdge(); 23 | /// Adjusts the bounding box to fit the contour. 24 | void bound(double &l, double &b, double &r, double &t) const; 25 | /// Adjusts the bounding box to fit the contour border's mitered corners. 26 | void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const; 27 | /// Computes the winding of the contour. Returns 1 if positive, -1 if negative. 28 | int winding() const; 29 | /// Reverses the sequence of edges on the contour. 30 | void reverse(); 31 | 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /use_cases/dotherside/include/DOtherSide/DosQDeclarative.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2020 Filippo Cucchetto. 3 | Contact: https://github.com/filcuc/dotherside 4 | 5 | This file is part of the DOtherSide library. 6 | 7 | The DOtherSide library is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version. 10 | 11 | The DOtherSide library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with the DOtherSide library. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "DOtherSide/DOtherSideTypes.h" 23 | 24 | namespace DOS { 25 | int dosQmlRegisterType(QmlRegisterType args); 26 | int dosQmlRegisterSingletonType(QmlRegisterType args); 27 | } 28 | -------------------------------------------------------------------------------- /use_cases/imgui/include/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2023 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Real.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | #ifdef JPH_DOUBLE_PRECISION 13 | 14 | // Define real to double 15 | using Real = double; 16 | using Real3 = Double3; 17 | using RVec3 = DVec3; 18 | using RVec3Arg = DVec3Arg; 19 | using RMat44 = DMat44; 20 | using RMat44Arg = DMat44Arg; 21 | 22 | #define JPH_RVECTOR_ALIGNMENT JPH_DVECTOR_ALIGNMENT 23 | 24 | #else 25 | 26 | // Define real to float 27 | using Real = float; 28 | using Real3 = Float3; 29 | using RVec3 = Vec3; 30 | using RVec3Arg = Vec3Arg; 31 | using RMat44 = Mat44; 32 | using RMat44Arg = Mat44Arg; 33 | 34 | #define JPH_RVECTOR_ALIGNMENT JPH_VECTOR_ALIGNMENT 35 | 36 | #endif // JPH_DOUBLE_PRECISION 37 | 38 | // Put the 'real' operator in a namespace so that users can opt in to use it: 39 | // using namespace JPH::literals; 40 | namespace literals { 41 | constexpr Real operator "" _r (long double inValue) { return Real(inValue); } 42 | }; 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/FindRoot.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Find the roots of \f$inA \: x^2 + inB \: x + inC = 0\f$. 10 | /// @return The number of roots, actual roots in outX1 and outX2. 11 | /// If number of roots returned is 1 then outX1 == outX2. 12 | template 13 | inline int FindRoot(const T inA, const T inB, const T inC, T &outX1, T &outX2) 14 | { 15 | // Check if this is a linear equation 16 | if (inA == T(0)) 17 | { 18 | // Check if this is a constant equation 19 | if (inB == T(0)) 20 | return 0; 21 | 22 | // Linear equation with 1 solution 23 | outX1 = outX2 = -inC / inB; 24 | return 1; 25 | } 26 | 27 | // See Numerical Recipes in C, Chapter 5.6 Quadratic and Cubic Equations 28 | T det = Square(inB) - T(4) * inA * inC; 29 | if (det < T(0)) 30 | return 0; 31 | T q = (inB + Sign(inB) * sqrt(det)) / T(-2); 32 | outX1 = q / inA; 33 | if (q == T(0)) 34 | { 35 | outX2 = outX1; 36 | return 1; 37 | } 38 | outX2 = inC / q; 39 | return 2; 40 | } 41 | 42 | JPH_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleGrouper/TriangleGrouper.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N (according to closeness) 12 | class TriangleGrouper 13 | { 14 | public: 15 | /// Virtual destructor 16 | virtual ~TriangleGrouper() = default; 17 | 18 | /// Group a batch of indexed triangles 19 | /// @param inVertices The list of vertices 20 | /// @param inTriangles The list of indexed triangles (indexes into inVertices) 21 | /// @param inGroupSize How big each group should be 22 | /// @param outGroupedTriangleIndices An ordered list of indices (indexing into inTriangles), contains groups of inGroupSize large worth of indices to triangles that are grouped together. If the triangle count is not an exact multiple of inGroupSize the last batch will be smaller. 23 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) = 0; 24 | }; 25 | 26 | JPH_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/CastResult.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds a ray cast or other object cast hit 13 | class BroadPhaseCastResult 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For rays/cast shapes we can just use the collision fraction. 19 | inline float GetEarlyOutFraction() const { return mFraction; } 20 | 21 | BodyID mBodyID; ///< Body that was hit 22 | float mFraction = 1.0f + FLT_EPSILON; ///< Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start) 23 | }; 24 | 25 | /// Specialization of cast result against a shape 26 | class RayCastResult : public BroadPhaseCastResult 27 | { 28 | public: 29 | JPH_OVERRIDE_NEW_DELETE 30 | 31 | SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against 32 | }; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /use_cases/imgui/imgui_impl_sdl2_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "imgui_impl_sdl2.h" 3 | 4 | extern "C" bool _1_ImGui_ImplSDL2_Init_(SDL_Window * window, SDL_Renderer * renderer, void * sdl_gl_context) { return ::ImGui_ImplSDL2_Init(window, renderer, sdl_gl_context); } 5 | extern "C" bool _1_ImGui_ImplSDL2_InitForOpenGL_(SDL_Window * window, void * sdl_gl_context) { return ::ImGui_ImplSDL2_InitForOpenGL(window, sdl_gl_context); } 6 | extern "C" bool _1_ImGui_ImplSDL2_InitForVulkan_(SDL_Window * window) { return ::ImGui_ImplSDL2_InitForVulkan(window); } 7 | extern "C" bool _1_ImGui_ImplSDL2_InitForD3D_(SDL_Window * window) { return ::ImGui_ImplSDL2_InitForD3D(window); } 8 | extern "C" bool _1_ImGui_ImplSDL2_InitForMetal_(SDL_Window * window) { return ::ImGui_ImplSDL2_InitForMetal(window); } 9 | extern "C" bool _1_ImGui_ImplSDL2_InitForSDLRenderer_(SDL_Window * window, SDL_Renderer * renderer) { return ::ImGui_ImplSDL2_InitForSDLRenderer(window, renderer); } 10 | extern "C" void _1_ImGui_ImplSDL2_Shutdown_() { ::ImGui_ImplSDL2_Shutdown(); } 11 | extern "C" void _1_ImGui_ImplSDL2_NewFrame_() { ::ImGui_ImplSDL2_NewFrame(); } 12 | extern "C" bool _1_ImGui_ImplSDL2_ProcessEvent_(const SDL_Event * event) { return ::ImGui_ImplSDL2_ProcessEvent(event); } 13 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/EdgeHolder.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "edge-segments.h" 5 | 6 | namespace msdfgen { 7 | 8 | /// Container for a single edge of dynamic type. 9 | class EdgeHolder { 10 | 11 | public: 12 | /// Swaps the edges held by a and b. 13 | static void swap(EdgeHolder &a, EdgeHolder &b); 14 | 15 | EdgeHolder(); 16 | EdgeHolder(EdgeSegment *segment); 17 | EdgeHolder(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE); 18 | EdgeHolder(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE); 19 | EdgeHolder(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE); 20 | EdgeHolder(const EdgeHolder &orig); 21 | #ifdef MSDFGEN_USE_CPP11 22 | EdgeHolder(EdgeHolder &&orig); 23 | #endif 24 | ~EdgeHolder(); 25 | EdgeHolder & operator=(const EdgeHolder &orig); 26 | #ifdef MSDFGEN_USE_CPP11 27 | EdgeHolder & operator=(EdgeHolder &&orig); 28 | #endif 29 | EdgeSegment & operator*(); 30 | const EdgeSegment & operator*() const; 31 | EdgeSegment * operator->(); 32 | const EdgeSegment * operator->() const; 33 | operator EdgeSegment *(); 34 | operator const EdgeSegment *() const; 35 | 36 | private: 37 | EdgeSegment *edgeSegment; 38 | 39 | }; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Geometry/Triangle.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// A simple triangle and its material 10 | class Triangle 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | /// Constructor 16 | Triangle() = default; 17 | Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3) : mV { inV1, inV2, inV3 } { } 18 | Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3, uint32 inMaterialIndex) : Triangle(inV1, inV2, inV3) { mMaterialIndex = inMaterialIndex; } 19 | Triangle(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3) { inV1.StoreFloat3(&mV[0]); inV2.StoreFloat3(&mV[1]); inV3.StoreFloat3(&mV[2]); } 20 | 21 | /// Get center of triangle 22 | Vec3 GetCentroid() const 23 | { 24 | return (Vec3::sLoadFloat3Unsafe(mV[0]) + Vec3::sLoadFloat3Unsafe(mV[1]) + Vec3::sLoadFloat3Unsafe(mV[2])) * (1.0f / 3.0f); 25 | } 26 | 27 | /// Vertices 28 | Float3 mV[3]; 29 | uint32 mMaterialIndex = 0; ///< Follows mV[3] so that we can read mV as 4 vectors 30 | }; 31 | 32 | using TriangleList = Array; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /use_cases/imgui/imgui_impl_opengl3.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | const ImDrawData = @import("imgui.zig").ImDrawData; 5 | 6 | extern fn _1_ImGui_ImplOpenGL3_Init_(glsl_version: [*:0]const u8) bool; 7 | pub const Init = _1_ImGui_ImplOpenGL3_Init_; 8 | 9 | extern fn _1_ImGui_ImplOpenGL3_Shutdown_() void; 10 | pub const Shutdown = _1_ImGui_ImplOpenGL3_Shutdown_; 11 | 12 | extern fn _1_ImGui_ImplOpenGL3_NewFrame_() void; 13 | pub const NewFrame = _1_ImGui_ImplOpenGL3_NewFrame_; 14 | 15 | extern fn _1_ImGui_ImplOpenGL3_RenderDrawData_(draw_data: *ImDrawData) void; 16 | pub const RenderDrawData = _1_ImGui_ImplOpenGL3_RenderDrawData_; 17 | 18 | extern fn _1_ImGui_ImplOpenGL3_CreateFontsTexture_() bool; 19 | pub const CreateFontsTexture = _1_ImGui_ImplOpenGL3_CreateFontsTexture_; 20 | 21 | extern fn _1_ImGui_ImplOpenGL3_DestroyFontsTexture_() void; 22 | pub const DestroyFontsTexture = _1_ImGui_ImplOpenGL3_DestroyFontsTexture_; 23 | 24 | extern fn _1_ImGui_ImplOpenGL3_CreateDeviceObjects_() bool; 25 | pub const CreateDeviceObjects = _1_ImGui_ImplOpenGL3_CreateDeviceObjects_; 26 | 27 | extern fn _1_ImGui_ImplOpenGL3_DestroyDeviceObjects_() void; 28 | pub const DestroyDeviceObjects = _1_ImGui_ImplOpenGL3_DestroyDeviceObjects_; 29 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/JoltViewer.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #ifdef JPH_DEBUG_RENDERER 9 | #include 10 | #else 11 | // Hack to still compile DebugRenderer inside the test framework when Jolt is compiled without 12 | #define JPH_DEBUG_RENDERER 13 | #include 14 | #undef JPH_DEBUG_RENDERER 15 | #endif 16 | 17 | using namespace std; 18 | 19 | // Application that views recordings produced by DebugRendererRecorder 20 | class JoltViewer : public Application 21 | { 22 | public: 23 | // Constructor / destructor 24 | JoltViewer(); 25 | 26 | // Render the frame 27 | virtual bool RenderFrame(float inDeltaTime) override; 28 | 29 | private: 30 | enum class EPlaybackMode 31 | { 32 | Rewind, 33 | StepBack, 34 | Stop, 35 | StepForward, 36 | Play 37 | }; 38 | 39 | DebugRendererPlayback mRendererPlayback { *mDebugRenderer }; 40 | 41 | EPlaybackMode mPlaybackMode = EPlaybackMode::Play; // Current playback state. Indicates if we're playing or scrubbing back/forward. 42 | uint mCurrentFrame = 0; 43 | }; 44 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/contour-combiners.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Shape.h" 5 | #include "edge-selectors.h" 6 | 7 | namespace msdfgen { 8 | 9 | /// Simply selects the nearest contour. 10 | template 11 | class SimpleContourCombiner { 12 | 13 | public: 14 | typedef EdgeSelector EdgeSelectorType; 15 | typedef typename EdgeSelector::DistanceType DistanceType; 16 | 17 | explicit SimpleContourCombiner(const Shape &shape); 18 | void reset(const Point2 &p); 19 | EdgeSelector & edgeSelector(int i); 20 | DistanceType distance() const; 21 | 22 | private: 23 | EdgeSelector shapeEdgeSelector; 24 | 25 | }; 26 | 27 | /// Selects the nearest contour that actually forms a border between filled and unfilled area. 28 | template 29 | class OverlappingContourCombiner { 30 | 31 | public: 32 | typedef EdgeSelector EdgeSelectorType; 33 | typedef typename EdgeSelector::DistanceType DistanceType; 34 | 35 | explicit OverlappingContourCombiner(const Shape &shape); 36 | void reset(const Point2 &p); 37 | EdgeSelector & edgeSelector(int i); 38 | DistanceType distance() const; 39 | 40 | private: 41 | Point2 p; 42 | std::vector windings; 43 | std::vector edgeSelectors; 44 | 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /use_cases/msdfgen/Contour.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const cpp = @import("cpp"); 3 | 4 | const EdgeHolder = @import("EdgeHolder.zig").EdgeHolder; 5 | 6 | pub const Contour = extern struct { 7 | edges: cpp.Vector(EdgeHolder), 8 | 9 | extern fn _ZN7msdfgen7Contour7addEdgeERKNS_10EdgeHolderE(self: *Contour, edge: *const EdgeHolder) void; 10 | pub const addEdge = _ZN7msdfgen7Contour7addEdgeERKNS_10EdgeHolderE; 11 | 12 | extern fn _ZN7msdfgen7Contour7addEdgeEv(self: *Contour) *EdgeHolder; 13 | pub const addEdge__Overload2 = _ZN7msdfgen7Contour7addEdgeEv; 14 | 15 | extern fn _ZNK7msdfgen7Contour5boundERdS1_S1_S1_(self: *const Contour, l: *f64, b: *f64, r: *f64, t: *f64) void; 16 | pub const bound = _ZNK7msdfgen7Contour5boundERdS1_S1_S1_; 17 | 18 | extern fn _ZNK7msdfgen7Contour11boundMitersERdS1_S1_S1_ddi(self: *const Contour, l: *f64, b: *f64, r: *f64, t: *f64, border: f64, miterLimit: f64, polarity: c_int) void; 19 | pub const boundMiters = _ZNK7msdfgen7Contour11boundMitersERdS1_S1_S1_ddi; 20 | 21 | extern fn _ZNK7msdfgen7Contour7windingEv(self: *const Contour) c_int; 22 | pub const winding = _ZNK7msdfgen7Contour7windingEv; 23 | 24 | extern fn _ZN7msdfgen7Contour7reverseEv(self: *Contour) void; 25 | pub const reverse = _ZN7msdfgen7Contour7reverseEv; 26 | }; 27 | -------------------------------------------------------------------------------- /test_cases/c016_for.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | extern fn _1_foo_(__arg0: c_int) void; 6 | pub const foo = _1_foo_; 7 | 8 | pub fn for1() void { 9 | { 10 | var i: c_int = 0; 11 | while (i < 5) : (i += 1) foo(i); 12 | } 13 | } 14 | pub fn for2() void { 15 | { 16 | var i: c_int = 0; 17 | while (i < 5) : (i += 1) { 18 | foo(i); 19 | } 20 | } 21 | } 22 | pub fn for3() void { 23 | { 24 | var i: c_int = 0; 25 | while (i < 5) : (i += 1) { 26 | foo(i); 27 | } 28 | } 29 | { 30 | var i: c_int = 5; 31 | while (i < 10) : (i += 1) { 32 | foo(i); 33 | } 34 | } 35 | } 36 | pub fn for4() void { 37 | { 38 | var i: c_int = 0; 39 | var j: c_int = 8; 40 | while (i < 5) : ({ 41 | i += 1; 42 | j -= 1; 43 | }) { 44 | foo(i); 45 | } 46 | } 47 | } 48 | pub fn for5() void { 49 | var i: c_int = 0; 50 | var j: c_int = 0; 51 | while (i < 5) : (i += 1) { 52 | while (j < 5) : (j += 2) foo(i * j); 53 | } 54 | { 55 | i = 0; 56 | while (i < 5) : (i += 1) foo(i); 57 | } 58 | j += 2; 59 | i += j; 60 | } 61 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Body/BodyActivationListener.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class BodyID; 10 | 11 | /// A listener class that receives events when a body activates or deactivates. 12 | /// It can be registered with the BodyManager (or PhysicsSystem). 13 | class BodyActivationListener 14 | { 15 | public: 16 | /// Ensure virtual destructor 17 | virtual ~BodyActivationListener() = default; 18 | 19 | /// Called whenever a body activates, note this can be called from any thread so make sure your code is thread safe. 20 | /// At the time of the callback the body inBodyID will be locked and no bodies can be written/activated/deactivated from the callback. 21 | virtual void OnBodyActivated(const BodyID &inBodyID, uint64 inBodyUserData) = 0; 22 | 23 | /// Called whenever a body deactivates, note this can be called from any thread so make sure your code is thread safe. 24 | /// At the time of the callback the body inBodyID will be locked and no bodies can be written/activated/deactivated from the callback. 25 | virtual void OnBodyDeactivated(const BodyID &inBodyID, uint64 inBodyUserData) = 0; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Vehicle/VehicleAntiRollBar.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | /// An anti rollbar is a stiff spring that connects two wheels to reduce the amount of roll the vehicle makes in sharp corners 14 | /// See: https://en.wikipedia.org/wiki/Anti-roll_bar 15 | class VehicleAntiRollBar 16 | { 17 | public: 18 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(VehicleAntiRollBar) 19 | 20 | /// Saves the contents in binary form to inStream. 21 | void SaveBinaryState(StreamOut &inStream) const; 22 | 23 | /// Restores the contents in binary form to inStream. 24 | void RestoreBinaryState(StreamIn &inStream); 25 | 26 | int mLeftWheel = 0; ///< Index (in mWheels) that represents the left wheel of this anti-rollbar 27 | int mRightWheel = 1; ///< Index (in mWheels) that represents the right wheel of this anti-rollbar 28 | float mStiffness = 1000.0f; ///< Stiffness (spring constant in N/m) of anti rollbar, can be 0 to disable the anti-rollbar 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Body/BodyPair.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds a body pair 13 | struct alignas(uint64) BodyPair 14 | { 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | /// Constructor 18 | BodyPair() = default; 19 | BodyPair(BodyID inA, BodyID inB) : mBodyA(inA), mBodyB(inB) { } 20 | 21 | /// Equals operator 22 | bool operator == (const BodyPair &inRHS) const { return *reinterpret_cast(this) == *reinterpret_cast(&inRHS); } 23 | 24 | /// Smaller than operator, used for consistently ordering body pairs 25 | bool operator < (const BodyPair &inRHS) const { return *reinterpret_cast(this) < *reinterpret_cast(&inRHS); } 26 | 27 | /// Get the hash value of this object 28 | uint64 GetHash() const { return Hash64(*reinterpret_cast(this)); } 29 | 30 | BodyID mBodyA; 31 | BodyID mBodyB; 32 | }; 33 | 34 | static_assert(sizeof(BodyPair) == sizeof(uint64), "Mismatch in class size"); 35 | 36 | JPH_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/render-sdf.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Vector2.h" 5 | #include "BitmapRef.hpp" 6 | 7 | namespace msdfgen { 8 | 9 | /// Reconstructs the shape's appearance into output from the distance field sdf. 10 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 11 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 12 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 13 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 14 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 15 | void renderSDF(const BitmapRef &output, const BitmapConstRef &sdf, double pxRange = 0, float midValue = .5f); 16 | 17 | /// Snaps the values of the floating-point bitmaps into one of the 256 values representable in a standard 8-bit bitmap. 18 | void simulate8bit(const BitmapRef &bitmap); 19 | void simulate8bit(const BitmapRef &bitmap); 20 | void simulate8bit(const BitmapRef &bitmap); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/FPFlushDenormals.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | #if defined(JPH_USE_SSE) 12 | 13 | /// Helper class that needs to be put on the stack to enable flushing denormals to zero 14 | /// This can make floating point operations much faster when working with very small numbers 15 | class FPFlushDenormals : public FPControlWord<_MM_FLUSH_ZERO_ON, _MM_FLUSH_ZERO_MASK> { }; 16 | 17 | #elif defined(JPH_CPU_ARM) && defined(JPH_COMPILER_MSVC) 18 | 19 | class FPFlushDenormals : public FPControlWord<_DN_FLUSH, _MCW_DN> { }; 20 | 21 | #elif defined(JPH_CPU_ARM) 22 | 23 | /// Flush denormals to zero bit 24 | static constexpr uint64 FP_FZ = 1 << 24; 25 | 26 | /// Helper class that needs to be put on the stack to enable flushing denormals to zero 27 | /// This can make floating point operations much faster when working with very small numbers 28 | class FPFlushDenormals : public FPControlWord { }; 29 | 30 | #elif defined(JPH_CPU_WASM) 31 | 32 | // Not supported 33 | class FPFlushDenormals { }; 34 | 35 | #else 36 | 37 | #error Unsupported CPU architecture 38 | 39 | #endif 40 | 41 | JPH_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/Projection.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Vector2.h" 5 | 6 | namespace msdfgen { 7 | 8 | /// A transformation from shape coordinates to pixel coordinates. 9 | class Projection { 10 | 11 | public: 12 | Projection(); 13 | Projection(const Vector2 &scale, const Vector2 &translate); 14 | /// Converts the shape coordinate to pixel coordinate. 15 | Point2 project(const Point2 &coord) const; 16 | /// Converts the pixel coordinate to shape coordinate. 17 | Point2 unproject(const Point2 &coord) const; 18 | /// Converts the vector to pixel coordinate space. 19 | Vector2 projectVector(const Vector2 &vector) const; 20 | /// Converts the vector from pixel coordinate space. 21 | Vector2 unprojectVector(const Vector2 &vector) const; 22 | /// Converts the X-coordinate from shape to pixel coordinate space. 23 | double projectX(double x) const; 24 | /// Converts the Y-coordinate from shape to pixel coordinate space. 25 | double projectY(double y) const; 26 | /// Converts the X-coordinate from pixel to shape coordinate space. 27 | double unprojectX(double x) const; 28 | /// Converts the Y-coordinate from pixel to shape coordinate space. 29 | double unprojectY(double y) const; 30 | 31 | private: 32 | Vector2 scale; 33 | Vector2 translate; 34 | 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/ext/import-svg.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include "../core/Shape.h" 6 | 7 | #ifndef MSDFGEN_DISABLE_SVG 8 | 9 | #ifndef MSDFGEN_EXT_PUBLIC 10 | #define MSDFGEN_EXT_PUBLIC // for DLL import/export 11 | #endif 12 | 13 | namespace msdfgen { 14 | 15 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_FAILURE; 16 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_SUCCESS_FLAG; 17 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_PARTIAL_FAILURE_FLAG; 18 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_INCOMPLETE_FLAG; 19 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_UNSUPPORTED_FEATURE_FLAG; 20 | extern MSDFGEN_EXT_PUBLIC const int SVG_IMPORT_TRANSFORMATION_IGNORED_FLAG; 21 | 22 | /// Builds a shape from an SVG path string 23 | bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSnapRange = 0); 24 | 25 | /// Reads a single element found in the specified SVG file and converts it to output Shape 26 | bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL); 27 | 28 | /// New version - if Skia is available, reads the entire geometry of the SVG file into the output Shape, otherwise may only read one path, returns SVG import flags 29 | int loadSvgShape(Shape &output, Shape::Bounds &viewBox, const char *filename); 30 | 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/Bitmap.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "BitmapRef.hpp" 5 | 6 | namespace msdfgen { 7 | 8 | /// A 2D image bitmap with N channels of type T. Pixel memory is managed by the class. 9 | template 10 | class Bitmap { 11 | 12 | public: 13 | Bitmap(); 14 | Bitmap(int width, int height); 15 | Bitmap(const BitmapConstRef &orig); 16 | Bitmap(const Bitmap &orig); 17 | #ifdef MSDFGEN_USE_CPP11 18 | Bitmap(Bitmap &&orig); 19 | #endif 20 | ~Bitmap(); 21 | Bitmap & operator=(const BitmapConstRef &orig); 22 | Bitmap & operator=(const Bitmap &orig); 23 | #ifdef MSDFGEN_USE_CPP11 24 | Bitmap & operator=(Bitmap &&orig); 25 | #endif 26 | /// Bitmap width in pixels. 27 | int width() const; 28 | /// Bitmap height in pixels. 29 | int height() const; 30 | T * operator()(int x, int y); 31 | const T * operator()(int x, int y) const; 32 | #ifdef MSDFGEN_USE_CPP11 33 | explicit operator T *(); 34 | explicit operator const T *() const; 35 | #else 36 | operator T *(); 37 | operator const T *() const; 38 | #endif 39 | operator BitmapRef(); 40 | operator BitmapConstRef() const; 41 | 42 | private: 43 | T *pixels; 44 | int w, h; 45 | 46 | }; 47 | 48 | } 49 | 50 | #include "Bitmap.hpp" 51 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Double3.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Class that holds 3 doubles. Used as a storage class. Convert to DVec3 for calculations. 12 | class [[nodiscard]] Double3 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | Double3() = default; ///< Intentionally not initialized for performance reasons 18 | Double3(const Double3 &inRHS) = default; 19 | Double3(double inX, double inY, double inZ) : x(inX), y(inY), z(inZ) { } 20 | 21 | double operator [] (int inCoordinate) const 22 | { 23 | JPH_ASSERT(inCoordinate < 3); 24 | return *(&x + inCoordinate); 25 | } 26 | 27 | bool operator == (const Double3 &inRHS) const 28 | { 29 | return x == inRHS.x && y == inRHS.y && z == inRHS.z; 30 | } 31 | 32 | bool operator != (const Double3 &inRHS) const 33 | { 34 | return x != inRHS.x || y != inRHS.y || z != inRHS.z; 35 | } 36 | 37 | double x; 38 | double y; 39 | double z; 40 | }; 41 | 42 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 43 | 44 | JPH_NAMESPACE_END 45 | 46 | // Create a std::hash for Double3 47 | JPH_MAKE_HASHABLE(JPH::Double3, t.x, t.y, t.z) 48 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/PhysicsStepListener.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class PhysicsSystem; 10 | 11 | /// A listener class that receives a callback before every physics simulation step 12 | class PhysicsStepListener 13 | { 14 | public: 15 | /// Ensure virtual destructor 16 | virtual ~PhysicsStepListener() = default; 17 | 18 | /// Called before every simulation step (received inCollisionSteps times for every PhysicsSystem::Update(...) call) 19 | /// This is called while all body and constraint mutexes are locked. You can read/write bodies and constraints but not add/remove them. 20 | /// Multiple listeners can be executed in parallel and it is the responsibility of the listener to avoid race conditions. 21 | /// The best way to do this is to have each step listener operate on a subset of the bodies and constraints 22 | /// and making sure that these bodies and constraints are not touched by any other step listener. 23 | /// Note that this function is not called if there aren't any active bodies or when the physics system is updated with 0 delta time. 24 | virtual void OnStep(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0; 25 | }; 26 | 27 | JPH_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Float3.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations. 12 | class [[nodiscard]] Float3 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | Float3() = default; ///< Intentionally not initialized for performance reasons 18 | Float3(const Float3 &inRHS) = default; 19 | Float3(float inX, float inY, float inZ) : x(inX), y(inY), z(inZ) { } 20 | 21 | float operator [] (int inCoordinate) const 22 | { 23 | JPH_ASSERT(inCoordinate < 3); 24 | return *(&x + inCoordinate); 25 | } 26 | 27 | bool operator == (const Float3 &inRHS) const 28 | { 29 | return x == inRHS.x && y == inRHS.y && z == inRHS.z; 30 | } 31 | 32 | bool operator != (const Float3 &inRHS) const 33 | { 34 | return x != inRHS.x || y != inRHS.y || z != inRHS.z; 35 | } 36 | 37 | float x; 38 | float y; 39 | float z; 40 | }; 41 | 42 | using VertexList = Array; 43 | 44 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 45 | 46 | JPH_NAMESPACE_END 47 | 48 | // Create a std::hash for Float3 49 | JPH_MAKE_HASHABLE(JPH::Float3, t.x, t.y, t.z) 50 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/ShapeDistanceFinder.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include "Vector2.h" 6 | #include "edge-selectors.h" 7 | #include "contour-combiners.h" 8 | 9 | namespace msdfgen { 10 | 11 | /// Finds the distance between a point and a Shape. ContourCombiner dictates the distance metric and its data type. 12 | template 13 | class ShapeDistanceFinder { 14 | 15 | public: 16 | typedef typename ContourCombiner::DistanceType DistanceType; 17 | 18 | // Passed shape object must persist until the distance finder is destroyed! 19 | explicit ShapeDistanceFinder(const Shape &shape); 20 | /// Finds the distance from origin. Not thread-safe! Is fastest when subsequent queries are close together. 21 | DistanceType distance(const Point2 &origin); 22 | 23 | /// Finds the distance between shape and origin. Does not allocate result cache used to optimize performance of multiple queries. 24 | static DistanceType oneShotDistance(const Shape &shape, const Point2 &origin); 25 | 26 | private: 27 | const Shape &shape; 28 | ContourCombiner contourCombiner; 29 | std::vector shapeEdgeCache; 30 | 31 | }; 32 | 33 | typedef ShapeDistanceFinder > SimpleTrueShapeDistanceFinder; 34 | 35 | } 36 | 37 | #include "ShapeDistanceFinder.hpp" 38 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Geometry/MortonCode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | class MortonCode 12 | { 13 | public: 14 | /// First converts a floating point value in the range [0, 1] to a 10 bit fixed point integer. 15 | /// Then expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit. 16 | static uint32 sExpandBits(float inV) 17 | { 18 | JPH_ASSERT(inV >= 0.0f && inV <= 1.0f); 19 | uint32 v = uint32(inV * 1023.0f + 0.5f); 20 | JPH_ASSERT(v < 1024); 21 | v = (v * 0x00010001u) & 0xFF0000FFu; 22 | v = (v * 0x00000101u) & 0x0F00F00Fu; 23 | v = (v * 0x00000011u) & 0xC30C30C3u; 24 | v = (v * 0x00000005u) & 0x49249249u; 25 | return v; 26 | } 27 | 28 | /// Calculate the morton code for inVector, given that all vectors lie in inVectorBounds 29 | static uint32 sGetMortonCode(Vec3Arg inVector, const AABox &inVectorBounds) 30 | { 31 | // Convert to 10 bit fixed point 32 | Vec3 scaled = (inVector - inVectorBounds.mMin) / inVectorBounds.GetSize(); 33 | uint x = sExpandBits(scaled.GetX()); 34 | uint y = sExpandBits(scaled.GetY()); 35 | uint z = sExpandBits(scaled.GetZ()); 36 | return (x << 2) + (y << 1) + z; 37 | } 38 | }; 39 | 40 | JPH_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/BitmapRef.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace msdfgen { 7 | 8 | typedef unsigned char byte; 9 | 10 | /// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. 11 | template 12 | struct BitmapRef { 13 | 14 | T *pixels; 15 | int width, height; 16 | 17 | inline BitmapRef() : pixels(NULL), width(0), height(0) { } 18 | inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { } 19 | 20 | inline T * operator()(int x, int y) const { 21 | return pixels+N*(width*y+x); 22 | } 23 | 24 | }; 25 | 26 | /// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. 27 | template 28 | struct BitmapConstRef { 29 | 30 | const T *pixels; 31 | int width, height; 32 | 33 | inline BitmapConstRef() : pixels(NULL), width(0), height(0) { } 34 | inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { } 35 | inline BitmapConstRef(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { } 36 | 37 | inline const T * operator()(int x, int y) const { 38 | return pixels+N*(width*y+x); 39 | } 40 | 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | fail-fast: false 9 | matrix: 10 | runs-on: [ubuntu-latest, macos-latest, windows-latest] 11 | runs-on: ${{ matrix.runs-on }} 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: goto-bus-stop/setup-zig@v2 15 | - name: build 16 | run: zig build -freference-trace 17 | - name: test release 18 | run: zig build test -Doptimize=ReleaseFast -freference-trace 19 | 20 | - name: test debug 21 | run: zig build test -freference-trace 22 | 23 | zig-msvc: 24 | runs-on: windows-latest 25 | strategy: 26 | fail-fast: false 27 | steps: 28 | - uses: actions/checkout@v3 29 | - uses: goto-bus-stop/setup-zig@v2 30 | - name: build 31 | run: zig build -freference-trace -Dtarget=native-windows-msvc 32 | 33 | # - name: Run transpiler 34 | # run: | 35 | # ./zig-out/bin/c2z.exe $PWD/use_cases/common_cases/include/c013_cpp_vector.h 36 | # Get-Content $PWD/x86_64/windows/msvc/c013_cpp_vector.zig 37 | 38 | - name: test release 39 | run: zig build test -Doptimize=ReleaseFast -freference-trace -Dtarget=native-windows-msvc 40 | 41 | - name: test debug 42 | run: zig build test -freference-trace -Dtarget=native-windows-msvc 43 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_opengles.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 1.X API headers. 26 | */ 27 | #include "SDL_config.h" 28 | 29 | #ifdef __IPHONEOS__ 30 | #include 31 | #include 32 | #else 33 | #include 34 | #include 35 | #endif 36 | 37 | #ifndef APIENTRY 38 | #define APIENTRY 39 | #endif 40 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ObjectStream/GetPrimitiveTypeOfType.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Helper functions to get the underlying RTTI type of a type (so e.g. Array will return sometype) 12 | template 13 | const RTTI *GetPrimitiveTypeOfType(T *) 14 | { 15 | return GetRTTIOfType((T *)nullptr); 16 | } 17 | 18 | template 19 | const RTTI *GetPrimitiveTypeOfType(T **) 20 | { 21 | return GetRTTIOfType((T *)nullptr); 22 | } 23 | 24 | template 25 | const RTTI *GetPrimitiveTypeOfType(Ref *) 26 | { 27 | return GetRTTIOfType((T *)nullptr); 28 | } 29 | 30 | template 31 | const RTTI *GetPrimitiveTypeOfType(RefConst *) 32 | { 33 | return GetRTTIOfType((T *)nullptr); 34 | } 35 | 36 | template 37 | const RTTI *GetPrimitiveTypeOfType(Array *) 38 | { 39 | return GetPrimitiveTypeOfType((T *)nullptr); 40 | } 41 | 42 | template 43 | const RTTI *GetPrimitiveTypeOfType(StaticArray *) 44 | { 45 | return GetPrimitiveTypeOfType((T *)nullptr); 46 | } 47 | 48 | template 49 | const RTTI *GetPrimitiveTypeOfType(T (*)[N]) 50 | { 51 | return GetPrimitiveTypeOfType((T *)nullptr); 52 | } 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/PhysicsMaterialSimple.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Sample implementation of PhysicsMaterial that just holds the needed properties directly 12 | class PhysicsMaterialSimple : public PhysicsMaterial 13 | { 14 | public: 15 | JPH_DECLARE_SERIALIZABLE_VIRTUAL(PhysicsMaterialSimple) 16 | 17 | /// Constructor 18 | PhysicsMaterialSimple() = default; 19 | PhysicsMaterialSimple(const string_view &inName, ColorArg inColor) : mDebugName(inName), mDebugColor(inColor) { } 20 | 21 | // Properties 22 | virtual const char * GetDebugName() const override { return mDebugName.c_str(); } 23 | virtual Color GetDebugColor() const override { return mDebugColor; } 24 | 25 | // See: PhysicsMaterial::SaveBinaryState 26 | virtual void SaveBinaryState(StreamOut &inStream) const override; 27 | 28 | protected: 29 | // See: PhysicsMaterial::RestoreBinaryState 30 | virtual void RestoreBinaryState(StreamIn &inStream) override; 31 | 32 | private: 33 | String mDebugName; ///< Name of the material, used for debugging purposes 34 | Color mDebugColor = Color::sGrey; ///< Color of the material, used to render the shapes 35 | }; 36 | 37 | JPH_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /use_cases/dotherside/include/DOtherSide/DosQQuickImageProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2020 Filippo Cucchetto. 3 | Contact: https://github.com/filcuc/dotherside 4 | 5 | This file is part of the DOtherSide library. 6 | 7 | The DOtherSide library is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version. 10 | 11 | The DOtherSide library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with the DOtherSide library. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | // std 23 | #include 24 | 25 | // Qt 26 | #include 27 | #include 28 | 29 | #include "DOtherSideTypes.h" 30 | 31 | class DosImageProvider : public QQuickImageProvider 32 | { 33 | public: 34 | DosImageProvider(RequestPixmapCallback callback); 35 | 36 | QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; 37 | 38 | private: 39 | RequestPixmapCallback m_pixmap_callback; 40 | }; 41 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/edge-coloring.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Shape.h" 5 | 6 | #define MSDFGEN_EDGE_LENGTH_PRECISION 4 7 | 8 | namespace msdfgen { 9 | 10 | /** Assigns colors to edges of the shape in accordance to the multi-channel distance field technique. 11 | * May split some edges if necessary. 12 | * angleThreshold specifies the maximum angle (in radians) to be considered a corner, for example 3 (~172 degrees). 13 | * Values below 1/2 PI will be treated as the external angle. 14 | */ 15 | void edgeColoringSimple(Shape &shape, double angleThreshold, unsigned long long seed = 0); 16 | 17 | /** The alternative "ink trap" coloring strategy is designed for better results with typefaces 18 | * that use ink traps as a design feature. It guarantees that even if all edges that are shorter than 19 | * both their neighboring edges are removed, the coloring remains consistent with the established rules. 20 | */ 21 | void edgeColoringInkTrap(Shape &shape, double angleThreshold, unsigned long long seed = 0); 22 | 23 | /** The alternative coloring by distance tries to use different colors for edges that are close together. 24 | * This should theoretically be the best strategy on average. However, since it needs to compute the distance 25 | * between all pairs of edges, and perform a graph optimization task, it is much slower than the rest. 26 | */ 27 | void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long long seed = 0); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/GroupFilter.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | class CollisionGroup; 13 | class StreamIn; 14 | class StreamOut; 15 | 16 | /// Abstract class that checks if two CollisionGroups collide 17 | class GroupFilter : public SerializableObject, public RefTarget 18 | { 19 | public: 20 | JPH_DECLARE_SERIALIZABLE_ABSTRACT(GroupFilter) 21 | 22 | /// Virtual destructor 23 | virtual ~GroupFilter() override = default; 24 | 25 | /// Check if two groups collide 26 | virtual bool CanCollide(const CollisionGroup &inGroup1, const CollisionGroup &inGroup2) const = 0; 27 | 28 | /// Saves the contents of the group filter in binary form to inStream. 29 | virtual void SaveBinaryState(StreamOut &inStream) const; 30 | 31 | using GroupFilterResult = Result>; 32 | 33 | /// Creates a GroupFilter of the correct type and restores its contents from the binary stream inStream. 34 | static GroupFilterResult sRestoreFromBinaryState(StreamIn &inStream); 35 | 36 | protected: 37 | /// This function should not be called directly, it is used by sRestoreFromBinaryState. 38 | virtual void RestoreBinaryState(StreamIn &inStream); 39 | }; 40 | 41 | JPH_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /use_cases/box2d/include/b2_types.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2020 Erin Catto 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #ifndef B2_TYPES_H 24 | #define B2_TYPES_H 25 | 26 | typedef signed char int8; 27 | typedef signed short int16; 28 | typedef signed int int32; 29 | typedef unsigned char uint8; 30 | typedef unsigned short uint16; 31 | typedef unsigned int uint32; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Body/BodyAccess.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #ifdef JPH_ENABLE_ASSERTS 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | class BodyAccess 12 | { 13 | public: 14 | /// Access rules, used to detect race conditions during simulation 15 | enum class EAccess : uint8 16 | { 17 | None = 0, 18 | Read = 1, 19 | ReadWrite = 3, 20 | }; 21 | 22 | /// Grant a scope specific access rights on the current thread 23 | class Grant 24 | { 25 | public: 26 | inline Grant(EAccess inVelocity, EAccess inPosition) 27 | { 28 | JPH_ASSERT(sVelocityAccess == EAccess::ReadWrite); 29 | JPH_ASSERT(sPositionAccess == EAccess::ReadWrite); 30 | 31 | sVelocityAccess = inVelocity; 32 | sPositionAccess = inPosition; 33 | } 34 | 35 | inline ~Grant() 36 | { 37 | sVelocityAccess = EAccess::ReadWrite; 38 | sPositionAccess = EAccess::ReadWrite; 39 | } 40 | }; 41 | 42 | /// Check if we have permission 43 | static bool sCheckRights(EAccess inRights, EAccess inDesiredRights) 44 | { 45 | return (uint8(inRights) & uint8(inDesiredRights)) == uint8(inDesiredRights); 46 | } 47 | 48 | // Various permissions that can be granted 49 | static thread_local EAccess sVelocityAccess; 50 | static thread_local EAccess sPositionAccess; 51 | }; 52 | 53 | JPH_NAMESPACE_END 54 | 55 | #endif // JPH_ENABLE_ASSERTS 56 | -------------------------------------------------------------------------------- /test_cases/c021_operator_overload_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "c021_operator_overload.h" 3 | 4 | extern "C" void _1_ImVec2_init_(::ImVec2 *self) { *self = ::ImVec2(); } 5 | extern "C" void _2_ImVec2_init_(::ImVec2 *self, float x, float y) { *self = ::ImVec2(x, y); } 6 | extern "C" float & _1_ImVec2_getPtr_(::ImVec2* self, int idx) { return (*self)[idx]; } 7 | extern "C" float _1_ImVec2_get_(const ::ImVec2 *self, int idx) { return (*self)[idx]; } 8 | extern "C" ImVec2 _1_ImVec2_mul_(const ::ImVec2 *self, const float rhs) { return *self * rhs; } 9 | extern "C" ImVec2 & _1_ImVec2_mulInto_(::ImVec2* self, const float rhs) { return *self *= rhs; } 10 | extern "C" ImVec2 _1_ImVec2_div_(const ::ImVec2 *self, const float rhs) { return *self / rhs; } 11 | extern "C" ImVec2 & _1_ImVec2_divInto_(::ImVec2* self, const float rhs) { return *self /= rhs; } 12 | extern "C" ImVec2 _1_ImVec2_add_(const ::ImVec2 *self, const ImVec2 & rhs) { return *self + rhs; } 13 | extern "C" ImVec2 & _1_ImVec2_addInto_(::ImVec2* self, const ImVec2 & rhs) { return *self += rhs; } 14 | extern "C" ImVec2 _1_ImVec2_sub_(const ::ImVec2 *self, const ImVec2 & rhs) { return *self - rhs; } 15 | extern "C" ImVec2 & _1_ImVec2_subInto_(::ImVec2* self, const ImVec2 & rhs) { return *self -= rhs; } 16 | extern "C" ImVec4 _1_add_(const ImVec4 & lhs, const ImVec4 & rhs) { return lhs + rhs; } 17 | extern "C" ImVec4 _1_sub_(const ImVec4 & lhs, const ImVec4 & rhs) { return lhs - rhs; } 18 | extern "C" ImVec4 _1_mul_(const ImVec4 & lhs, const ImVec4 & rhs) { return lhs * rhs; } 19 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/StateRecorder.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Class that records the state of a physics system. Can be used to check if the simulation is deterministic by putting the recorder in validation mode. 13 | /// Can be used to restore the state to an earlier point in time. 14 | class StateRecorder : public StreamIn, public StreamOut 15 | { 16 | public: 17 | /// Constructor 18 | StateRecorder() = default; 19 | StateRecorder(const StateRecorder &inRHS) : mIsValidating(inRHS.mIsValidating) { } 20 | 21 | /// Sets the stream in validation mode. In this case the physics system ensures that before it calls ReadBytes that it will 22 | /// ensure that those bytes contain the current state. This makes it possible to step and save the state, restore to the previous 23 | /// step and step again and when the recorded state is not the same it can restore the expected state and any byte that changes 24 | /// due to a ReadBytes function can be caught to find out which part of the simulation is not deterministic 25 | void SetValidating(bool inValidating) { mIsValidating = inValidating; } 26 | bool IsValidating() const { return mIsValidating; } 27 | 28 | private: 29 | bool mIsValidating = false; 30 | }; 31 | 32 | JPH_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_dx9.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX9 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 8 | 9 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 10 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 11 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 12 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 13 | 14 | #pragma once 15 | #include "imgui.h" // IMGUI_IMPL_API 16 | 17 | struct IDirect3DDevice9; 18 | 19 | IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device); 20 | IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown(); 21 | IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame(); 22 | IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data); 23 | 24 | // Use if you want to reset your rendering device without losing Dear ImGui state. 25 | IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects(); 26 | IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects(); 27 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_dx10.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX10 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 8 | 9 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 10 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 11 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 12 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 13 | 14 | #pragma once 15 | #include "imgui.h" // IMGUI_IMPL_API 16 | 17 | struct ID3D10Device; 18 | 19 | IMGUI_IMPL_API bool ImGui_ImplDX10_Init(ID3D10Device* device); 20 | IMGUI_IMPL_API void ImGui_ImplDX10_Shutdown(); 21 | IMGUI_IMPL_API void ImGui_ImplDX10_NewFrame(); 22 | IMGUI_IMPL_API void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data); 23 | 24 | // Use if you want to reset your rendering device without losing Dear ImGui state. 25 | IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects(); 26 | IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects(); 27 | -------------------------------------------------------------------------------- /use_cases/imgui/imgui_impl_sdl2.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | extern fn _1_ImGui_ImplSDL2_Init_(window: *SDL_Window, renderer: [*c]SDL_Renderer, sdl_gl_context: ?*anyopaque) bool; 6 | pub const Init = _1_ImGui_ImplSDL2_Init_; 7 | 8 | extern fn _1_ImGui_ImplSDL2_InitForOpenGL_(window: *SDL_Window, sdl_gl_context: ?*anyopaque) bool; 9 | pub const InitForOpenGL = _1_ImGui_ImplSDL2_InitForOpenGL_; 10 | 11 | extern fn _1_ImGui_ImplSDL2_InitForVulkan_(window: *SDL_Window) bool; 12 | pub const InitForVulkan = _1_ImGui_ImplSDL2_InitForVulkan_; 13 | 14 | extern fn _1_ImGui_ImplSDL2_InitForD3D_(window: *SDL_Window) bool; 15 | pub const InitForD3D = _1_ImGui_ImplSDL2_InitForD3D_; 16 | 17 | extern fn _1_ImGui_ImplSDL2_InitForMetal_(window: *SDL_Window) bool; 18 | pub const InitForMetal = _1_ImGui_ImplSDL2_InitForMetal_; 19 | 20 | extern fn _1_ImGui_ImplSDL2_InitForSDLRenderer_(window: [*c]SDL_Window, renderer: [*c]SDL_Renderer) bool; 21 | pub const InitForSDLRenderer = _1_ImGui_ImplSDL2_InitForSDLRenderer_; 22 | 23 | extern fn _1_ImGui_ImplSDL2_Shutdown_() void; 24 | pub const Shutdown = _1_ImGui_ImplSDL2_Shutdown_; 25 | 26 | extern fn _1_ImGui_ImplSDL2_NewFrame_() void; 27 | pub const NewFrame = _1_ImGui_ImplSDL2_NewFrame_; 28 | 29 | extern fn _1_ImGui_ImplSDL2_ProcessEvent_(event: [*c]const SDL_Event) bool; 30 | pub const ProcessEvent = _1_ImGui_ImplSDL2_ProcessEvent_; 31 | 32 | // opaques 33 | 34 | const SDL_Window = anyopaque; 35 | const SDL_Renderer = anyopaque; 36 | const SDL_Event = anyopaque; 37 | -------------------------------------------------------------------------------- /use_cases/msdfgen/SignedDistance.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | /// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment. 4 | pub const SignedDistance = extern struct { 5 | distance: f64, 6 | dot: f64, 7 | 8 | extern fn _ZN7msdfgen14SignedDistanceC1Ev(self: *SignedDistance) void; 9 | pub inline fn init() SignedDistance { 10 | var self: SignedDistance = undefined; 11 | _ZN7msdfgen14SignedDistanceC1Ev(&self); 12 | return self; 13 | } 14 | 15 | extern fn _ZN7msdfgen14SignedDistanceC1Edd(self: *SignedDistance, dist: f64, d: f64) void; 16 | pub inline fn init1(dist: f64, d: f64) SignedDistance { 17 | var self: SignedDistance = undefined; 18 | _ZN7msdfgen14SignedDistanceC1Edd(&self, dist, d); 19 | return self; 20 | } 21 | 22 | extern fn _ZN7msdfgenltENS_14SignedDistanceES0_(a: SignedDistance, b: SignedDistance) bool; 23 | pub const lessThan = _ZN7msdfgenltENS_14SignedDistanceES0_; 24 | 25 | extern fn _ZN7msdfgengtENS_14SignedDistanceES0_(a: SignedDistance, b: SignedDistance) bool; 26 | pub const greaterThan = _ZN7msdfgengtENS_14SignedDistanceES0_; 27 | 28 | extern fn _ZN7msdfgenleENS_14SignedDistanceES0_(a: SignedDistance, b: SignedDistance) bool; 29 | pub const lessEqThan = _ZN7msdfgenleENS_14SignedDistanceES0_; 30 | 31 | extern fn _ZN7msdfgengeENS_14SignedDistanceES0_(a: SignedDistance, b: SignedDistance) bool; 32 | pub const greaterEqThan = _ZN7msdfgengeENS_14SignedDistanceES0_; 33 | }; 34 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/Factory.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Factory, to create RTTI objects 13 | class Factory 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Create an object 19 | void * CreateObject(const char *inName); 20 | 21 | /// Find type info for a specific class by name 22 | const RTTI * Find(const char *inName); 23 | 24 | /// Find type info for a specific class by hash 25 | const RTTI * Find(uint32 inHash); 26 | 27 | /// Register an object with the factory. Returns false on failure. 28 | bool Register(const RTTI *inRTTI); 29 | 30 | /// Register a list of objects with the factory. Returns false on failure. 31 | bool Register(const RTTI **inRTTIs, uint inNumber); 32 | 33 | /// Unregisters all types 34 | void Clear(); 35 | 36 | /// Get all registered classes 37 | Array GetAllClasses() const; 38 | 39 | /// Singleton factory instance 40 | static Factory * sInstance; 41 | 42 | private: 43 | using ClassNameMap = UnorderedMap; 44 | 45 | using ClassHashMap = UnorderedMap; 46 | 47 | /// Map of class names to type info 48 | ClassNameMap mClassNameMap; 49 | 50 | // Map of class hash to type info 51 | ClassHashMap mClassHashMap; 52 | }; 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/Atomics.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | // Things we're using from STL 14 | using std::atomic; 15 | using std::memory_order; 16 | using std::memory_order_relaxed; 17 | using std::memory_order_acquire; 18 | using std::memory_order_release; 19 | using std::memory_order_acq_rel; 20 | using std::memory_order_seq_cst; 21 | 22 | /// Atomically compute the min(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated 23 | template 24 | bool AtomicMin(atomic &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst) 25 | { 26 | T cur_value = ioAtomic.load(memory_order_relaxed); 27 | while (cur_value > inValue) 28 | if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder)) 29 | return true; 30 | return false; 31 | } 32 | 33 | /// Atomically compute the max(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated 34 | template 35 | bool AtomicMax(atomic &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst) 36 | { 37 | T cur_value = ioAtomic.load(memory_order_relaxed); 38 | while (cur_value < inValue) 39 | if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder)) 40 | return true; 41 | return false; 42 | } 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Renderer/DebugRendererPlayback.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #ifndef JPH_DEBUG_RENDERER 8 | #error This file should only be included when JPH_DEBUG_RENDERER is defined 9 | #endif // !JPH_DEBUG_RENDERER 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | JPH_NAMESPACE_BEGIN 16 | 17 | /// Class that can read a recorded stream from DebugRendererRecorder and plays it back trough a DebugRenderer 18 | class DebugRendererPlayback 19 | { 20 | public: 21 | /// Constructor 22 | DebugRendererPlayback(DebugRenderer &inRenderer) : mRenderer(inRenderer) { } 23 | 24 | /// Parse a stream of frames 25 | void Parse(StreamIn &inStream); 26 | 27 | /// Get the number of parsed frames 28 | uint GetNumFrames() const { return (uint)mFrames.size(); } 29 | 30 | /// Draw a frame 31 | void DrawFrame(uint inFrameNumber) const; 32 | 33 | private: 34 | /// The debug renderer we're using to do the actual rendering 35 | DebugRenderer & mRenderer; 36 | 37 | /// Mapping of ID to batch 38 | UnorderedMap mBatches; 39 | 40 | /// Mapping of ID to geometry 41 | UnorderedMap mGeometries; 42 | 43 | /// The list of parsed frames 44 | using Frame = DebugRendererRecorder::Frame; 45 | Array mFrames; 46 | }; 47 | 48 | JPH_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ConfigurationString.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Construct a string that lists the most important configuration settings 10 | inline const char *GetConfigurationString() 11 | { 12 | return JPH_IF_SINGLE_PRECISION_ELSE("Single", "Double") " precision " 13 | #if defined(JPH_CPU_X86) 14 | "x86 " 15 | #elif defined(JPH_CPU_ARM) 16 | "ARM " 17 | #elif defined(JPH_PLATFORM_WASM) 18 | "WASM " 19 | #endif 20 | #if JPH_CPU_ADDRESS_BITS == 64 21 | "64-bit " 22 | #elif JPH_CPU_ADDRESS_BITS == 32 23 | "32-bit " 24 | #endif 25 | "with instructions: " 26 | #ifdef JPH_USE_NEON 27 | "NEON " 28 | #endif 29 | #ifdef JPH_USE_SSE 30 | "SSE2 " 31 | #endif 32 | #ifdef JPH_USE_SSE4_1 33 | "SSE4.1 " 34 | #endif 35 | #ifdef JPH_USE_SSE4_2 36 | "SSE4.2 " 37 | #endif 38 | #ifdef JPH_USE_AVX 39 | "AVX " 40 | #endif 41 | #ifdef JPH_USE_AVX2 42 | "AVX2 " 43 | #endif 44 | #ifdef JPH_USE_AVX512 45 | "AVX512 " 46 | #endif 47 | #ifdef JPH_USE_F16C 48 | "F16C " 49 | #endif 50 | #ifdef JPH_USE_LZCNT 51 | "LZCNT " 52 | #endif 53 | #ifdef JPH_USE_TZCNT 54 | "TZCNT " 55 | #endif 56 | #ifdef JPH_USE_FMADD 57 | "FMADD " 58 | #endif 59 | #ifdef JPH_CROSS_PLATFORM_DETERMINISTIC 60 | "(Cross Platform Deterministic) " 61 | #endif 62 | #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED 63 | "(FP Exceptions) " 64 | #endif 65 | #ifdef _DEBUG 66 | "(Debug) " 67 | #endif 68 | ; 69 | } 70 | 71 | JPH_NAMESPACE_END 72 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Geometry/OrientedBox.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | class AABox; 15 | 16 | /// Oriented box 17 | class [[nodiscard]] OrientedBox 18 | { 19 | public: 20 | JPH_OVERRIDE_NEW_DELETE 21 | 22 | /// Constructor 23 | OrientedBox() = default; 24 | OrientedBox(Mat44Arg inOrientation, Vec3Arg inHalfExtents) : mOrientation(inOrientation), mHalfExtents(inHalfExtents) { } 25 | 26 | /// Construct from axis aligned box and transform. Only works for rotation/translation matrix (no scaling / shearing). 27 | OrientedBox(Mat44Arg inOrientation, const AABox &inBox) : OrientedBox(inOrientation.PreTranslated(inBox.GetCenter()), inBox.GetExtent()) { } 28 | 29 | /// Test if oriented boxe overlaps with axis aligned box eachother 30 | bool Overlaps(const AABox &inBox, float inEpsilon = 1.0e-6f) const; 31 | 32 | /// Test if two oriented boxes overlap eachother 33 | bool Overlaps(const OrientedBox &inBox, float inEpsilon = 1.0e-6f) const; 34 | 35 | Mat44 mOrientation; ///< Transform that positions and rotates the local space axis aligned box into world space 36 | Vec3 mHalfExtents; ///< Half extents (half the size of the edge) of the local space axis aligned box 37 | }; 38 | 39 | JPH_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 8 | 9 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 10 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 11 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 12 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 13 | 14 | #pragma once 15 | #include "imgui.h" // IMGUI_IMPL_API 16 | 17 | struct ID3D11Device; 18 | struct ID3D11DeviceContext; 19 | 20 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 21 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 22 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 23 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 24 | 25 | // Use if you want to reset your rendering device without losing Dear ImGui state. 26 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 27 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 28 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/StateRecorderImpl.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Implementation of the StateRecorder class that uses a stringstream as underlying store and that implements checking if the state doesn't change upon reading 12 | class StateRecorderImpl final : public StateRecorder 13 | { 14 | public: 15 | /// Constructor 16 | StateRecorderImpl() = default; 17 | StateRecorderImpl(StateRecorderImpl &&inRHS) : StateRecorder(inRHS), mStream(std::move(inRHS.mStream)) { } 18 | 19 | /// Write a string of bytes to the binary stream 20 | virtual void WriteBytes(const void *inData, size_t inNumBytes) override; 21 | 22 | /// Rewind the stream for reading 23 | void Rewind(); 24 | 25 | /// Read a string of bytes from the binary stream 26 | virtual void ReadBytes(void *outData, size_t inNumBytes) override; 27 | 28 | // See StreamIn 29 | virtual bool IsEOF() const override { return mStream.eof(); } 30 | 31 | // See StreamIn / StreamOut 32 | virtual bool IsFailed() const override { return mStream.fail(); } 33 | 34 | /// Compare this state with a reference state and ensure they are the same 35 | bool IsEqual(StateRecorderImpl &inReference); 36 | 37 | /// Convert the binary data to a string 38 | string GetData() const { return mStream.str(); } 39 | 40 | private: 41 | std::stringstream mStream; 42 | }; 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_wgpu.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for WebGPU 2 | // This needs to be used along with a Platform Binding (e.g. GLFW) 3 | // (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.) 4 | 5 | // Implemented features: 6 | // [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID! 7 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 8 | 9 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 10 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 11 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 12 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 13 | 14 | #pragma once 15 | #include "imgui.h" // IMGUI_IMPL_API 16 | #include 17 | 18 | IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format = WGPUTextureFormat_Undefined); 19 | IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown(); 20 | IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame(); 21 | IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder); 22 | 23 | // Use if you want to reset your rendering device without losing Dear ImGui state. 24 | IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects(); 25 | IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects(); 26 | -------------------------------------------------------------------------------- /test_cases/c024_cpp_bitfields.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const Bitfields = extern struct { 6 | bitfield_1: packed struct(u64) { 7 | bitfield1: u10, // 10 bits 8 | bitfield2: u10, // 20 bits 9 | /// C2Z WARNING: This perhaps shouldn't be padded in this way! 10 | /// Padding added by c2z 11 | _dummy_padding: u44, 12 | }, 13 | bitfield_2: packed struct(u32) { 14 | bitfield3: u5, // 5 bits 15 | bitfield4: i5, // 10 bits 16 | /// C2Z WARNING: This perhaps shouldn't be padded in this way! 17 | /// Padding added by c2z 18 | _dummy_padding: u22, 19 | }, 20 | bitfield_3: packed struct(u8) { 21 | bitfield5: u2, // 2 bits 22 | bitfield6: u2, // 4 bits 23 | bitfield7: u2, // 6 bits 24 | /// C2Z WARNING: This perhaps shouldn't be padded in this way! 25 | /// Padding added by c2z 26 | _dummy_padding: u2, 27 | }, 28 | bitfield_4: packed struct(u32) { 29 | bitfield8: i31, // 31 bits 30 | /// C2Z WARNING: This perhaps shouldn't be padded in this way! 31 | /// Padding added by c2z 32 | _dummy_padding: u1, 33 | }, 34 | bitfield_5: packed struct(u64) { 35 | bitfield9: i30, // 30 bits 36 | /// TODO: Add test of 0-length bitfield here 37 | /// long long : 0; 38 | bitfield11: i30, // 60 bits 39 | /// Padding added by c2z 40 | _dummy_padding: u4, 41 | }, 42 | }; 43 | 44 | extern fn _1_size_of_Bitfields_() c_int; 45 | pub const size_of_Bitfields = _1_size_of_Bitfields_; 46 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/arithmetics.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace msdfgen { 7 | 8 | /// Returns the smaller of the arguments. 9 | template 10 | inline T min(T a, T b) { 11 | return b < a ? b : a; 12 | } 13 | 14 | /// Returns the larger of the arguments. 15 | template 16 | inline T max(T a, T b) { 17 | return a < b ? b : a; 18 | } 19 | 20 | /// Returns the middle out of three values 21 | template 22 | inline T median(T a, T b, T c) { 23 | return max(min(a, b), min(max(a, b), c)); 24 | } 25 | 26 | /// Returns the weighted average of a and b. 27 | template 28 | inline T mix(T a, T b, S weight) { 29 | return T((S(1)-weight)*a+weight*b); 30 | } 31 | 32 | /// Clamps the number to the interval from 0 to 1. 33 | template 34 | inline T clamp(T n) { 35 | return n >= T(0) && n <= T(1) ? n : T(n > T(0)); 36 | } 37 | 38 | /// Clamps the number to the interval from 0 to b. 39 | template 40 | inline T clamp(T n, T b) { 41 | return n >= T(0) && n <= b ? n : T(n > T(0))*b; 42 | } 43 | 44 | /// Clamps the number to the interval from a to b. 45 | template 46 | inline T clamp(T n, T a, T b) { 47 | return n >= a && n <= b ? n : n < a ? a : b; 48 | } 49 | 50 | /// Returns 1 for positive values, -1 for negative values, and 0 for zero. 51 | template 52 | inline int sign(T n) { 53 | return (T(0) < n)-(n < T(0)); 54 | } 55 | 56 | /// Returns 1 for non-negative values and -1 for negative values. 57 | template 58 | inline int nonZeroSign(T n) { 59 | return 2*(n > T(0))-1; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/TickCounter.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | // Include for __rdtsc 8 | #if defined(JPH_PLATFORM_WINDOWS) 9 | #include 10 | #elif defined(JPH_CPU_X86) && defined(JPH_COMPILER_GCC) 11 | #include 12 | #endif 13 | 14 | JPH_NAMESPACE_BEGIN 15 | 16 | #if defined(JPH_PLATFORM_WINDOWS_UWP) || (defined(JPH_PLATFORM_WINDOWS) && defined(JPH_CPU_ARM)) 17 | 18 | /// Functionality to get the processors cycle counter 19 | uint64 GetProcessorTickCount(); // Not inline to avoid having to include Windows.h 20 | 21 | #else 22 | 23 | /// Functionality to get the processors cycle counter 24 | JPH_INLINE uint64 GetProcessorTickCount() 25 | { 26 | #if defined(JPH_PLATFORM_BLUE) 27 | return JPH_PLATFORM_BLUE_GET_TICKS(); 28 | #elif defined(JPH_CPU_X86) 29 | return __rdtsc(); 30 | #elif defined(JPH_CPU_ARM) && defined(JPH_USE_NEON) 31 | uint64 val; 32 | asm volatile("mrs %0, cntvct_el0" : "=r" (val)); 33 | return val; 34 | #elif defined(JPH_CPU_ARM) 35 | return 0; // Not supported 36 | #elif defined(JPH_CPU_WASM) 37 | return 0; // Not supported 38 | #else 39 | #error Undefined 40 | #endif 41 | } 42 | 43 | #endif // JPH_PLATFORM_WINDOWS_UWP || (JPH_PLATFORM_WINDOWS && JPH_CPU_ARM) 44 | 45 | /// Get the amount of ticks per second, note that this number will never be fully accurate as the amound of ticks per second may vary with CPU load, so this number is only to be used to give an indication of time for profiling purposes 46 | uint64 GetProcessorTicksPerSecond(); 47 | 48 | JPH_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_sdlrenderer.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for SDL_Renderer 2 | // (Requires: SDL 2.0.17+) 3 | 4 | // Important to understand: SDL_Renderer is an _optional_ component of SDL. 5 | // For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX. 6 | // If your application will want to render any non trivial amount of graphics other than UI, 7 | // please be aware that SDL_Renderer offers a limited graphic API to the end-user and it might 8 | // be difficult to step out of those boundaries. 9 | // However, we understand it is a convenient choice to get an app started easily. 10 | 11 | // Implemented features: 12 | // [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID! 13 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 14 | // Missing features: 15 | // [ ] Renderer: Multi-viewport support (multiple windows). 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | 20 | struct SDL_Renderer; 21 | 22 | IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer); 23 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer_Shutdown(); 24 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer_NewFrame(); 25 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data); 26 | 27 | // Called by Init/NewFrame/Shutdown 28 | IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateFontsTexture(); 29 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyFontsTexture(); 30 | IMGUI_IMPL_API bool ImGui_ImplSDLRenderer_CreateDeviceObjects(); 31 | IMGUI_IMPL_API void ImGui_ImplSDLRenderer_DestroyDeviceObjects(); 32 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/rasterization.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Vector2.h" 5 | #include "Shape.h" 6 | #include "Projection.h" 7 | #include "Scanline.h" 8 | #include "BitmapRef.hpp" 9 | 10 | namespace msdfgen { 11 | 12 | /// Rasterizes the shape into a monochrome bitmap. 13 | void rasterize(const BitmapRef &output, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO); 14 | /// Fixes the sign of the input signed distance field, so that it matches the shape's rasterized fill. 15 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO); 16 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO); 17 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO); 18 | 19 | // Old version of the function API's kept for backwards compatibility 20 | void rasterize(const BitmapRef &output, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO); 21 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO); 22 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO); 23 | void distanceSignCorrection(const BitmapRef &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ObjectStream/TypeDeclarations.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint8); 16 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint16); 17 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(int); 18 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint32); 19 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint64); 20 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(float); 21 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(double); 22 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(bool); 23 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(String); 24 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Float3); 25 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Double3); 26 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Vec3); 27 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(DVec3); 28 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Vec4); 29 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Quat); 30 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Mat44); 31 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(DMat44); 32 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(Color); 33 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(AABox); 34 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(Triangle); 35 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(IndexedTriangle); 36 | 37 | JPH_NAMESPACE_END 38 | 39 | // These need to be added after all types have been registered or else clang under linux will not find GetRTTIOfType for the type 40 | #include 41 | #include 42 | -------------------------------------------------------------------------------- /use_cases/dotherside/include/DOtherSide/DosIQObjectImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2020 Filippo Cucchetto. 3 | Contact: https://github.com/filcuc/dotherside 4 | 5 | This file is part of the DOtherSide library. 6 | 7 | The DOtherSide library is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version. 10 | 11 | The DOtherSide library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with the DOtherSide library. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | // std 23 | #include 24 | // Qt 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace DOS { 31 | 32 | class DosIQObjectImpl 33 | { 34 | public: 35 | /// Destructor 36 | virtual ~DosIQObjectImpl() = default; 37 | 38 | /// Emit the signal with the given name and arguments 39 | virtual bool emitSignal(QObject *emitter, const QString &name, const std::vector &argumentsValues) = 0; 40 | 41 | /// Return the metaObject 42 | virtual const QMetaObject *metaObject() const = 0; 43 | 44 | /// The qt_metacall implementation 45 | virtual int qt_metacall(QMetaObject::Call, int, void **) = 0; 46 | }; 47 | 48 | } // namespace dos 49 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/STLAlignedAllocator.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// STL allocator that takes care that memory is aligned to N bytes 10 | template 11 | class STLAlignedAllocator 12 | { 13 | public: 14 | using value_type = T; 15 | 16 | /// Pointer to type 17 | using pointer = T *; 18 | using const_pointer = const T *; 19 | 20 | /// Reference to type. 21 | /// Can be removed in C++20. 22 | using reference = T &; 23 | using const_reference = const T &; 24 | 25 | using size_type = size_t; 26 | using difference_type = ptrdiff_t; 27 | 28 | /// Constructor 29 | inline STLAlignedAllocator() = default; 30 | 31 | /// Constructor from other allocator 32 | template 33 | inline explicit STLAlignedAllocator(const STLAlignedAllocator &) { } 34 | 35 | /// Allocate memory 36 | inline pointer allocate(size_type inN) 37 | { 38 | return (pointer)AlignedAllocate(inN * sizeof(value_type), N); 39 | } 40 | 41 | /// Free memory 42 | inline void deallocate(pointer inPointer, size_type) 43 | { 44 | AlignedFree(inPointer); 45 | } 46 | 47 | /// Allocators are stateless so assumed to be equal 48 | inline bool operator == (const STLAlignedAllocator &) const 49 | { 50 | return true; 51 | } 52 | 53 | inline bool operator != (const STLAlignedAllocator &) const 54 | { 55 | return false; 56 | } 57 | 58 | /// Converting to allocator for other type 59 | template 60 | struct rebind 61 | { 62 | using other = STLAlignedAllocator; 63 | }; 64 | }; 65 | 66 | JPH_NAMESPACE_END 67 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/StreamWrapper.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 11 | #include 12 | JPH_SUPPRESS_WARNINGS_STD_END 13 | 14 | JPH_NAMESPACE_BEGIN 15 | 16 | /// Wrapper around std::ostream 17 | class StreamOutWrapper : public StreamOut 18 | { 19 | public: 20 | /// Constructor 21 | StreamOutWrapper(ostream &ioWrapped) : mWrapped(ioWrapped) { } 22 | 23 | /// Write a string of bytes to the binary stream 24 | virtual void WriteBytes(const void *inData, size_t inNumBytes) override { mWrapped.write((const char *)inData, inNumBytes); } 25 | 26 | /// Returns true if there was an IO failure 27 | virtual bool IsFailed() const override { return mWrapped.fail(); } 28 | 29 | private: 30 | ostream & mWrapped; 31 | }; 32 | 33 | /// Wrapper around std::istream 34 | class StreamInWrapper : public StreamIn 35 | { 36 | public: 37 | /// Constructor 38 | StreamInWrapper(istream &ioWrapped) : mWrapped(ioWrapped) { } 39 | 40 | /// Write a string of bytes to the binary stream 41 | virtual void ReadBytes(void *outData, size_t inNumBytes) override { mWrapped.read((char *)outData, inNumBytes); } 42 | 43 | /// Returns true when an attempt has been made to read past the end of the file 44 | virtual bool IsEOF() const override { return mWrapped.eof(); } 45 | 46 | /// Returns true if there was an IO failure 47 | virtual bool IsFailed() const override { return mWrapped.fail(); } 48 | 49 | private: 50 | istream & mWrapped; 51 | }; 52 | 53 | JPH_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleSplitter/TriangleSplitterBinning.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Binning splitter approach taken from: Realtime Ray Tracing on GPU with BVH-based Packet Traversal by Johannes Gunther et al. 13 | class TriangleSplitterBinning : public TriangleSplitter 14 | { 15 | public: 16 | /// Constructor 17 | TriangleSplitterBinning(const VertexList &inVertices, const IndexedTriangleList &inTriangles, uint inMinNumBins = 8, uint inMaxNumBins = 128, uint inNumTrianglesPerBin = 6); 18 | 19 | // See TriangleSplitter::GetStats 20 | virtual void GetStats(Stats &outStats) const override 21 | { 22 | outStats.mSplitterName = "TriangleSplitterBinning"; 23 | } 24 | 25 | // See TriangleSplitter::Split 26 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 27 | 28 | private: 29 | // Configuration 30 | const uint mMinNumBins; 31 | const uint mMaxNumBins; 32 | const uint mNumTrianglesPerBin; 33 | 34 | struct Bin 35 | { 36 | // Properties of this bin 37 | AABox mBounds; 38 | float mMinCentroid; 39 | uint mNumTriangles; 40 | 41 | // Accumulated data from left most / right most bin to current (including this bin) 42 | AABox mBoundsAccumulatedLeft; 43 | AABox mBoundsAccumulatedRight; 44 | uint mNumTrianglesAccumulatedLeft; 45 | uint mNumTrianglesAccumulatedRight; 46 | }; 47 | 48 | // Scratch area to store the bins 49 | Array mBins; 50 | }; 51 | 52 | JPH_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/Scanline.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace msdfgen { 7 | 8 | /// Fill rule dictates how intersection total is interpreted during rasterization. 9 | enum FillRule { 10 | FILL_NONZERO, 11 | FILL_ODD, // "even-odd" 12 | FILL_POSITIVE, 13 | FILL_NEGATIVE 14 | }; 15 | 16 | /// Resolves the number of intersection into a binary fill value based on fill rule. 17 | bool interpretFillRule(int intersections, FillRule fillRule); 18 | 19 | /// Represents a horizontal scanline intersecting a shape. 20 | class Scanline { 21 | 22 | public: 23 | /// An intersection with the scanline. 24 | struct Intersection { 25 | /// X coordinate. 26 | double x; 27 | /// Normalized Y direction of the oriented edge at the point of intersection. 28 | int direction; 29 | }; 30 | 31 | static double overlap(const Scanline &a, const Scanline &b, double xFrom, double xTo, FillRule fillRule); 32 | 33 | Scanline(); 34 | /// Populates the intersection list. 35 | void setIntersections(const std::vector &intersections); 36 | #ifdef MSDFGEN_USE_CPP11 37 | void setIntersections(std::vector &&intersections); 38 | #endif 39 | /// Returns the number of intersections left of x. 40 | int countIntersections(double x) const; 41 | /// Returns the total sign of intersections left of x. 42 | int sumIntersections(double x) const; 43 | /// Decides whether the scanline is filled at x based on fill rule. 44 | bool filled(double x, FillRule fillRule) const; 45 | 46 | private: 47 | std::vector intersections; 48 | mutable int lastIndex; 49 | 50 | void preprocess(); 51 | int moveTo(double x) const; 52 | 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/InsertionSort.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Implementation of the insertion sort algorithm. 10 | template 11 | inline void InsertionSort(Iterator inBegin, Iterator inEnd, Compare inCompare) 12 | { 13 | // Empty arrays don't need to be sorted 14 | if (inBegin != inEnd) 15 | { 16 | // Start at the second element 17 | for (Iterator i = inBegin + 1; i != inEnd; ++i) 18 | { 19 | // Move this element to a temporary value 20 | auto x = std::move(*i); 21 | 22 | // Check if the element goes before inBegin (we can't decrement the iterator before inBegin so this needs to be a separate branch) 23 | if (inCompare(x, *inBegin)) 24 | { 25 | // Move all elements to the right to make space for x 26 | Iterator prev; 27 | for (Iterator j = i; j != inBegin; j = prev) 28 | { 29 | prev = j - 1; 30 | *j = *prev; 31 | } 32 | 33 | // Move x to the first place 34 | *inBegin = std::move(x); 35 | } 36 | else 37 | { 38 | // Move elements to the right as long as they are bigger than x 39 | Iterator j = i; 40 | for (Iterator prev = j - 1; inCompare(x, *prev); j = prev, --prev) 41 | *j = std::move(*prev); 42 | 43 | // Move x into place 44 | *j = std::move(x); 45 | } 46 | } 47 | } 48 | } 49 | 50 | /// Implementation of insertion sort algorithm without comparator. 51 | template 52 | inline void InsertionSort(Iterator inBegin, Iterator inEnd) 53 | { 54 | std::less<> compare; 55 | InsertionSort(inBegin, inEnd, compare); 56 | } 57 | 58 | JPH_NAMESPACE_END 59 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Geometry/RayCapsule.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Tests a ray starting at inRayOrigin and extending infinitely in inRayDirection 13 | /// against a capsule centered around the origin with its axis along the Y axis and half height specified. 14 | /// @return FLT_MAX if there is no intersection, otherwise the fraction along the ray. 15 | /// @param inRayDirection Ray direction. Does not need to be normalized. 16 | /// @param inRayOrigin Origin of the ray. If the ray starts inside the capsule, the returned fraction will be 0. 17 | /// @param inCapsuleHalfHeight Distance from the origin to the center of the top sphere (or that of the bottom) 18 | /// @param inCapsuleRadius Radius of the top/bottom sphere 19 | JPH_INLINE float RayCapsule(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCapsuleHalfHeight, float inCapsuleRadius) 20 | { 21 | // Test infinite cylinder 22 | float cylinder = RayCylinder(inRayOrigin, inRayDirection, inCapsuleRadius); 23 | if (cylinder == FLT_MAX) 24 | return FLT_MAX; 25 | 26 | // If this hit is in the finite cylinder we have our fraction 27 | if (abs(inRayOrigin.GetY() + cylinder * inRayDirection.GetY()) <= inCapsuleHalfHeight) 28 | return cylinder; 29 | 30 | // Test upper and lower sphere 31 | Vec3 sphere_center(0, inCapsuleHalfHeight, 0); 32 | float upper = RaySphere(inRayOrigin, inRayDirection, sphere_center, inCapsuleRadius); 33 | float lower = RaySphere(inRayOrigin, inRayDirection, -sphere_center, inCapsuleRadius); 34 | return min(upper, lower); 35 | } 36 | 37 | JPH_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ObjectStream/SerializableAttributeTyped.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | ////////////////////////////////////////////////////////////////////////////////////////// 14 | // Macros to add properties to be serialized 15 | ////////////////////////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | inline void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName) 19 | { 20 | inRTTI.AddAttribute(SerializableAttribute(inName, inOffset, 21 | []() 22 | { 23 | return GetPrimitiveTypeOfType((MemberType *)nullptr); 24 | }, 25 | [](int inArrayDepth, EOSDataType inDataType, const char *inClassName) 26 | { 27 | return OSIsType((MemberType *)nullptr, inArrayDepth, inDataType, inClassName); 28 | }, 29 | [](IObjectStreamIn &ioStream, void *inObject) 30 | { 31 | return OSReadData(ioStream, *reinterpret_cast(inObject)); 32 | }, 33 | [](IObjectStreamOut &ioStream, const void *inObject) 34 | { 35 | OSWriteData(ioStream, *reinterpret_cast(inObject)); 36 | }, 37 | [](IObjectStreamOut &ioStream) 38 | { 39 | OSWriteDataType(ioStream, (MemberType *)nullptr); 40 | })); 41 | } 42 | 43 | // JPH_ADD_ATTRIBUTE 44 | #define JPH_ADD_ATTRIBUTE(class_name, member_name) \ 45 | AddSerializableAttributeTyped(inRTTI, offsetof(class_name, member_name), #member_name); 46 | 47 | JPH_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/EPhysicsUpdateError.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Enum used by PhysicsSystem to report error conditions during the PhysicsSystem::Update call. This is a bit field, multiple errors can trigger in the same update. 10 | enum class EPhysicsUpdateError : uint32 11 | { 12 | None = 0, ///< No errors 13 | ManifoldCacheFull = 1 << 0, ///< The manifold cache is full, this means that the total number of contacts between bodies is too high. Some contacts were ignored. Increase inMaxContactConstraints in PhysicsSystem::Init. 14 | BodyPairCacheFull = 1 << 1, ///< The body pair cache is full, this means that too many bodies contacted. Some contacts were ignored. Increase inMaxBodyPairs in PhysicsSystem::Init. 15 | ContactConstraintsFull = 1 << 2, ///< The contact constraints buffer is full. Some contacts were ignored. Increase inMaxContactConstraints in PhysicsSystem::Init. 16 | }; 17 | 18 | /// OR operator for EPhysicsUpdateError 19 | inline EPhysicsUpdateError operator | (EPhysicsUpdateError inA, EPhysicsUpdateError inB) 20 | { 21 | return static_cast(static_cast(inA) | static_cast(inB)); 22 | } 23 | 24 | /// OR operator for EPhysicsUpdateError 25 | inline EPhysicsUpdateError operator |= (EPhysicsUpdateError &ioA, EPhysicsUpdateError inB) 26 | { 27 | ioA = ioA | inB; 28 | return ioA; 29 | } 30 | 31 | /// AND operator for EPhysicsUpdateError 32 | inline EPhysicsUpdateError operator & (EPhysicsUpdateError inA, EPhysicsUpdateError inB) 33 | { 34 | return static_cast(static_cast(inA) & static_cast(inB)); 35 | } 36 | 37 | JPH_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Body/MotionQuality.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Motion quality, or how well it detects collisions when it has a high velocity 10 | enum class EMotionQuality : uint8 11 | { 12 | /// Update the body in discrete steps. Body will tunnel throuh thin objects if its velocity is high enough. 13 | /// This is the cheapest way of simulating a body. 14 | Discrete, 15 | 16 | /// Update the body using linear casting. When stepping the body, its collision shape is cast from 17 | /// start to destination using the starting rotation. The body will not be able to tunnel through thin 18 | /// objects at high velocity, but tunneling is still possible if the body is long and thin and has high 19 | /// angular velocity. Time is stolen from the object (which means it will move up to the first collision 20 | /// and will not bounce off the surface until the next integration step). This will make the body appear 21 | /// to go slower when it collides with high velocity. In order to not get stuck, the body is always 22 | /// allowed to move by a fraction of it's inner radius, which may eventually lead it to pass through geometry. 23 | /// 24 | /// Note that if you're using a collision listener, you can receive contact added/persisted notifications of contacts 25 | /// that may in the end not happen. This happens between bodies that are using casting: If bodies A and B collide at t1 26 | /// and B and C collide at t2 where t2 < t1 and A and C don't collide. In this case you may receive an incorrect contact 27 | /// point added callback between A and B (which will be removed the next frame). 28 | LinearCast, 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_opengles2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles2.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 2.0 API headers. 26 | */ 27 | #include "SDL_config.h" 28 | 29 | #if !defined(_MSC_VER) && !defined(SDL_USE_BUILTIN_OPENGL_DEFINITIONS) 30 | 31 | #ifdef __IPHONEOS__ 32 | #include 33 | #include 34 | #else 35 | #include 36 | #include 37 | #include 38 | #endif 39 | 40 | #else /* _MSC_VER */ 41 | 42 | /* OpenGL ES2 headers for Visual Studio */ 43 | #include "SDL_opengles2_khrplatform.h" 44 | #include "SDL_opengles2_gl2platform.h" 45 | #include "SDL_opengles2_gl2.h" 46 | #include "SDL_opengles2_gl2ext.h" 47 | 48 | #endif /* _MSC_VER */ 49 | 50 | #ifndef APIENTRY 51 | #define APIENTRY GL_APIENTRY 52 | #endif 53 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/Semaphore.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | #include 10 | #include 11 | JPH_SUPPRESS_WARNINGS_STD_END 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | // Things we're using from STL 16 | using std::atomic; 17 | using std::mutex; 18 | using std::condition_variable; 19 | 20 | /// Implements a semaphore 21 | /// When we switch to C++20 we can use counting_semaphore to unify this 22 | class Semaphore 23 | { 24 | public: 25 | /// Constructor 26 | Semaphore(); 27 | ~Semaphore(); 28 | 29 | /// Release the semaphore, signalling the thread waiting on the barrier that there may be work 30 | void Release(uint inNumber = 1); 31 | 32 | /// Acquire the semaphore inNumber times 33 | void Acquire(uint inNumber = 1); 34 | 35 | /// Get the current value of the semaphore 36 | inline int GetValue() const { return mCount; } 37 | 38 | private: 39 | #ifdef JPH_PLATFORM_WINDOWS 40 | // On windows we use a semaphore object since it is more efficient than a lock and a condition variable 41 | alignas(JPH_CACHE_LINE_SIZE) atomic mCount { 0 }; ///< We increment mCount for every release, to acquire we decrement the count. If the count is negative we know that we are waiting on the actual semaphore. 42 | void * mSemaphore; ///< The semaphore is an expensive construct so we only acquire/release it if we know that we need to wait/have waiting threads 43 | #else 44 | // Other platforms: Emulate a semaphore using a mutex, condition variable and count 45 | mutex mLock; 46 | condition_variable mWaitVariable; 47 | int mCount = 0; 48 | #endif 49 | }; 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /use_cases/dotherside/include/DOtherSide/DosQObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2020 Filippo Cucchetto. 3 | Contact: https://github.com/filcuc/dotherside 4 | 5 | This file is part of the DOtherSide library. 6 | 7 | The DOtherSide library is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version. 10 | 11 | The DOtherSide library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with the DOtherSide library. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | // Qt 23 | #include 24 | #include 25 | // DOtherSide 26 | #include "DOtherSideTypesCpp.h" 27 | #include "DOtherSide/DosIQObjectImpl.h" 28 | 29 | namespace DOS { 30 | 31 | /// This class model a QObject 32 | class DosQObject : public QObject, public DosIQObjectImpl 33 | { 34 | public: 35 | /// Constructor 36 | DosQObject(void *dObjectPointer, DosIQMetaObjectPtr metaObject, DObjectCallback dObjectCallback); 37 | 38 | /// Emit a signal 39 | bool emitSignal(QObject *emitter, const QString &name, const std::vector &arguments) override; 40 | 41 | /// Return the metaObject 42 | const QMetaObject *metaObject() const override; 43 | 44 | /// The qt_metacall 45 | int qt_metacall(QMetaObject::Call, int, void **) override; 46 | 47 | private: 48 | std::unique_ptr m_impl; 49 | }; 50 | 51 | } // namespace DOS 52 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/IssueReporting.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Trace function, needs to be overridden by application. This should output a line of text to the log / TTY. 10 | using TraceFunction = void (*)(const char *inFMT, ...); 11 | extern TraceFunction Trace; 12 | 13 | // Always turn on asserts in Debug mode 14 | #if defined(_DEBUG) && !defined(JPH_ENABLE_ASSERTS) 15 | #define JPH_ENABLE_ASSERTS 16 | #endif 17 | 18 | #ifdef JPH_ENABLE_ASSERTS 19 | /// Function called when an assertion fails. This function should return true if a breakpoint needs to be triggered 20 | using AssertFailedFunction = bool(*)(const char *inExpression, const char *inMessage, const char *inFile, uint inLine); 21 | extern AssertFailedFunction AssertFailed; 22 | 23 | // Helper functions to pass message on to failed function 24 | struct AssertLastParam { }; 25 | inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, AssertLastParam) { return AssertFailed(inExpression, nullptr, inFile, inLine); } 26 | inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, const char *inMessage, AssertLastParam) { return AssertFailed(inExpression, inMessage, inFile, inLine); } 27 | 28 | /// Main assert macro, usage: JPH_ASSERT(condition, message) or JPH_ASSERT(condition) 29 | #define JPH_ASSERT(inExpression, ...) do { if (!(inExpression) && AssertFailedParamHelper(#inExpression, __FILE__, uint(__LINE__), ##__VA_ARGS__, AssertLastParam())) JPH_BREAKPOINT; } while (false) 30 | 31 | #define JPH_IF_ENABLE_ASSERTS(...) __VA_ARGS__ 32 | #else 33 | #define JPH_ASSERT(...) ((void)0) 34 | 35 | #define JPH_IF_ENABLE_ASSERTS(...) 36 | #endif // JPH_ENABLE_ASSERTS 37 | 38 | JPH_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Math/Trigonometry.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | // Note that this file exists because std::sin etc. are not platform independent and will lead to non-deterministic simulation 10 | 11 | /// Sine of x (input in radians) 12 | JPH_INLINE float Sin(float inX) 13 | { 14 | Vec4 s, c; 15 | Vec4::sReplicate(inX).SinCos(s, c); 16 | return s.GetX(); 17 | } 18 | 19 | /// Cosine of x (input in radians) 20 | JPH_INLINE float Cos(float inX) 21 | { 22 | Vec4 s, c; 23 | Vec4::sReplicate(inX).SinCos(s, c); 24 | return c.GetX(); 25 | } 26 | 27 | /// Tangent of x (input in radians) 28 | JPH_INLINE float Tan(float inX) 29 | { 30 | return Vec4::sReplicate(inX).Tan().GetX(); 31 | } 32 | 33 | /// Arc sine of x (returns value in the range [-PI / 2, PI / 2]) 34 | /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::asin 35 | JPH_INLINE float ASin(float inX) 36 | { 37 | return Vec4::sReplicate(inX).ASin().GetX(); 38 | } 39 | 40 | /// Arc cosine of x (returns value in the range [0, PI]) 41 | /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::acos 42 | JPH_INLINE float ACos(float inX) 43 | { 44 | return Vec4::sReplicate(inX).ACos().GetX(); 45 | } 46 | 47 | /// Arc tangent of x (returns value in the range [-PI / 2, PI / 2]) 48 | JPH_INLINE float ATan(float inX) 49 | { 50 | return Vec4::sReplicate(inX).ATan().GetX(); 51 | } 52 | 53 | /// Arc tangent of y / x using the signs of the arguments to determine the correct quadrant (returns value in the range [-PI, PI]) 54 | JPH_INLINE float ATan2(float inY, float inX) 55 | { 56 | return Vec4::sATan2(Vec4::sReplicate(inY), Vec4::sReplicate(inX)).GetX(); 57 | } 58 | 59 | JPH_NAMESPACE_END 60 | -------------------------------------------------------------------------------- /use_cases/box2d/include/b2_timer.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2019 Erin Catto 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #ifndef B2_TIMER_H 24 | #define B2_TIMER_H 25 | 26 | #include "b2_api.h" 27 | #include "b2_settings.h" 28 | 29 | /// Timer for profiling. This has platform specific code and may 30 | /// not work on every platform. 31 | class B2_API b2Timer 32 | { 33 | public: 34 | 35 | /// Constructor 36 | b2Timer(); 37 | 38 | /// Reset the timer. 39 | void Reset(); 40 | 41 | /// Get the time since construction or the last reset. 42 | float GetMilliseconds() const; 43 | 44 | private: 45 | 46 | #if defined(_WIN32) 47 | double m_start; 48 | static double s_invFrequency; 49 | #elif defined(__linux__) || defined (__APPLE__) 50 | unsigned long long m_start_sec; 51 | unsigned long long m_start_usec; 52 | #endif 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /test_cases/c023_cpp_nested_structs.zig: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | const std = @import("std"); 3 | //const cpp = @import("cpp"); 4 | 5 | pub const RootStruct = extern struct { 6 | value_begin: c_int, 7 | nested_struct_1a: __Struct0, 8 | nested_struct_1b: __Struct0, 9 | value_mid: c_int, 10 | nested_struct_2b: NestedStruct2a, 11 | nested_struct_3b: NestedStruct3a, 12 | nested_struct_3c: NestedStruct3a, 13 | __struct_field2: __Struct1, 14 | value_end: c_int, 15 | 16 | pub const __Struct0 = extern struct { 17 | m1: f32, 18 | }; 19 | 20 | pub const NestedStruct2a = extern struct { 21 | m2: f32, 22 | }; 23 | 24 | pub const NestedStruct3a = extern struct { 25 | m3: f32, 26 | }; 27 | 28 | /// Fully anonymous 4 29 | pub const __Struct1 = extern struct { 30 | m44: f32, 31 | }; 32 | }; 33 | 34 | extern fn _1_test_sizeof_RootStruct_() c_int; 35 | pub const test_sizeof_RootStruct = _1_test_sizeof_RootStruct_; 36 | 37 | pub const RootUnion = extern struct { 38 | value_begin: c_int, 39 | nested_union_1a: __Union0, 40 | nested_union_1b: __Union0, 41 | value_mid: c_int, 42 | nested_union_2b: NestedUnion2a, 43 | nested_union_3b: NestedUnion3a, 44 | nested_union_3c: NestedUnion3a, 45 | __union_field2: __Union1, 46 | value_end: c_int, 47 | 48 | pub const __Union0 = extern union { 49 | iii1: c_int, 50 | fff1: f32, 51 | }; 52 | 53 | pub const NestedUnion2a = extern union { 54 | iii2: c_int, 55 | fff2: f32, 56 | }; 57 | 58 | pub const NestedUnion3a = extern union { 59 | iii3: c_int, 60 | fff3: f32, 61 | }; 62 | 63 | /// Fully anonymous 4 64 | pub const __Union1 = extern union { 65 | iii4: c_int, 66 | fff4: f32, 67 | }; 68 | }; 69 | 70 | extern fn _1_test_sizeof_RootUnion_() c_int; 71 | pub const test_sizeof_RootUnion = _1_test_sizeof_RootUnion_; 72 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/StringTools.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Create a formatted text string for debugging purposes. 10 | /// Note that this function has an internal buffer of 1024 characters, so long strings will be trimmed. 11 | String StringFormat(const char *inFMT, ...); 12 | 13 | /// Convert type to string 14 | template 15 | String ConvertToString(const T &inValue) 16 | { 17 | using OStringStream = std::basic_ostringstream, STLAllocator>; 18 | OStringStream oss; 19 | oss << inValue; 20 | return oss.str(); 21 | } 22 | 23 | /// Calculate the FNV-1a hash of inString. 24 | /// @see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function 25 | constexpr uint64 HashString(const char *inString) 26 | { 27 | uint64 hash = 14695981039346656037UL; 28 | for (const char *c = inString; *c != 0; ++c) 29 | { 30 | hash ^= *c; 31 | hash = hash * 1099511628211UL; 32 | } 33 | return hash; 34 | } 35 | 36 | /// Replace substring with other string 37 | void StringReplace(String &ioString, const string_view &inSearch, const string_view &inReplace); 38 | 39 | /// Convert a delimited string to an array of strings 40 | void StringToVector(const string_view &inString, Array &outVector, const string_view &inDelimiter = ",", bool inClearVector = true); 41 | 42 | /// Convert an array strings to a delimited string 43 | void VectorToString(const Array &inVector, String &outString, const string_view &inDelimiter = ","); 44 | 45 | /// Convert a string to lower case 46 | String ToLower(const string_view &inString); 47 | 48 | /// Converts the lower 4 bits of inNibble to a string that represents the number in binary format 49 | const char *NibbleToBinary(uint32 inNibble); 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /use_cases/box2d/include/b2_api.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2019 Erin Catto 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #ifndef B2_API_H 24 | #define B2_API_H 25 | 26 | #ifdef B2_SHARED 27 | #if defined _WIN32 || defined __CYGWIN__ 28 | #ifdef box2d_EXPORTS 29 | #ifdef __GNUC__ 30 | #define B2_API __attribute__ ((dllexport)) 31 | #else 32 | #define B2_API __declspec(dllexport) 33 | #endif 34 | #else 35 | #ifdef __GNUC__ 36 | #define B2_API __attribute__ ((dllimport)) 37 | #else 38 | #define B2_API __declspec(dllimport) 39 | #endif 40 | #endif 41 | #else 42 | #if __GNUC__ >= 4 43 | #define B2_API __attribute__ ((visibility ("default"))) 44 | #else 45 | #define B2_API 46 | #endif 47 | #endif 48 | #else 49 | #define B2_API 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/ObjectStream/SerializableAttributeEnum.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | ////////////////////////////////////////////////////////////////////////////////////////// 13 | // Macros to add properties to be serialized 14 | ////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | template 17 | inline void AddSerializableAttributeEnum(RTTI &inRTTI, uint inOffset, const char *inName) 18 | { 19 | inRTTI.AddAttribute(SerializableAttribute(inName, inOffset, 20 | []() -> const RTTI * 21 | { 22 | return nullptr; 23 | }, 24 | [](int inArrayDepth, EOSDataType inDataType, [[maybe_unused]] const char *inClassName) 25 | { 26 | return inArrayDepth == 0 && inDataType == EOSDataType::T_uint32; 27 | }, 28 | [](IObjectStreamIn &ioStream, void *inObject) 29 | { 30 | uint32 temporary; 31 | if (OSReadData(ioStream, temporary)) 32 | { 33 | *reinterpret_cast(inObject) = static_cast(temporary); 34 | return true; 35 | } 36 | return false; 37 | }, 38 | [](IObjectStreamOut &ioStream, const void *inObject) 39 | { 40 | static_assert(sizeof(MemberType) <= sizeof(uint32)); 41 | uint32 temporary = uint32(*reinterpret_cast(inObject)); 42 | OSWriteData(ioStream, temporary); 43 | }, 44 | [](IObjectStreamOut &ioStream) 45 | { 46 | ioStream.WriteDataType(EOSDataType::T_uint32); 47 | })); 48 | } 49 | 50 | // JPH_ADD_ENUM_ATTRIBUTE 51 | #define JPH_ADD_ENUM_ATTRIBUTE(class_name, member_name) \ 52 | AddSerializableAttributeEnum(inRTTI, offsetof(class_name, member_name), #member_name); 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/TriangleSplitter/TriangleSplitterFixedLeafSize.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Same as TriangleSplitterBinning, but ensuring that leaves have a fixed amount of triangles 13 | /// The resulting tree should be suitable for processing on GPU where we want all threads to process an equal amount of triangles 14 | class TriangleSplitterFixedLeafSize : public TriangleSplitter 15 | { 16 | public: 17 | /// Constructor 18 | TriangleSplitterFixedLeafSize(const VertexList &inVertices, const IndexedTriangleList &inTriangles, uint inLeafSize, uint inMinNumBins = 8, uint inMaxNumBins = 128, uint inNumTrianglesPerBin = 6); 19 | 20 | // See TriangleSplitter::GetStats 21 | virtual void GetStats(Stats &outStats) const override 22 | { 23 | outStats.mSplitterName = "TriangleSplitterFixedLeafSize"; 24 | outStats.mLeafSize = mLeafSize; 25 | } 26 | 27 | // See TriangleSplitter::Split 28 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 29 | 30 | private: 31 | /// Get centroid for group 32 | Vec3 GetCentroidForGroup(uint inFirstTriangleInGroup); 33 | 34 | // Configuration 35 | const uint mLeafSize; 36 | const uint mMinNumBins; 37 | const uint mMaxNumBins; 38 | const uint mNumTrianglesPerBin; 39 | 40 | struct Bin 41 | { 42 | // Properties of this bin 43 | AABox mBounds; 44 | float mMinCentroid; 45 | uint mNumTriangles; 46 | 47 | // Accumulated data from left most / right most bin to current (including this bin) 48 | AABox mBoundsAccumulatedLeft; 49 | AABox mBoundsAccumulatedRight; 50 | uint mNumTrianglesAccumulatedLeft; 51 | uint mNumTrianglesAccumulatedRight; 52 | }; 53 | }; 54 | 55 | JPH_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /use_cases/box2d/include/b2_contact_manager.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2019 Erin Catto 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #ifndef B2_CONTACT_MANAGER_H 24 | #define B2_CONTACT_MANAGER_H 25 | 26 | #include "b2_api.h" 27 | #include "b2_broad_phase.h" 28 | 29 | class b2Contact; 30 | class b2ContactFilter; 31 | class b2ContactListener; 32 | class b2BlockAllocator; 33 | 34 | // Delegate of b2World. 35 | class B2_API b2ContactManager 36 | { 37 | public: 38 | b2ContactManager(); 39 | 40 | // Broad-phase callback. 41 | void AddPair(void* proxyUserDataA, void* proxyUserDataB); 42 | 43 | void FindNewContacts(); 44 | 45 | void Destroy(b2Contact* c); 46 | 47 | void Collide(); 48 | 49 | b2BroadPhase m_broadPhase; 50 | b2Contact* m_contactList; 51 | int32 m_contactCount; 52 | b2ContactFilter* m_contactFilter; 53 | b2ContactListener* m_contactListener; 54 | b2BlockAllocator* m_allocator; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /use_cases/msdfgen/include/core/msdf-error-correction.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "Vector2.h" 5 | #include "Projection.h" 6 | #include "Shape.h" 7 | #include "BitmapRef.hpp" 8 | #include "generator-config.h" 9 | 10 | namespace msdfgen { 11 | 12 | /// Predicts potential artifacts caused by the interpolation of the MSDF and corrects them by converting nearby texels to single-channel. 13 | void msdfErrorCorrection(const BitmapRef &sdf, const Shape &shape, const Projection &projection, double range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig()); 14 | void msdfErrorCorrection(const BitmapRef &sdf, const Shape &shape, const Projection &projection, double range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig()); 15 | 16 | /// Applies the simplified error correction to all discontiunous distances (INDISCRIMINATE mode). Does not need shape or translation. 17 | void msdfFastDistanceErrorCorrection(const BitmapRef &sdf, const Projection &projection, double range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio); 18 | void msdfFastDistanceErrorCorrection(const BitmapRef &sdf, const Projection &projection, double range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio); 19 | 20 | /// Applies the simplified error correction to edges only (EDGE_ONLY mode). Does not need shape or translation. 21 | void msdfFastEdgeErrorCorrection(const BitmapRef &sdf, const Projection &projection, double range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio); 22 | void msdfFastEdgeErrorCorrection(const BitmapRef &sdf, const Projection &projection, double range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio); 23 | 24 | /// The original version of the error correction algorithm. 25 | void msdfErrorCorrection_legacy(const BitmapRef &output, const Vector2 &threshold); 26 | void msdfErrorCorrection_legacy(const BitmapRef &output, const Vector2 &threshold); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/STLTempAllocator.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// STL allocator that wraps around TempAllocator 12 | template 13 | class STLTempAllocator 14 | { 15 | public: 16 | using value_type = T; 17 | 18 | /// Pointer to type 19 | using pointer = T *; 20 | using const_pointer = const T *; 21 | 22 | /// Reference to type. 23 | /// Can be removed in C++20. 24 | using reference = T &; 25 | using const_reference = const T &; 26 | 27 | using size_type = size_t; 28 | using difference_type = ptrdiff_t; 29 | 30 | /// Constructor 31 | inline STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { } 32 | 33 | /// Constructor from other allocator 34 | template 35 | inline explicit STLTempAllocator(const STLTempAllocator &inRHS) : mAllocator(inRHS.GetAllocator()) { } 36 | 37 | /// Allocate memory 38 | inline pointer allocate(size_type inN) 39 | { 40 | return (pointer)mAllocator.Allocate(uint(inN * sizeof(value_type))); 41 | } 42 | 43 | /// Free memory 44 | inline void deallocate(pointer inPointer, size_type inN) 45 | { 46 | mAllocator.Free(inPointer, uint(inN * sizeof(value_type))); 47 | } 48 | 49 | /// Allocators are stateless so assumed to be equal 50 | inline bool operator == (const STLTempAllocator &) const 51 | { 52 | return true; 53 | } 54 | 55 | inline bool operator != (const STLTempAllocator &) const 56 | { 57 | return false; 58 | } 59 | 60 | /// Converting to allocator for other type 61 | template 62 | struct rebind 63 | { 64 | using other = STLTempAllocator; 65 | }; 66 | 67 | /// Get our temp allocator 68 | TempAllocator & GetAllocator() const 69 | { 70 | return mAllocator; 71 | } 72 | 73 | private: 74 | TempAllocator & mAllocator; 75 | }; 76 | 77 | JPH_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_android.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Android native app 2 | // This needs to be used along with the OpenGL 3 Renderer (imgui_impl_opengl3) 3 | 4 | // Implemented features: 5 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // Missing features: 8 | // [ ] Platform: Clipboard support. 9 | // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android. 11 | // Important: 12 | // - Consider using SDL or GLFW backend on Android, which will be more full-featured than this. 13 | // - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446) 14 | // - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446) 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 19 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 20 | 21 | #pragma once 22 | 23 | struct ANativeWindow; 24 | struct AInputEvent; 25 | 26 | IMGUI_IMPL_API bool ImGui_ImplAndroid_Init(ANativeWindow* window); 27 | IMGUI_IMPL_API int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event); 28 | IMGUI_IMPL_API void ImGui_ImplAndroid_Shutdown(); 29 | IMGUI_IMPL_API void ImGui_ImplAndroid_NewFrame(); 30 | -------------------------------------------------------------------------------- /use_cases/SDL2/include/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2023 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/SortReverseAndStore.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// This function will sort values from high to low and only keep the ones that are less than inMaxValue 10 | /// @param inValues Values to be sorted 11 | /// @param inMaxValue Values need to be less than this to keep them 12 | /// @param ioIdentifiers 4 identifiers that will be sorted in the same way as the values 13 | /// @param outValues The values are stored here from high to low 14 | /// @return The number of values that were kept 15 | JPH_INLINE int SortReverseAndStore(Vec4Arg inValues, float inMaxValue, UVec4 &ioIdentifiers, float *outValues) 16 | { 17 | // Sort so that highest values are first (we want to first process closer hits and we process stack top to bottom) 18 | Vec4::sSort4Reverse(inValues, ioIdentifiers); 19 | 20 | // Count how many results are less than the max value 21 | UVec4 closer = Vec4::sLess(inValues, Vec4::sReplicate(inMaxValue)); 22 | int num_results = closer.CountTrues(); 23 | 24 | // Shift the values so that only the ones that are less than max are kept 25 | inValues = inValues.ReinterpretAsInt().ShiftComponents4Minus(num_results).ReinterpretAsFloat(); 26 | ioIdentifiers = ioIdentifiers.ShiftComponents4Minus(num_results); 27 | 28 | // Store the values 29 | inValues.StoreFloat4((Float4 *)outValues); 30 | 31 | return num_results; 32 | } 33 | 34 | /// Shift the elements so that the identifiers that correspond with the trues in inValue come first 35 | /// @param inValue Values to test for true or false 36 | /// @param ioIdentifiers the identifiers that are shifted, on return they are shifted 37 | /// @return The number of trues 38 | JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers) 39 | { 40 | // Sort the hits 41 | ioIdentifiers = UVec4::sSort4True(inValue, ioIdentifiers); 42 | 43 | // Return the amount of hits 44 | return inValue.CountTrues(); 45 | } 46 | 47 | JPH_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /test_cases/include/c023_cpp_nested_structs.h: -------------------------------------------------------------------------------- 1 | class RootStruct 2 | { 3 | int value_begin; 4 | struct 5 | { 6 | float m1; 7 | } nested_struct_1a, nested_struct_1b; 8 | 9 | class NestedStruct2a 10 | { 11 | float m2; 12 | }; 13 | 14 | int value_mid; 15 | 16 | NestedStruct2a nested_struct_2b; 17 | 18 | struct NestedStruct3a 19 | { 20 | float m3; 21 | } nested_struct_3b, nested_struct_3c; 22 | 23 | // Fully anonymous 4 24 | struct 25 | { 26 | float m44; 27 | }; 28 | 29 | int value_end; 30 | }; 31 | 32 | int test_sizeof_RootStruct(); 33 | 34 | class RootUnion 35 | { 36 | int value_begin; 37 | union 38 | { 39 | int iii1; 40 | float fff1; 41 | } nested_union_1a, nested_union_1b; 42 | 43 | union NestedUnion2a 44 | { 45 | int iii2; 46 | float fff2; 47 | }; 48 | 49 | int value_mid; 50 | 51 | NestedUnion2a nested_union_2b; 52 | 53 | union NestedUnion3a 54 | { 55 | int iii3; 56 | float fff3; 57 | } nested_union_3b, nested_union_3c; 58 | 59 | // Fully anonymous 4 60 | union 61 | { 62 | int iii4; 63 | float fff4; 64 | }; 65 | int value_end; 66 | }; 67 | 68 | int test_sizeof_RootUnion(); 69 | 70 | // TODO 71 | // class RootEnum 72 | // { 73 | // int value_begin; 74 | // enum 75 | // { 76 | // AAAA, 77 | // ZZZZ 78 | // } nested_enum_1a, 79 | // nested_enum_1b; 80 | 81 | // enum NestedEnum2a 82 | // { 83 | // AAAA, 84 | // ZZZZ 85 | // }; 86 | 87 | // int value_mid; 88 | 89 | // NestedEnum2a nested_enum_2b; 90 | 91 | // enum NestedEnum3a 92 | // { 93 | // AAAA, 94 | // ZZZZ 95 | // } nested_enum_3b, 96 | // nested_enum_3c; 97 | 98 | // // Fully anonymous 4 99 | // enum 100 | // { 101 | // AAAA, 102 | // ZZZZ 103 | // }; 104 | // int value_end; 105 | // }; 106 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Core/ByteBuffer.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Underlying data type for ByteBuffer 12 | using ByteBufferVector = std::vector>; 13 | 14 | /// Simple byte buffer, aligned to a cache line 15 | class ByteBuffer : public ByteBufferVector 16 | { 17 | public: 18 | /// Align the size to a multiple of inSize, returns the length after alignment 19 | size_t Align(size_t inSize) 20 | { 21 | // Assert power of 2 22 | JPH_ASSERT(IsPowerOf2(inSize)); 23 | 24 | // Calculate new size and resize buffer 25 | size_t s = AlignUp(size(), inSize); 26 | resize(s); 27 | 28 | return s; 29 | } 30 | 31 | /// Allocate block of data of inSize elements and return the pointer 32 | template 33 | Type * Allocate(size_t inSize = 1) 34 | { 35 | // Reserve space 36 | size_t s = size(); 37 | resize(s + inSize * sizeof(Type)); 38 | 39 | // Get data pointer 40 | Type *data = reinterpret_cast(&at(s)); 41 | 42 | // Construct elements 43 | for (Type *d = data, *d_end = data + inSize; d < d_end; ++d) 44 | ::new (d) Type; 45 | 46 | // Return pointer 47 | return data; 48 | } 49 | 50 | /// Append inData to the buffer 51 | template 52 | void AppendVector(const Array &inData) 53 | { 54 | size_t size = inData.size() * sizeof(Type); 55 | uint8 *data = Allocate(size); 56 | memcpy(data, &inData[0], size); 57 | } 58 | 59 | /// Get object at inPosition (an offset in bytes) 60 | template 61 | const Type * Get(size_t inPosition) const 62 | { 63 | return reinterpret_cast(&at(inPosition)); 64 | } 65 | 66 | /// Get object at inPosition (an offset in bytes) 67 | template 68 | Type * Get(size_t inPosition) 69 | { 70 | return reinterpret_cast(&at(inPosition)); 71 | } 72 | }; 73 | 74 | JPH_NAMESPACE_END 75 | -------------------------------------------------------------------------------- /use_cases/JoltPhysics/include/Physics/Collision/PhysicsMaterial.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | class StreamIn; 15 | class StreamOut; 16 | 17 | /// This structure describes the surface of (part of) a shape. You should inherit from it to define additional 18 | /// information that is interesting for the simulation. The 2 materials involved in a contact could be used 19 | /// to decide which sound or particle effects to play. 20 | /// 21 | /// If you inherit from this material, don't forget to create a suitable default material in sDefault 22 | class PhysicsMaterial : public SerializableObject, public RefTarget 23 | { 24 | public: 25 | JPH_DECLARE_SERIALIZABLE_VIRTUAL(PhysicsMaterial) 26 | 27 | /// Virtual destructor 28 | virtual ~PhysicsMaterial() override = default; 29 | 30 | /// Default material that is used when a shape has no materials defined 31 | static RefConst sDefault; 32 | 33 | // Properties 34 | virtual const char * GetDebugName() const { return "Unknown"; } 35 | virtual Color GetDebugColor() const { return Color::sGrey; } 36 | 37 | /// Saves the contents of the material in binary form to inStream. 38 | virtual void SaveBinaryState(StreamOut &inStream) const; 39 | 40 | using PhysicsMaterialResult = Result>; 41 | 42 | /// Creates a PhysicsMaterial of the correct type and restores its contents from the binary stream inStream. 43 | static PhysicsMaterialResult sRestoreFromBinaryState(StreamIn &inStream); 44 | 45 | protected: 46 | /// This function should not be called directly, it is used by sRestoreFromBinaryState. 47 | virtual void RestoreBinaryState(StreamIn &inStream); 48 | }; 49 | 50 | using PhysicsMaterialList = Array>; 51 | 52 | JPH_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /use_cases/xatlas/xatlas_glue.cpp: -------------------------------------------------------------------------------- 1 | // auto generated by c2z 2 | #include "xatlas.h" 3 | 4 | extern "C" const uint32_t *_1_xatlas_kImageChartIndexMask_() { return &::xatlas::kImageChartIndexMask; } 5 | extern "C" const uint32_t *_1_xatlas_kImageHasChartIndexBit_() { return &::xatlas::kImageHasChartIndexBit; } 6 | extern "C" const uint32_t *_1_xatlas_kImageIsBilinearBit_() { return &::xatlas::kImageIsBilinearBit; } 7 | extern "C" const uint32_t *_1_xatlas_kImageIsPaddingBit_() { return &::xatlas::kImageIsPaddingBit; } 8 | extern "C" Atlas * _1_xatlas_Create_() { return ::xatlas::Create(); } 9 | extern "C" void _1_xatlas_Destroy_(Atlas * atlas) { ::xatlas::Destroy(atlas); } 10 | extern "C" AddMeshError _1_xatlas_AddMesh_(Atlas * atlas, const MeshDecl & meshDecl, uint32_t meshCountHint) { return ::xatlas::AddMesh(atlas, meshDecl, meshCountHint); } 11 | extern "C" void _1_xatlas_AddMeshJoin_(Atlas * atlas) { ::xatlas::AddMeshJoin(atlas); } 12 | extern "C" AddMeshError _1_xatlas_AddUvMesh_(Atlas * atlas, const UvMeshDecl & decl) { return ::xatlas::AddUvMesh(atlas, decl); } 13 | extern "C" void _1_xatlas_ComputeCharts_(Atlas * atlas, ChartOptions options) { ::xatlas::ComputeCharts(atlas, options); } 14 | extern "C" void _1_xatlas_PackCharts_(Atlas * atlas, PackOptions packOptions) { ::xatlas::PackCharts(atlas, packOptions); } 15 | extern "C" void _1_xatlas_Generate_(Atlas * atlas, ChartOptions chartOptions, PackOptions packOptions) { ::xatlas::Generate(atlas, chartOptions, packOptions); } 16 | extern "C" void _1_xatlas_SetProgressCallback_(Atlas * atlas, ProgressFunc progressFunc, void * progressUserData) { ::xatlas::SetProgressCallback(atlas, progressFunc, progressUserData); } 17 | extern "C" void _1_xatlas_SetAlloc_(ReallocFunc reallocFunc, FreeFunc freeFunc) { ::xatlas::SetAlloc(reallocFunc, freeFunc); } 18 | extern "C" void _1_xatlas_SetPrint_(PrintFunc print, bool verbose) { ::xatlas::SetPrint(print, verbose); } 19 | extern "C" const char * _1_xatlas_StringForEnum_(AddMeshError error) { return ::xatlas::StringForEnum(error); } 20 | extern "C" const char * _2_xatlas_StringForEnum_(ProgressCategory category) { return ::xatlas::StringForEnum(category); } 21 | -------------------------------------------------------------------------------- /use_cases/box2d/include/box2d.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2019 Erin Catto 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #ifndef BOX2D_H 24 | #define BOX2D_H 25 | 26 | // These include files constitute the main Box2D API 27 | 28 | #include "b2_settings.h" 29 | #include "b2_draw.h" 30 | #include "b2_timer.h" 31 | 32 | #include "b2_chain_shape.h" 33 | #include "b2_circle_shape.h" 34 | #include "b2_edge_shape.h" 35 | #include "b2_polygon_shape.h" 36 | 37 | #include "b2_broad_phase.h" 38 | #include "b2_dynamic_tree.h" 39 | 40 | #include "b2_body.h" 41 | #include "b2_contact.h" 42 | #include "b2_fixture.h" 43 | #include "b2_time_step.h" 44 | #include "b2_world.h" 45 | #include "b2_world_callbacks.h" 46 | 47 | #include "b2_distance_joint.h" 48 | #include "b2_friction_joint.h" 49 | #include "b2_gear_joint.h" 50 | #include "b2_motor_joint.h" 51 | #include "b2_mouse_joint.h" 52 | #include "b2_prismatic_joint.h" 53 | #include "b2_pulley_joint.h" 54 | #include "b2_revolute_joint.h" 55 | #include "b2_weld_joint.h" 56 | #include "b2_wheel_joint.h" 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /use_cases/imgui/include/backends/imgui_impl_allegro5.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer + Platform Backend for Allegro 5 2 | // (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy ALLEGRO_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 7 | // [X] Platform: Clipboard support (from Allegro 5.1.12) 8 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 9 | // Issues: 10 | // [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually. 11 | // [ ] Platform: Missing gamepad support. 12 | 13 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 14 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 15 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 16 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 17 | 18 | #pragma once 19 | #include "imgui.h" // IMGUI_IMPL_API 20 | 21 | struct ALLEGRO_DISPLAY; 22 | union ALLEGRO_EVENT; 23 | 24 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display); 25 | IMGUI_IMPL_API void ImGui_ImplAllegro5_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplAllegro5_NewFrame(); 27 | IMGUI_IMPL_API void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data); 28 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* event); 29 | 30 | // Use if you want to reset your rendering device without losing Dear ImGui state. 31 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects(); 32 | IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects(); 33 | --------------------------------------------------------------------------------