fix includes and include order

This commit is contained in:
Dennis Eichhorn 2024-09-21 01:34:20 +02:00
parent b150fe12f6
commit f3cd6bb31f
23 changed files with 393 additions and 242 deletions

58
asset/AssetFile.h Normal file
View File

@ -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

View File

@ -132,7 +132,7 @@ void generate_default_wav_references(const FileBody* file, Wav* wav)
wav->sample_data = wav->data + WAV_HEADER_SIZE; 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. // @performance We are generating the struct and then filling the data.
// There is some asignment/copy overhead // There is some asignment/copy overhead

View File

@ -10,7 +10,6 @@
#define TOS_CAMERA_H #define TOS_CAMERA_H
#include "../stdlib/Types.h" #include "../stdlib/Types.h"
#include "../stdlib/Mathtypes.h"
#include "../math/matrix/MatrixFloat32.h" #include "../math/matrix/MatrixFloat32.h"

View File

@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../stdlib/Mathtypes.h"
#include "../math/matrix/MatrixFloat32.h" #include "../math/matrix/MatrixFloat32.h"
void make_character( void make_character(

View File

@ -10,7 +10,6 @@
#define TOS_GPUAPI_OPENGL_UI_H #define TOS_GPUAPI_OPENGL_UI_H
#include "../../stdlib/Types.h" #include "../../stdlib/Types.h"
#include "../../stdlib/Mathtypes.h"
#include "../../ui/UIButton.h" #include "../../ui/UIButton.h"
#include "../../ui/UIWindow.h" #include "../../ui/UIWindow.h"

View File

@ -10,7 +10,6 @@
#define TOS_MATH_MATRIX_FLOAT32_H #define TOS_MATH_MATRIX_FLOAT32_H
#include "../../stdlib/Intrinsics.h" #include "../../stdlib/Intrinsics.h"
#include "../../stdlib/Mathtypes.h"
#include "../../utils/MathUtils.h" #include "../../utils/MathUtils.h"
#include "../../utils/TestUtils.h" #include "../../utils/TestUtils.h"
#include <math.h> #include <math.h>

View File

@ -11,7 +11,6 @@
#define TOS_MATH_MATRIX_QUATERNION_FLOAT32_H #define TOS_MATH_MATRIX_QUATERNION_FLOAT32_H
#include "../../stdlib/Intrinsics.h" #include "../../stdlib/Intrinsics.h"
#include "../../stdlib/Mathtypes.h"
#include "../../utils/MathUtils.h" #include "../../utils/MathUtils.h"
#include "../../utils/TestUtils.h" #include "../../utils/TestUtils.h"

View File

@ -14,15 +14,19 @@
#include "../utils/MathUtils.h" #include "../utils/MathUtils.h"
#include "../utils/TestUtils.h" #include "../utils/TestUtils.h"
#include "Allocation.h" #include "Allocation.h"
#include "DebugMemory.h"
struct BufferMemory { struct BufferMemory {
byte* memory; byte* memory;
uint32 id;
uint64 size; uint64 size;
uint64 pos; uint64 pos;
int alignment; int alignment;
}; };
// @todo implement memory usage visualization
inline inline
void buffer_alloc(BufferMemory* buf, uint64 size, int alignment = 1) 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) // @bug arent we wasting element 0 (see get_memory, we are not using 0 only next element)
buf->pos = 0; buf->pos = 0;
DEBUG_MEMORY_RESET(&debug_memory[buf->id]);
} }
inline inline
@ -69,6 +74,8 @@ byte* buffer_get_memory(BufferMemory* buf, uint64 size, int aligned = 1, bool ze
memset((void *) offset, 0, size); memset((void *) offset, 0, size);
} }
DEBUG_MEMORY(&debug_memory[buf->id], buf->pos, size);
buf->pos += size; buf->pos += size;
return offset; return offset;

View File

@ -13,10 +13,12 @@
#include "../stdlib/Types.h" #include "../stdlib/Types.h"
#include "../utils/MathUtils.h" #include "../utils/MathUtils.h"
#include "Allocation.h" #include "Allocation.h"
#include "DebugMemory.h"
struct ChunkMemory { struct ChunkMemory {
byte* memory; byte* memory;
uint32 id;
uint64 count; uint64 count;
uint64 chunk_size; uint64 chunk_size;
int64 last_pos; int64 last_pos;
@ -27,6 +29,8 @@ struct ChunkMemory {
uint64* free; uint64* free;
}; };
// @todo implement memory usage visualization
inline inline
void chunk_alloc(ChunkMemory* buf, uint64 count, uint64 chunk_size, int alignment = 1) 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); 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; 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); 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; buf->last_pos = free_element;
return free_element; return free_element;

79
memory/DebugMemory.h Normal file
View File

@ -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 <string.h>
#include <malloc.h>
#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

View File

@ -15,10 +15,12 @@
#include "../utils/TestUtils.h" #include "../utils/TestUtils.h"
#include "Allocation.h" #include "Allocation.h"
#include "BufferMemory.h" #include "BufferMemory.h"
#include "DebugMemory.h"
struct RingMemory { struct RingMemory {
byte* memory; byte* memory;
uint32 id;
uint64 size; uint64 size;
uint64 pos; uint64 pos;
int alignment; int alignment;
@ -35,6 +37,8 @@ struct RingMemory {
uint64 end; uint64 end;
}; };
// @todo implement memory usage visualization
inline inline
void ring_alloc(RingMemory* ring, uint64 size, int alignment = 1) 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); memset((void *) offset, 0, size);
} }
DEBUG_MEMORY(&debug_memory[ring->id], ring->pos, size);
ring->pos += size; ring->pos += size;
return offset; return offset;
@ -142,6 +148,7 @@ inline
void ring_reset(RingMemory* ring) void ring_reset(RingMemory* ring)
{ {
ring->pos = 0; ring->pos = 0;
DEBUG_MEMORY_RESET(&debug_memory[ring->id]);
} }
/** /**

View File

@ -9,7 +9,7 @@
#ifndef TOS_MODELS_LOCATION_H #ifndef TOS_MODELS_LOCATION_H
#define TOS_MODELS_LOCATION_H #define TOS_MODELS_LOCATION_H
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
struct Location { struct Location {
v3_f32 position; v3_f32 position;

View File

@ -13,7 +13,9 @@
#include "../chat/ChatStatus.h" #include "../chat/ChatStatus.h"
#include "setting_types.h" #include "setting_types.h"
#if __linux__ #if _WIN32
#include <windows.h>
#else __linux__
#include <linux/limits.h> #include <linux/limits.h>
#define MAX_PATH PATH_MAX #define MAX_PATH PATH_MAX
#endif #endif

View File

@ -12,8 +12,16 @@
#if _WIN32 #if _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#define close closesocket
#define sleep Sleep inline
int close(SOCKET sock) {
return closesocket(sock);
}
inline
void sleep(unsigned long time) {
Sleep(time);
}
#endif #endif
#endif #endif

View File

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
#define WORLEY_FEATURE_POINTS 4 #define WORLEY_FEATURE_POINTS 4

View File

@ -10,7 +10,7 @@
#ifndef TOS_PARTICLE_H #ifndef TOS_PARTICLE_H
#define TOS_PARTICLE_H #define TOS_PARTICLE_H
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
struct Particle { struct Particle {
v3_f32 position; v3_f32 position;

View File

@ -13,7 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
#include "../utils/MathUtils.h" #include "../utils/MathUtils.h"
#include "../memory/RingMemory.h" #include "../memory/RingMemory.h"

View File

@ -13,7 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
#include "../memory/RingMemory.h" #include "../memory/RingMemory.h"
// Manhattan distance for 3D // Manhattan distance for 3D

View File

@ -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

View File

@ -43,6 +43,217 @@ typedef intptr_t smm;
#define local_persist static #define local_persist static
#define global_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_SIGN_MASK 0x8000
#define HALF_FLOAT_EXP_MASK 0x7C00 #define HALF_FLOAT_EXP_MASK 0x7C00
#define HALF_FLOAT_FRAC_MASK 0x03FF #define HALF_FLOAT_FRAC_MASK 0x03FF

View File

@ -1,7 +1,7 @@
#ifndef TOS_UI_LAYOUT_H #ifndef TOS_UI_LAYOUT_H
#define TOS_UI_LAYOUT_H #define TOS_UI_LAYOUT_H
#include "../stdlib/Mathtypes.h" #include "../stdlib/Types.h"
#include "UIPosition.h" #include "UIPosition.h"
#include "UILocation.h" #include "UILocation.h"

View File

@ -10,6 +10,7 @@
#define TOS_UTILS_TEST_UTILS_H #define TOS_UTILS_TEST_UTILS_H
#include <time.h> #include <time.h>
#include <stdio.h>
#include "../stdlib/Types.h" #include "../stdlib/Types.h"
#if _WIN32 #if _WIN32

View File

@ -9,6 +9,8 @@
#ifndef TOS_UTILS_H #ifndef TOS_UTILS_H
#define TOS_UTILS_H #define TOS_UTILS_H
#include <stdlib.h>
#include "../stdlib/Types.h" #include "../stdlib/Types.h"
#define ARRAY_COUNT(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_COUNT(a) (sizeof(a) / sizeof((a)[0]))