diff --git a/asset/AssetFile.h b/asset/AssetFile.h new file mode 100644 index 0000000..dc20aa1 --- /dev/null +++ b/asset/AssetFile.h @@ -0,0 +1,58 @@ +/** + * Jingga + * + * @copyright Jingga + * @license License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef TOS_ASSET_FILE_H +#define TOS_ASSET_FILE_H + +#include "../stdlib/Types.h" + +enum AssetType { + ASSET_TYPE_RAW_IMG, + ASSET_TYPE_PNG, + + ASSET_TYPE_RAW_SOUND, + ASSET_TYPE_WAV, + + ASSET_TYPE_OBJBIN, + ASSET_TYPE_MATBIN, + ASSET_TYPE_ANIBIN, + + ASSET_TYPE_RAW_TEXTURE, // may include bump map, normal map, ... +}; + +struct AssetFileTableOfContent { + uint32 asset_id; + AssetType asset_type; + uint64 asset_offset; +}; + +struct AssetFileHeader { + uint32 version; + uint32 asset_count; + AssetFileTableOfContent* table_of_content; +}; + +struct AssetFile { + AssetFileHeader header; + byte* data; +}; + +void asset_file_load_header(void* fp, AssetFileHeader* header) {} + +void asset_file_write_header() {} + +// add asset at end (automatically) or in pos +void asset_file_add_asset(void* fp, AssetFile* asset_file, byte* asset, int64 pos = -1) {} + +// remove asset by id or pos +void asset_file_remove_asset(void* fp, AssetFile* asset_file, int64 id, int64 pos = -1) {} + +// load the toc info of an asset by id or pos +AssetFileTableOfContent* asset_file_load_asset_toc(AssetFileHeader* header, int64 id, int64 pos = -1) {} + +#endif \ No newline at end of file diff --git a/audio/Wav.h b/audio/Wav.h index d26889d..032943d 100644 --- a/audio/Wav.h +++ b/audio/Wav.h @@ -132,7 +132,7 @@ void generate_default_wav_references(const FileBody* file, Wav* wav) wav->sample_data = wav->data + WAV_HEADER_SIZE; } -void generate_wav_image(const FileBody* src_data, Audio* audio) +void generate_wav_audio(const FileBody* src_data, Audio* audio) { // @performance We are generating the struct and then filling the data. // There is some asignment/copy overhead diff --git a/camera/Camera.h b/camera/Camera.h index 38f59c1..627b3d5 100644 --- a/camera/Camera.h +++ b/camera/Camera.h @@ -10,7 +10,6 @@ #define TOS_CAMERA_H #include "../stdlib/Types.h" -#include "../stdlib/Mathtypes.h" #include "../math/matrix/MatrixFloat32.h" diff --git a/gpuapi/RenderUtils.h b/gpuapi/RenderUtils.h index 059a3d2..c45288e 100644 --- a/gpuapi/RenderUtils.h +++ b/gpuapi/RenderUtils.h @@ -11,7 +11,6 @@ #include #include -#include "../stdlib/Mathtypes.h" #include "../math/matrix/MatrixFloat32.h" void make_character( diff --git a/gpuapi/opengl/UIOpengl.h b/gpuapi/opengl/UIOpengl.h index 1391790..5de2850 100644 --- a/gpuapi/opengl/UIOpengl.h +++ b/gpuapi/opengl/UIOpengl.h @@ -10,7 +10,6 @@ #define TOS_GPUAPI_OPENGL_UI_H #include "../../stdlib/Types.h" -#include "../../stdlib/Mathtypes.h" #include "../../ui/UIButton.h" #include "../../ui/UIWindow.h" diff --git a/math/matrix/MatrixFloat32.h b/math/matrix/MatrixFloat32.h index 75f014c..7dd5641 100644 --- a/math/matrix/MatrixFloat32.h +++ b/math/matrix/MatrixFloat32.h @@ -10,7 +10,6 @@ #define TOS_MATH_MATRIX_FLOAT32_H #include "../../stdlib/Intrinsics.h" -#include "../../stdlib/Mathtypes.h" #include "../../utils/MathUtils.h" #include "../../utils/TestUtils.h" #include diff --git a/math/matrix/QuaternionFloat32.h b/math/matrix/QuaternionFloat32.h index 70e5004..9913bcf 100644 --- a/math/matrix/QuaternionFloat32.h +++ b/math/matrix/QuaternionFloat32.h @@ -11,7 +11,6 @@ #define TOS_MATH_MATRIX_QUATERNION_FLOAT32_H #include "../../stdlib/Intrinsics.h" -#include "../../stdlib/Mathtypes.h" #include "../../utils/MathUtils.h" #include "../../utils/TestUtils.h" diff --git a/memory/BufferMemory.h b/memory/BufferMemory.h index 9751024..0a47415 100644 --- a/memory/BufferMemory.h +++ b/memory/BufferMemory.h @@ -14,15 +14,19 @@ #include "../utils/MathUtils.h" #include "../utils/TestUtils.h" #include "Allocation.h" +#include "DebugMemory.h" struct BufferMemory { byte* memory; + uint32 id; uint64 size; uint64 pos; int alignment; }; +// @todo implement memory usage visualization + inline void buffer_alloc(BufferMemory* buf, uint64 size, int alignment = 1) { @@ -49,6 +53,7 @@ void buffer_reset(BufferMemory* buf) { // @bug arent we wasting element 0 (see get_memory, we are not using 0 only next element) buf->pos = 0; + DEBUG_MEMORY_RESET(&debug_memory[buf->id]); } inline @@ -69,6 +74,8 @@ byte* buffer_get_memory(BufferMemory* buf, uint64 size, int aligned = 1, bool ze memset((void *) offset, 0, size); } + DEBUG_MEMORY(&debug_memory[buf->id], buf->pos, size); + buf->pos += size; return offset; diff --git a/memory/ChunkMemory.h b/memory/ChunkMemory.h index 29becf3..17c72ae 100644 --- a/memory/ChunkMemory.h +++ b/memory/ChunkMemory.h @@ -13,10 +13,12 @@ #include "../stdlib/Types.h" #include "../utils/MathUtils.h" #include "Allocation.h" +#include "DebugMemory.h" struct ChunkMemory { byte* memory; + uint32 id; uint64 count; uint64 chunk_size; int64 last_pos; @@ -27,6 +29,8 @@ struct ChunkMemory { uint64* free; }; +// @todo implement memory usage visualization + inline void chunk_alloc(ChunkMemory* buf, uint64 count, uint64 chunk_size, int alignment = 1) { @@ -82,6 +86,8 @@ void chunk_reserve_index(ChunkMemory* buf, int64 index, int64 elements = 1, bool memset(buf->memory + index * buf->chunk_size, 0, elements * buf->chunk_size); } + DEBUG_MEMORY(&debug_memory[buf->id], index * buf->chunk_size, elements * buf->chunk_size); + buf->last_pos = index; } @@ -156,6 +162,8 @@ int64 chunk_reserve(ChunkMemory* buf, uint64 elements = 1, bool zeroed = false) memset(buf->memory + free_element * buf->chunk_size, 0, elements * buf->chunk_size); } + DEBUG_MEMORY(&debug_memory[buf->id], free_element * buf->chunk_size, elements * buf->chunk_size); + buf->last_pos = free_element; return free_element; diff --git a/memory/DebugMemory.h b/memory/DebugMemory.h new file mode 100644 index 0000000..b09ac23 --- /dev/null +++ b/memory/DebugMemory.h @@ -0,0 +1,79 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef TOS_MEMORY_DEBUG_H +#define TOS_MEMORY_DEBUG_H + +#include +#include + +#include "../stdlib/Types.h" + +struct DebugMemoryRange { + uint64 start; + uint64 end; +}; + +struct DebugMemory { + uint64 size; + uint64 usage; + + uint64 debug_range_size; + uint64 debug_range_idx; + DebugMemoryRange* debug_ranges; +}; + +#if DEBUG + #define DEBUG_MEMORY(mem, start, end) debug_memory_add_range((mem), (start), (end)) + #define DEBUG_MEMORY_RESET(mem) debug_memory_reset((mem)) + #define DEBUG_MEMORY_FREE(mem, start, end) debug_memory_add_range((mem), (start), (end)) +#else + #define DEBUG_MEMORY(mem, start, end) ((void)0) + #define DEBUG_MEMORY_RESET(mem) ((void)0) + #define DEBUG_MEMORY_FREE(mem, start, end) ((void)0) +#endif + +void debug_memory_resize(DebugMemory* mem) +{ + DebugMemoryRange* old = mem->debug_ranges; + + mem->debug_range_size += 100; + mem->debug_ranges = (DebugMemoryRange *) malloc(mem->debug_range_size * sizeof(DebugMemoryRange)); + + if (old) { + memcpy(mem->debug_ranges, old, mem->debug_range_size - 100); + free(old); + } +} + +void debug_memory_add_range(DebugMemory* mem, uint64 start, uint64 end) +{ + if (mem->debug_range_idx >= mem->debug_range_size) { + debug_memory_resize(mem); + } + + mem->debug_ranges[mem->debug_range_idx].start = start; + mem->debug_ranges[mem->debug_range_idx].end = end; + + ++mem->debug_range_idx; +} + +inline +void debug_memory_reset(DebugMemory* mem) +{ + mem->usage = 0; + mem->debug_range_idx = 0; +} + +inline +void debug_memory_free(DebugMemory* mem) +{ + free(mem->debug_ranges); +} + +#endif \ No newline at end of file diff --git a/memory/RingMemory.h b/memory/RingMemory.h index 6a9f395..36cb9bb 100644 --- a/memory/RingMemory.h +++ b/memory/RingMemory.h @@ -15,10 +15,12 @@ #include "../utils/TestUtils.h" #include "Allocation.h" #include "BufferMemory.h" +#include "DebugMemory.h" struct RingMemory { byte* memory; + uint32 id; uint64 size; uint64 pos; int alignment; @@ -35,6 +37,8 @@ struct RingMemory { uint64 end; }; +// @todo implement memory usage visualization + inline void ring_alloc(RingMemory* ring, uint64 size, int alignment = 1) { @@ -124,6 +128,8 @@ byte* ring_get_memory(RingMemory* ring, uint64 size, byte aligned = 1, bool zero memset((void *) offset, 0, size); } + DEBUG_MEMORY(&debug_memory[ring->id], ring->pos, size); + ring->pos += size; return offset; @@ -142,6 +148,7 @@ inline void ring_reset(RingMemory* ring) { ring->pos = 0; + DEBUG_MEMORY_RESET(&debug_memory[ring->id]); } /** diff --git a/models/Location.h b/models/Location.h index 041abdc..567a280 100644 --- a/models/Location.h +++ b/models/Location.h @@ -9,7 +9,7 @@ #ifndef TOS_MODELS_LOCATION_H #define TOS_MODELS_LOCATION_H -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" struct Location { v3_f32 position; diff --git a/models/settings/Settings.h b/models/settings/Settings.h index f681cae..7a2d1a5 100644 --- a/models/settings/Settings.h +++ b/models/settings/Settings.h @@ -13,7 +13,9 @@ #include "../chat/ChatStatus.h" #include "setting_types.h" -#if __linux__ +#if _WIN32 + #include +#else __linux__ #include #define MAX_PATH PATH_MAX #endif diff --git a/network/NetworkOSWrapper.h b/network/NetworkOSWrapper.h index d409409..05e9352 100644 --- a/network/NetworkOSWrapper.h +++ b/network/NetworkOSWrapper.h @@ -12,8 +12,16 @@ #if _WIN32 #include #include - #define close closesocket - #define sleep Sleep + + inline + int close(SOCKET sock) { + return closesocket(sock); + } + + inline + void sleep(unsigned long time) { + Sleep(time); + } #endif #endif \ No newline at end of file diff --git a/noise/WorleyNoise.h b/noise/WorleyNoise.h index a75bd0b..cca885f 100644 --- a/noise/WorleyNoise.h +++ b/noise/WorleyNoise.h @@ -12,7 +12,7 @@ #include #include -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" #define WORLEY_FEATURE_POINTS 4 diff --git a/particle/Particle.h b/particle/Particle.h index 4c7bd59..914cc69 100644 --- a/particle/Particle.h +++ b/particle/Particle.h @@ -10,7 +10,7 @@ #ifndef TOS_PARTICLE_H #define TOS_PARTICLE_H -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" struct Particle { v3_f32 position; diff --git a/pathfinding/Metric2d.h b/pathfinding/Metric2d.h index 324f8bb..4cf77dd 100644 --- a/pathfinding/Metric2d.h +++ b/pathfinding/Metric2d.h @@ -13,7 +13,7 @@ #include #include -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" #include "../utils/MathUtils.h" #include "../memory/RingMemory.h" diff --git a/pathfinding/Metric3d.h b/pathfinding/Metric3d.h index c45b2f5..b1754e3 100644 --- a/pathfinding/Metric3d.h +++ b/pathfinding/Metric3d.h @@ -13,7 +13,7 @@ #include #include -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" #include "../memory/RingMemory.h" // Manhattan distance for 3D diff --git a/stdlib/Mathtypes.h b/stdlib/Mathtypes.h deleted file mode 100644 index 9feca27..0000000 --- a/stdlib/Mathtypes.h +++ /dev/null @@ -1,227 +0,0 @@ -/** - * Jingga - * - * @copyright Jingga - * @license OMS License 2.0 - * @version 1.0.0 - * @link https://jingga.app - */ -#ifndef TOS_STDLIB_MATHTYPES_H -#define TOS_STDLIB_MATHTYPES_H - -#include "Types.h" - -// @todo Move to matrix - -struct v2_int32 { - union { - struct { - int32 x; - int32 y; - }; - - struct { - int32 width; - int32 height; - }; - - int32 v[2]; - }; -}; - -struct v3_int32 { - union { - struct { - union { - int32 x; - int32 r; - }; - union { - int32 y; - int32 g; - }; - union { - int32 z; - int32 b; - }; - }; - - int32 v[3]; - }; -}; - -struct v4_int32 { - union { - struct { - int32 x; - int32 y; - int32 z; - int32 w; - }; - - int32 v[4]; - }; -}; - -struct v2_int64 { - union { - struct { - int64 x; - int64 y; - }; - - int64 v[2]; - }; -}; - -struct v3_int64 { - union { - struct { - union { - int64 x; - int64 r; - }; - union { - int64 y; - int64 g; - }; - union { - int64 z; - int64 b; - }; - }; - - int64 v[3]; - }; -}; - -struct v4_int64 { - union { - struct { - int64 x; - int64 y; - int64 z; - int64 w; - }; - - int64 v[4]; - }; -}; - -struct v2_f32 { - union { - struct { - f32 x; - f32 y; - }; - - f32 v[2]; - }; -}; - -struct v3_f32 { - union { - struct { - union { - f32 x; - f32 r; - f32 pitch; - f32 u; - }; - union { - f32 y; - f32 g; - f32 yaw; - f32 v; - }; - union { - f32 z; - f32 b; - f32 roll; - f32 w; - }; - }; - - f32 vec[3]; - }; -}; - -struct v4_f32 { - union { - struct { - f32 x; - f32 y; - f32 z; - f32 w; - }; - - f32 vec[4]; - }; -}; - -struct v2_f64 { - union { - struct { - f64 x; - f64 y; - }; - - f64 v[2]; - }; -}; - -struct v3_f64 { - union { - struct { - union { - f64 x; - f64 r; - }; - union { - f64 y; - f64 g; - }; - union { - f64 z; - f64 b; - }; - }; - - f64 v[3]; - }; -}; - -struct v4_f64 { - union { - struct { - f64 x; - f64 y; - f64 z; - f64 w; - }; - - f64 v[4]; - }; -}; - -struct m_int32 { - int32 *e; - size_t m, n; -}; - -struct m_int64 { - int64 *e; - size_t m, n; -}; - -struct m_f32 { - f32 *e; - size_t m, n; -}; - -struct m_f64 { - f64 *e; - size_t m, n; -}; - -#endif \ No newline at end of file diff --git a/stdlib/Types.h b/stdlib/Types.h index 9c6fc37..4b083f8 100644 --- a/stdlib/Types.h +++ b/stdlib/Types.h @@ -43,6 +43,217 @@ typedef intptr_t smm; #define local_persist static #define global_persist static +struct v2_int32 { + union { + struct { + int32 x; + int32 y; + }; + + struct { + int32 width; + int32 height; + }; + + int32 v[2]; + }; +}; + +struct v3_int32 { + union { + struct { + union { + int32 x; + int32 r; + }; + union { + int32 y; + int32 g; + }; + union { + int32 z; + int32 b; + }; + }; + + int32 v[3]; + }; +}; + +struct v4_int32 { + union { + struct { + int32 x; + int32 y; + int32 z; + int32 w; + }; + + int32 v[4]; + }; +}; + +struct v2_int64 { + union { + struct { + int64 x; + int64 y; + }; + + int64 v[2]; + }; +}; + +struct v3_int64 { + union { + struct { + union { + int64 x; + int64 r; + }; + union { + int64 y; + int64 g; + }; + union { + int64 z; + int64 b; + }; + }; + + int64 v[3]; + }; +}; + +struct v4_int64 { + union { + struct { + int64 x; + int64 y; + int64 z; + int64 w; + }; + + int64 v[4]; + }; +}; + +struct v2_f32 { + union { + struct { + f32 x; + f32 y; + }; + + f32 v[2]; + }; +}; + +struct v3_f32 { + union { + struct { + union { + f32 x; + f32 r; + f32 pitch; + f32 u; + }; + union { + f32 y; + f32 g; + f32 yaw; + f32 v; + }; + union { + f32 z; + f32 b; + f32 roll; + f32 w; + }; + }; + + f32 vec[3]; + }; +}; + +struct v4_f32 { + union { + struct { + f32 x; + f32 y; + f32 z; + f32 w; + }; + + f32 vec[4]; + }; +}; + +struct v2_f64 { + union { + struct { + f64 x; + f64 y; + }; + + f64 v[2]; + }; +}; + +struct v3_f64 { + union { + struct { + union { + f64 x; + f64 r; + }; + union { + f64 y; + f64 g; + }; + union { + f64 z; + f64 b; + }; + }; + + f64 v[3]; + }; +}; + +struct v4_f64 { + union { + struct { + f64 x; + f64 y; + f64 z; + f64 w; + }; + + f64 v[4]; + }; +}; + +struct m_int32 { + int32 *e; + size_t m, n; +}; + +struct m_int64 { + int64 *e; + size_t m, n; +}; + +struct m_f32 { + f32 *e; + size_t m, n; +}; + +struct m_f64 { + f64 *e; + size_t m, n; +}; + #define HALF_FLOAT_SIGN_MASK 0x8000 #define HALF_FLOAT_EXP_MASK 0x7C00 #define HALF_FLOAT_FRAC_MASK 0x03FF diff --git a/ui/UILayout.h b/ui/UILayout.h index 74150f0..4cad065 100644 --- a/ui/UILayout.h +++ b/ui/UILayout.h @@ -1,7 +1,7 @@ #ifndef TOS_UI_LAYOUT_H #define TOS_UI_LAYOUT_H -#include "../stdlib/Mathtypes.h" +#include "../stdlib/Types.h" #include "UIPosition.h" #include "UILocation.h" diff --git a/utils/TestUtils.h b/utils/TestUtils.h index df12fa6..0aaa7f6 100644 --- a/utils/TestUtils.h +++ b/utils/TestUtils.h @@ -10,6 +10,7 @@ #define TOS_UTILS_TEST_UTILS_H #include +#include #include "../stdlib/Types.h" #if _WIN32 diff --git a/utils/Utils.h b/utils/Utils.h index ff9722a..0b3e4d9 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -9,6 +9,8 @@ #ifndef TOS_UTILS_H #define TOS_UTILS_H +#include + #include "../stdlib/Types.h" #define ARRAY_COUNT(a) (sizeof(a) / sizeof((a)[0]))