meta layer progress

This commit is contained in:
jacob 2025-08-23 18:32:27 -05:00
parent 014b8e84c3
commit b42299688d
70 changed files with 1727 additions and 799 deletions

View File

@ -2,6 +2,7 @@
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
cd /D "%~dp0" cd /D "%~dp0"
if not exist build mkdir build if not exist build mkdir build
pushd build
:::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::
::~ Unpack args ::~ Unpack args
@ -31,8 +32,7 @@ if "%debug%" == "1" echo [Debug]
if "%meta%" == "1" ( if "%meta%" == "1" (
echo [Building meta] echo [Building meta]
:: cl.exe /Fe"build/" /Fo"build/" /c src\\meta\\meta.c /link build/meta.obj "cl" ../src/meta/meta.c /Od /Z7 /nologo /link /DEBUG:FULL /INCREMENTAL:NO
"cl" /Zi /DEBUG src/meta/meta.c /Fo:build/meta.obj /Fe:build/meta.exe /nologo
if not "!errorlevel!" == "0" ( if not "!errorlevel!" == "0" (
echo . echo .
@ -47,7 +47,7 @@ if "%meta%" == "1" (
if "%pp%" == "1" ( if "%pp%" == "1" (
echo [Building power play] echo [Building power play]
"build/meta.exe" pp "meta.exe" pp
if not "!errorlevel!" == "0" ( if not "!errorlevel!" == "0" (
echo. echo.

View File

@ -1,8 +1,6 @@
@Layer app @Layer app
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep ttf @Dep ttf
@ -20,7 +18,8 @@
@Dep playback @Dep playback
@Dep pp @Dep pp
//////////////////////////////// //- Api
//~ Api @IncludeC app_core.h
@ApiC app_core //- Impl
@IncludeC app_core.c

View File

@ -1,12 +1,11 @@
@Layer ase @Layer ase
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep bitbuff @Dep bitbuff
//////////////////////////////// //- Api
//~ Api @IncludeC ase_core.h
@ApiC ase_core //- Impl
@IncludeC ase_core.c

View File

@ -1,17 +1,14 @@
@Layer asset_cache @Layer asset_cache
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
//////////////////////////////// //- Api
//~ Api @IncludeC asset_cache_core.h
@ApiC asset_cache_core //- Impl
@IncludeC asset_cache_core.c
//////////////////////////////// //- Startup
//~ Init @Startup AC_StartupCore
@Init AC_StartupCore

View File

@ -1,33 +1,42 @@
@Layer base @Layer base
//////////////////////////////// @Dep mp3
//~ Api
@ApiC base_core //- Api
@ApiC base_intrinsics @IncludeC base_core.h
@ApiC base_memory @IncludeC base_intrinsics.h
@ApiC base_arena @IncludeC base_memory.h
@ApiC base_snc @IncludeC base_arena.h
@ApiC base_job @IncludeC base_snc.h
@ApiC base_uid @IncludeC base_job.h
@ApiC base_string @IncludeC base_uid.h
@ApiC base_uni @IncludeC base_string.h
@ApiC base_gstat @IncludeC base_uni.h
@ApiC base_buddy @IncludeC base_gstat.h
@ApiC base_math @IncludeC base_buddy.h
@ApiC base_rand @IncludeC base_math.h
@ApiC base_util @IncludeC base_rand.h
@ApiC base_incbin @IncludeC base_util.h
@ApiC base_entry @IncludeC base_incbin.h
@IncludeC base_entry.h
@IncludeGpu base_core.h
@IncludeGpu base_math_gpu.h
@ApiGpu base_core //- Impl
@ApiGpu base_math_gpu @IncludeC base_memory.c
@IncludeC base_arena.c
@IncludeC base_snc.c
@IncludeC base_uid.c
@IncludeC base_string.c
@IncludeC base_uni.c
@IncludeC base_gstat.c
@IncludeC base_buddy.c
@IncludeC base_math.c
@IncludeC base_rand.c
@IncludeC base_incbin.c
//- Win32 //- Win32 impl
@ApiCWindows win32/base_win32_job @DefaultWindowsImpl base_win32
@ApiCWindows win32/base_win32_entry
//////////////////////////////// //- Startup
//~ Init @Startup StartupBaseJobs
@Init StartupBaseJobs

View File

@ -236,9 +236,9 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//- Fallthrough //- Fallthrough
#if CompilerIsClang #if CompilerIsClang
# define FALLTHROUGH
#else
# define FALLTHROUGH __attribute((fallthrough)) # define FALLTHROUGH __attribute((fallthrough))
#else
# define FALLTHROUGH
#endif #endif
//- Preprocessor concatenation //- Preprocessor concatenation
@ -263,7 +263,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//~ Type helper macros //~ Type helper macros
//- alignof //- alignof
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && (__STDC_VERSION__ < 202311L)) #if LanguageIsC && (CompilerIsMsvc || __STDC_VERSION__ < 202311L)
# define alignof(type) __alignof(type) # define alignof(type) __alignof(type)
#endif #endif

View File

@ -1376,7 +1376,7 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt)
Mat4x4 Mat4x4FromXform(Xform xf) Mat4x4 Mat4x4FromXform(Xform xf)
{ {
return CppCompatInitListType(Mat4x4) return (Mat4x4)
{ {
.e = { .e = {
{xf.bx.x, xf.bx.y, 0, 0}, {xf.bx.x, xf.bx.y, 0, 0},

View File

@ -10,7 +10,7 @@
Struct(Vec2) { Struct(Vec2) {
f32 x, y; f32 x, y;
}; };
#define VEC2(x, y) CppCompatInitListType(Vec2) { (x), (y) } #define VEC2(x, y) (Vec2) { (x), (y) }
Struct(Vec2Array) { Struct(Vec2Array) {
Vec2 *points; Vec2 *points;
@ -23,7 +23,7 @@ Struct(Vec2Array) {
Struct(Vec3) { Struct(Vec3) {
f32 x, y, z; f32 x, y, z;
}; };
#define VEC3(x, y, z) CppCompatInitListType(Vec3) { (x), (y), (z) } #define VEC3(x, y, z) (Vec3) { (x), (y), (z) }
Struct(Vec3Array) { Struct(Vec3Array) {
Vec3 *points; Vec3 *points;
@ -49,7 +49,7 @@ Struct(Vec4Array) {
Struct(Vec2I32) { Struct(Vec2I32) {
i32 x, y; i32 x, y;
}; };
#define VEC2I32(x, y) CppCompatInitListType(Vec2I32) { (x), (y) } #define VEC2I32(x, y) (Vec2I32) { (x), (y) }
//////////////////////////////// ////////////////////////////////
//~ Integer vector3 types //~ Integer vector3 types
@ -57,7 +57,7 @@ Struct(Vec2I32) {
Struct(Vec3I32) { Struct(Vec3I32) {
i32 x, y, z; i32 x, y, z;
}; };
#define VEC3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) } #define VEC3I32(x, y, z) (Vec3I32) { (x), (y), (z) }
//////////////////////////////// ////////////////////////////////
//~ Integer vector4 types //~ Integer vector4 types
@ -66,7 +66,7 @@ Struct(Vec4I32)
{ {
i32 x, y, z, w; i32 x, y, z, w;
}; };
#define VEC4I32(x, y, z, w) CppCompatInitListType(Vec4I32) { (x), (y), (z), (w) } #define VEC4I32(x, y, z, w) (Vec4I32) { (x), (y), (z), (w) }
//////////////////////////////// ////////////////////////////////
//~ Xform types //~ Xform types
@ -90,7 +90,8 @@ Struct(Trs)
//~ Rect types //~ Rect types
Struct(Rect) { Struct(Rect) {
union { union
{
struct { f32 x, y, width, height; }; struct { f32 x, y, width, height; };
struct { Vec2 pos, size; }; struct { Vec2 pos, size; };
}; };
@ -114,7 +115,8 @@ Struct(Aabb) {
//~ Quad types //~ Quad types
Struct(Quad) { Struct(Quad) {
union { union
{
struct { Vec2 p0, p1, p2, p3; }; struct { Vec2 p0, p1, p2, p3; };
struct { Vec2 e[4]; }; struct { Vec2 e[4]; };
}; };
@ -329,7 +331,7 @@ Vec2I32 SubVec2I32(Vec2I32 a, Vec2I32 b);
b32 EqXform(Xform xf1, Xform xf2); b32 EqXform(Xform xf1, Xform xf2);
//- Initialization //- Initialization
#define XformIdentity CppCompatInitListType(Xform) { .bx = VEC2(1, 0), .by = VEC2(0, 1) } #define XformIdentity (Xform) { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
#define XformIdentityNoCast { .bx = VEC2(1, 0), .by = VEC2(0, 1) } #define XformIdentityNoCast { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
Xform XformFromPos(Vec2 v); Xform XformFromPos(Vec2 v);
Xform XformFromRot(f32 r); Xform XformFromRot(f32 r);

View File

@ -1,30 +1,3 @@
////////////////////////////////
//~ String types
Struct(String)
{
u64 len;
u8 *text;
};
Struct(String16)
{
u64 len;
u16 *text;
};
Struct(String32)
{
u64 len;
u32 *text;
};
Struct(StringArray)
{
u64 count;
String *strings;
};
//////////////////////////////// ////////////////////////////////
//~ Formatting types //~ Formatting types
@ -85,8 +58,8 @@ Struct(CodepointIter)
//////////////////////////////// ////////////////////////////////
//~ String utils //~ String utils
#define StringFromPointers(p0, p1) (CppCompatInitListType(String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 }) #define StringFromPointers(p0, p1) ((String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
#define StringFromStruct(ptr) (CppCompatInitListType(String) { sizeof(*(ptr)), (u8 *)(ptr) }) #define StringFromStruct(ptr) ((String) { sizeof(*(ptr)), (u8 *)(ptr) })
#define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena))) #define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena)))
/* String from static array */ /* String from static array */

View File

@ -1,11 +1,10 @@
@Layer bitbuff @Layer bitbuff
//////////////////////////////// //- Dependencies
//~ Dependencies @Dep base
@dep base //- Api
@IncludeC bitbuff_core.h
//////////////////////////////// //- Impl
//~ Api @IncludeC bitbuff_core.c
@ApiC bitbuff_core

View File

@ -1,11 +1,10 @@
@Layer collider @Layer collider
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC collider_core.h
@ApiC collider_core //- Impl
@IncludeC collider_core.c

View File

@ -1,20 +1,17 @@
@Layer draw @Layer draw
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep gpu @Dep gpu
@Dep sprite @Dep sprite
@Dep font @Dep font
@Dep collider @Dep collider
//////////////////////////////// //- Api
//~ Api @IncludeC draw_core.h
@ApiC draw_core //- Impl
@IncludeC draw_core.c
//////////////////////////////// //- Init
//~ Init @Startup D_StartupCore
@Init D_StartupCore

View File

@ -1,15 +1,14 @@
@Layer font @Layer font
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep ttf @Dep ttf
@Dep gpu @Dep gpu
@Dep resource @Dep resource
@Dep asset_cache @Dep asset_cache
//////////////////////////////// //- Api
//~ Api @IncludeC font_core.h
@ApiC font_core //- Impl
@IncludeC font_core.c

View File

@ -1,20 +1,14 @@
@Layer gpu @Layer gpu
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
//////////////////////////////// //- Api
//~ Api @IncludeC gpu_core.h
@ApiC gpu_core //- Dx12 impl
@DefaultWindowsImpl gpu_dx12
//- Dx12 //- Startup
@ApiCWindows dx12/gpu_dx12 @Startup GPU_StartupCore
////////////////////////////////
//~ Init
@Init GPU_StartupCore

View File

@ -1,11 +1,10 @@
@Layer inc @Layer inc
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC inc_core.h
@ApiC inc_core //- Impl
@IncludeC inc_core.c

View File

@ -1,11 +1,10 @@
@Layer json @Layer json
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC json_core.h
@ApiC json_core //- Impl
@IncludeC json_core.c

View File

@ -1,12 +1,8 @@
@Layer kernel @Layer kernel
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC kernel_core.h
@IncludeGpu kernel_core.h
@ApiC kernel_core
@ApiGpu kernel_core

File diff suppressed because it is too large Load Diff

View File

@ -235,9 +235,9 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//- Fallthrough //- Fallthrough
#if CompilerIsClang #if CompilerIsClang
# define FALLTHROUGH
#else
# define FALLTHROUGH __attribute((fallthrough)) # define FALLTHROUGH __attribute((fallthrough))
#else
# define FALLTHROUGH
#endif #endif
//- Preprocessor concatenation //- Preprocessor concatenation
@ -262,7 +262,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//~ Type helper macros //~ Type helper macros
//- alignof //- alignof
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && (__STDC_VERSION__ < 202311L)) #if LanguageIsC && (CompilerIsMsvc || __STDC_VERSION__ < 202311L)
# define alignof(type) __alignof(type) # define alignof(type) __alignof(type)
#endif #endif
@ -450,8 +450,8 @@ Struct(Atomic32) { volatile i32 _v; };
Struct(Atomic64) { volatile i64 _v; }; Struct(Atomic64) { volatile i64 _v; };
//- Cache-line isolated aligned atomic types //- Cache-line isolated aligned atomic types
AlignedStruct(Atomic8Padded, 64) { Atomic8 v; u8 _pad[60]; }; AlignedStruct(Atomic8Padded, 64) { Atomic8 v; u8 _pad[63]; };
AlignedStruct(Atomic16Padded, 64) { Atomic16 v; u8 _pad[60]; }; AlignedStruct(Atomic16Padded, 64) { Atomic16 v; u8 _pad[62]; };
AlignedStruct(Atomic32Padded, 64) { Atomic32 v; u8 _pad[60]; }; AlignedStruct(Atomic32Padded, 64) { Atomic32 v; u8 _pad[60]; };
AlignedStruct(Atomic64Padded, 64) { Atomic64 v; u8 _pad[56]; }; AlignedStruct(Atomic64Padded, 64) { Atomic64 v; u8 _pad[56]; };
StaticAssert(sizeof(Atomic8Padded) == 64 && alignof(Atomic8Padded) == 64); StaticAssert(sizeof(Atomic8Padded) == 64 && alignof(Atomic8Padded) == 64);
@ -517,11 +517,21 @@ ForceInline void UnlockTicketMutex(TicketMutex *tm)
#endif #endif
//////////////////////////////// ////////////////////////////////
//~ String types //~ String utils
#define STRING(size, data) (CppCompatInitListType(String) { (size), (data) }) #define STRING(size, data) ((String) { (size), (data) })
#define Lit(cstr_lit) CppCompatInitListType(String) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) } #define Lit(cstr_lit) (String) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
#define LitNoCast(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) } #define LitNoCast(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
#define StringFromPointers(p0, p1) ((String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
#define StringFromStruct(ptr) ((String) { sizeof(*(ptr)), (u8 *)(ptr) })
#define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena)))
/* String from static array */
#define StringFromArray(a) \
( \
Assert(IsArray(a)), \
((String) { .len = sizeof(a), .text = (u8 *)(a) }) \
)
Struct(String) Struct(String)
{ {
@ -544,7 +554,8 @@ Struct(String32)
//////////////////////////////// ////////////////////////////////
//~ @hookdecl Core hooks //~ @hookdecl Core hooks
void Panic(String msg); void StartupBase(void);
b32 Panic(String msg);
b32 IsRunningInDebugger(void); b32 IsRunningInDebugger(void);
i16 ThreadId(void); i16 ThreadId(void);

View File

@ -57,6 +57,9 @@ extern SharedArenaCtx shared_arena_ctx;
#define PopStruct(a, type, dst) PopBytes((a), sizeof(type), dst) #define PopStruct(a, type, dst) PopBytes((a), sizeof(type), dst)
#define PopStructs(a, type, n, dst) PopBytes((a), sizeof(type) * (n), dst) #define PopStructs(a, type, n, dst) PopBytes((a), sizeof(type) * (n), dst)
#define PopStructNoCopy(a, type) PopBytesNoCopy((a), sizeof(type))
#define PopStructsNoCopy(a, type, n) PopBytesNoCopy((a), sizeof(type) * (n))
/* Returns a pointer to where the next push would be (at alignment of type). /* Returns a pointer to where the next push would be (at alignment of type).
* Equivalent to PushStruct but without actually allocating anything or modifying the arena. */ * Equivalent to PushStruct but without actually allocating anything or modifying the arena. */
#define PushDry(a, type) (type *)(_PushDry((a), alignof(type))) #define PushDry(a, type) (type *)(_PushDry((a), alignof(type)))
@ -84,6 +87,15 @@ Inline void PopTo(Arena *arena, u64 pos)
arena->pos = pos; arena->pos = pos;
} }
Inline void PopBytesNoCopy(Arena *arena, u64 size)
{
Assert(arena->pos >= size);
Assert(!arena->readonly);
u64 new_pos = arena->pos - size;
AsanPoison(ArenaBase(arena) + new_pos, arena->pos - new_pos);
arena->pos = new_pos;
}
Inline void PopBytes(Arena *arena, u64 size, void *copy_dst) Inline void PopBytes(Arena *arena, u64 size, void *copy_dst)
{ {
Assert(arena->pos >= size); Assert(arena->pos >= size);

View File

@ -0,0 +1,21 @@
//- Header files
#include "meta_base.h"
#include "meta_base_intrinsics.h"
#include "meta_base_memory.h"
#include "meta_base_arena.h"
#include "meta_base_math.h"
#include "meta_base_uni.h"
#include "meta_base_string.h"
#include "meta_base_util.h"
//- Source files
#include "meta_base_arena.c"
#include "meta_base_math.c"
#include "meta_base_memory.c"
#include "meta_base_string.c"
#include "meta_base_uni.c"
//- Win32
#if PlatformIsWindows
# include "meta_base_win32/meta_base_win32_inc.h"
#endif

View File

@ -293,12 +293,12 @@ f32 LnF32(f32 x)
if ((x_int & 0x7fffffff) == 0) if ((x_int & 0x7fffffff) == 0)
{ {
/* Return -inf if x is 0 */ /* Return -inf if x is 0 */
return -two_p25 / 0; return -F32Infinity;
} }
else if (x_int < 0) else if (x_int < 0)
{ {
/* Return NaN if x is negative */ /* Return NaN if x is negative */
return (x - x) / 0; return F32Nan;
} }
k -= 25; k -= 25;
x *= two_p25; x *= two_p25;
@ -391,7 +391,7 @@ f32 ExpF32(f32 x)
/* Filter out non-finite argument */ /* Filter out non-finite argument */
if (x_uint >= 0x42b17218) if (x_uint >= 0x42b17218)
{ /* if |x|>=88.721... */ { /* if |x| >= 88.721... */
if (x_uint > 0x7f800000) if (x_uint > 0x7f800000)
{ {
return x + x; /* NaN */ return x + x; /* NaN */
@ -1377,7 +1377,7 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt)
Mat4x4 Mat4x4FromXform(Xform xf) Mat4x4 Mat4x4FromXform(Xform xf)
{ {
return CppCompatInitListType(Mat4x4) return (Mat4x4)
{ {
.e = { .e = {
{xf.bx.x, xf.bx.y, 0, 0}, {xf.bx.x, xf.bx.y, 0, 0},

View File

@ -10,7 +10,7 @@
Struct(Vec2) { Struct(Vec2) {
f32 x, y; f32 x, y;
}; };
#define VEC2(x, y) CppCompatInitListType(Vec2) { (x), (y) } #define VEC2(x, y) (Vec2) { (x), (y) }
Struct(Vec2Array) { Struct(Vec2Array) {
Vec2 *points; Vec2 *points;
@ -23,7 +23,7 @@ Struct(Vec2Array) {
Struct(Vec3) { Struct(Vec3) {
f32 x, y, z; f32 x, y, z;
}; };
#define VEC3(x, y, z) CppCompatInitListType(Vec3) { (x), (y), (z) } #define VEC3(x, y, z) (Vec3) { (x), (y), (z) }
Struct(Vec3Array) { Struct(Vec3Array) {
Vec3 *points; Vec3 *points;
@ -49,7 +49,7 @@ Struct(Vec4Array) {
Struct(Vec2I32) { Struct(Vec2I32) {
i32 x, y; i32 x, y;
}; };
#define VEC2I32(x, y) CppCompatInitListType(Vec2I32) { (x), (y) } #define VEC2I32(x, y) (Vec2I32) { (x), (y) }
//////////////////////////////// ////////////////////////////////
//~ Integer vector3 types //~ Integer vector3 types
@ -57,7 +57,7 @@ Struct(Vec2I32) {
Struct(Vec3I32) { Struct(Vec3I32) {
i32 x, y, z; i32 x, y, z;
}; };
#define VEC3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) } #define VEC3I32(x, y, z) (Vec3I32) { (x), (y), (z) }
//////////////////////////////// ////////////////////////////////
//~ Integer vector4 types //~ Integer vector4 types
@ -66,7 +66,7 @@ Struct(Vec4I32)
{ {
i32 x, y, z, w; i32 x, y, z, w;
}; };
#define VEC4I32(x, y, z, w) CppCompatInitListType(Vec4I32) { (x), (y), (z), (w) } #define VEC4I32(x, y, z, w) (Vec4I32) { (x), (y), (z), (w) }
//////////////////////////////// ////////////////////////////////
//~ Xform types //~ Xform types
@ -90,7 +90,8 @@ Struct(Trs)
//~ Rect types //~ Rect types
Struct(Rect) { Struct(Rect) {
union { union
{
struct { f32 x, y, width, height; }; struct { f32 x, y, width, height; };
struct { Vec2 pos, size; }; struct { Vec2 pos, size; };
}; };
@ -114,7 +115,8 @@ Struct(Aabb) {
//~ Quad types //~ Quad types
Struct(Quad) { Struct(Quad) {
union { union
{
struct { Vec2 p0, p1, p2, p3; }; struct { Vec2 p0, p1, p2, p3; };
struct { Vec2 e[4]; }; struct { Vec2 e[4]; };
}; };
@ -329,7 +331,7 @@ Vec2I32 SubVec2I32(Vec2I32 a, Vec2I32 b);
b32 EqXform(Xform xf1, Xform xf2); b32 EqXform(Xform xf1, Xform xf2);
//- Initialization //- Initialization
#define XformIdentity CppCompatInitListType(Xform) { .bx = VEC2(1, 0), .by = VEC2(0, 1) } #define XformIdentity (Xform) { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
#define XformIdentityNoCast { .bx = VEC2(1, 0), .by = VEC2(0, 1) } #define XformIdentityNoCast { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
Xform XformFromPos(Vec2 v); Xform XformFromPos(Vec2 v);
Xform XformFromRot(f32 r); Xform XformFromRot(f32 r);

View File

@ -1,5 +1,5 @@
//////////////////////////////// ////////////////////////////////
//~ Conversion //~ Conversion helpers
//- Char conversion //- Char conversion
@ -171,7 +171,7 @@ String StringFromF64(Arena *arena, f64 f, u32 precision)
} }
//////////////////////////////// ////////////////////////////////
//~ String operations //~ String helpers
//- Copy //- Copy
@ -433,11 +433,11 @@ b32 StringEndsWith(String str, String substring)
} }
//////////////////////////////// ////////////////////////////////
//~ String list operations //~ String list helpers
StringNode *PushStringNode(Arena *arena, StringList *l, String s) StringListNode *PushStringToList(Arena *arena, StringList *l, String s)
{ {
StringNode *n = PushStruct(arena, StringNode); StringListNode *n = PushStruct(arena, StringListNode);
n->s = s; n->s = s;
n->prev = l->last; n->prev = l->last;
if (l->last) if (l->last)
@ -449,9 +449,28 @@ StringNode *PushStringNode(Arena *arena, StringList *l, String s)
l->first = n; l->first = n;
} }
l->last = n; l->last = n;
++l->count;
return n; return n;
} }
String StringFromStringList(Arena *arena, StringList l, String separator)
{
String result = ZI;
result.text = PushDry(arena, u8);
for (StringListNode *n = l.first; n; n = n->next)
{
String s = n->s;
PushString(arena, s);
result.len += s.len;
if (n->next)
{
PushString(arena, separator);
result.len += separator.len;
}
}
return result;
}
//////////////////////////////// ////////////////////////////////
//~ Formatting //~ Formatting

View File

@ -7,17 +7,18 @@ Struct(StringArray)
String *strings; String *strings;
}; };
Struct(StringNode) Struct(StringListNode)
{ {
String s; String s;
StringNode *next; StringListNode *next;
StringNode *prev; StringListNode *prev;
}; };
Struct(StringList) Struct(StringList)
{ {
StringNode *first; StringListNode *first;
StringNode *last; StringListNode *last;
u64 count;
}; };
//////////////////////////////// ////////////////////////////////
@ -71,24 +72,7 @@ Struct(CodepointIter)
}; };
//////////////////////////////// ////////////////////////////////
//~ String utils //~ Conversion helpers
#define STRING(size, data) (CppCompatInitListType(String) { (size), (data) })
#define Lit(cstr_lit) CppCompatInitListType(String) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
#define LitNoCast(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
#define StringFromPointers(p0, p1) (CppCompatInitListType(String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
#define StringFromStruct(ptr) (CppCompatInitListType(String) { sizeof(*(ptr)), (u8 *)(ptr) })
#define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena)))
/* String from static array */
#define StringFromArray(a) \
( \
Assert(IsArray(a)), \
((String) { .len = sizeof(a), .text = (u8 *)(a) }) \
)
////////////////////////////////
//~ Conversion operations
String StringFromChar(Arena *arena, char c); String StringFromChar(Arena *arena, char c);
String StringFromU64(Arena *arena, u64 n, u64 base, u64 zfill); String StringFromU64(Arena *arena, u64 n, u64 base, u64 zfill);
@ -97,7 +81,7 @@ String StringFromPtr(Arena *arena, void *ptr);
String StringFromF64(Arena *arena, f64 f, u32 precision); String StringFromF64(Arena *arena, f64 f, u32 precision);
//////////////////////////////// ////////////////////////////////
//~ String operation //~ String helpers
String PushString(Arena *arena, String src); String PushString(Arena *arena, String src);
String PushStringToBuff(String dst, String src); String PushStringToBuff(String dst, String src);
@ -112,6 +96,12 @@ b32 StringContains(String str, String substring);
b32 StringStartsWith(String str, String substring); b32 StringStartsWith(String str, String substring);
b32 StringEndsWith(String str, String substring); b32 StringEndsWith(String str, String substring);
////////////////////////////////
//~ String list helpers
StringListNode *PushStringToList(Arena *arena, StringList *l, String s);
String StringFromStringList(Arena *arena, StringList l, String separator);
//////////////////////////////// ////////////////////////////////
//~ Formatting //~ Formatting
@ -130,6 +120,7 @@ b32 StringEndsWith(String str, String substring);
#define FmtEnd (FmtArg) {.kind = FmtKind_End} #define FmtEnd (FmtArg) {.kind = FmtKind_End}
//- Format functions //- Format functions
#define StringF(arena, lit, ...) _StringFormat((arena), Lit(lit), __VA_ARGS__, FmtEnd)
#define StringFormat(arena, fmt, ...) _StringFormat((arena), (fmt), __VA_ARGS__, FmtEnd) #define StringFormat(arena, fmt, ...) _StringFormat((arena), (fmt), __VA_ARGS__, FmtEnd)
String _StringFormat(Arena *arena, String fmt, ...); String _StringFormat(Arena *arena, String fmt, ...);
String StringFormatV(Arena *arena, String fmt, va_list args); String StringFormatV(Arena *arena, String fmt, va_list args);

View File

@ -0,0 +1,296 @@
////////////////////////////////
//~ Hash types
#define Fnv64Basis 0xCBF29CE484222325
////////////////////////////////
//~ Mergesort types
/* Compare functions should
* return a positive value if a should go before b
* return a negative value if a should go after b
* return 0 otherwise
*/
#define MergesortCompareFuncDef(name, arg_a, arg_b, arg_udata) i32 name(void *arg_a, void *arg_b, void *arg_udata)
typedef MergesortCompareFuncDef(MergesortCompareFunc, a, b, udata);
////////////////////////////////
//~ Dict types
Struct(DictEntry)
{
u64 hash;
u64 value;
DictEntry *prev_in_bin;
DictEntry *next_in_bin;
DictEntry *prev;
DictEntry *next;
};
Struct(DictBin)
{
DictEntry *first;
DictEntry *last;
};
Struct(Dict)
{
u64 bins_count;
DictBin *bins;
DictEntry *first_free;
DictEntry *first;
DictEntry *last;
};
////////////////////////////////
//~ Hash utils
/* FNV-1a parameters for different hash sizes:
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV_hash_parameters
*/
Inline u64 HashFnv64(u64 seed, String s)
{
u64 hash = seed;
for (u64 i = 0; i < s.len; ++i)
{
hash ^= (u8)s.text[i];
hash *= 0x100000001B3;
}
return hash;
}
////////////////////////////////
//~ Mergesort utils
Inline void MergesortInternal(u8 *left, u8 *right, u8 *items, u64 left_count, u64 right_count, u64 item_size, MergesortCompareFunc *callback, void *udata)
{
/* Sort */
u64 i = 0;
u64 l = 0;
u64 r = 0;
while (l < left_count && r < right_count)
{
u8 *dst = items + (i * item_size);
u8 *left_item = left + (l * item_size);
u8 *right_item = right + (r * item_size);
++i;
if (callback(left_item, right_item, udata) > 0)
{
CopyBytes(dst, left_item, item_size);
++l;
}
else
{
CopyBytes(dst, right_item, item_size);
++r;
}
}
/* Copy remaining */
if (l != left_count)
{
u64 remaining_count = left_count - l;
u64 remaining_bytes = remaining_count * item_size;
u8 *dst = items + (i * item_size);
u8 *src = left + (l * item_size);
CopyBytes(dst, src, remaining_bytes);
}
else if (r != right_count)
{
u64 remaining_count = right_count - r;
u64 remaining_bytes = remaining_count * item_size;
u8 *dst = items + (i * item_size);
u8 *src = right + (r * item_size);
CopyBytes(dst, src, remaining_bytes);
}
}
Inline void Mergesort(void *items, u64 item_count, u64 item_size, MergesortCompareFunc *callback, void *udata)
{
if (item_count > 1)
{
TempArena scratch = BeginScratchNoConflict();
u64 left_count = item_count / 2;
u64 right_count = item_count - left_count;
u64 left_size = left_count * item_size;
u64 right_size = right_count * item_size;
u8 *left = PushStructsNoZero(scratch.arena, u8, left_size);
u8 *right = PushStructsNoZero(scratch.arena, u8, right_size);
CopyBytes(left, items, left_size);
CopyBytes(right, (u8 *)items + left_size, right_size);
Mergesort(left, left_count, item_size, callback, udata);
Mergesort(right, right_count, item_size, callback, udata);
MergesortInternal(left, right, (u8 *)items, left_count, right_count, item_size, callback, udata);
EndScratch(scratch);
}
}
////////////////////////////////
//~ Dict utils
//- Dict init
Inline Dict *InitDict(Arena *arena, u64 bins_count)
{
__prof;
Dict *dict = PushStruct(arena, Dict);
dict->bins_count = MaxU64(bins_count, 1); /* Ensure at least 1 bin */
dict->bins = PushStructs(arena, DictBin, dict->bins_count);
return dict;
}
Inline void ResetDict(Dict *dict)
{
ZeroBytes(dict->bins, sizeof(*dict->bins) * dict->bins_count);
if (dict->first)
{
dict->last->next = dict->first_free;
dict->first_free = dict->first;
}
}
//- Dict set
Inline DictEntry *EnsureDictEntry(Arena *arena, Dict *dict, u64 hash)
{
__prof;
DictBin *bin = &dict->bins[hash % dict->bins_count];
DictEntry *entry = bin->first;
while (entry)
{
if (hash == entry->hash)
{
/* Existing match found */
break;
}
entry = entry->next_in_bin;
}
/* No match found, create new entry */
if (!entry)
{
if (dict->first_free)
{
entry = dict->first_free;
dict->first_free = entry->next;
}
else
{
entry = PushStructNoZero(arena, DictEntry);
}
ZeroStruct(entry);
entry->hash = hash;
if (bin->last)
{
bin->last->next_in_bin = entry;
entry->prev_in_bin = bin->last;
}
else
{
bin->first = entry;
}
bin->last = entry;
if (dict->last)
{
dict->last->next = entry;
entry->prev = dict->last;
}
else
{
dict->first = entry;
}
dict->last = entry;
}
return entry;
}
Inline void SetDictValue(Arena *arena, Dict *dict, u64 hash, u64 value)
{
__prof;
DictEntry *entry = EnsureDictEntry(arena, dict, hash);
entry->value = value;
}
//- Dict remove
Inline void RemoveDictEntry(Dict *dict, DictEntry *entry)
{
/* Remove from bin */
{
DictBin *bin = &dict->bins[entry->hash % dict->bins_count];
DictEntry *prev_in_bin = entry->prev_in_bin;
DictEntry *next_in_bin = entry->next_in_bin;
if (prev_in_bin)
{
prev_in_bin->next_in_bin = next_in_bin;
}
else
{
bin->first = next_in_bin;
}
if (next_in_bin)
{
next_in_bin->prev_in_bin = prev_in_bin;
}
else
{
bin->last = prev_in_bin;
}
}
/* Remove from list */
{
DictEntry *prev = entry->prev;
DictEntry *next = entry->next;
if (prev)
{
prev->next = next;
}
else
{
dict->first = next;
}
if (next)
{
next->prev = prev;
}
else
{
dict->last = prev;
}
}
/* Insert into free list */
{
entry->next = dict->first_free;
dict->first_free = entry;
}
}
//- Dict index
Inline DictEntry *DictEntryFromHash(Dict *dict, u64 hash)
{
__prof;
DictEntry *result = 0;
DictBin *bin = &dict->bins[hash % dict->bins_count];
for (DictEntry *entry = bin->first; entry; entry = entry->next_in_bin)
{
if (hash == entry->hash)
{
/* Match found */
result = entry;
break;
}
}
return result;
}
Inline u64 DictValueFromHash(Dict *dict, u64 hash)
{
__prof;
DictEntry *entry = DictEntryFromHash(dict, hash);
return entry ? entry->value : 0;
}

View File

@ -9,7 +9,7 @@ W32_SharedState W32_shared_state = ZI;
//////////////////////////////// ////////////////////////////////
//~ @hookdef OS startup hook //~ @hookdef OS startup hook
void StartupOs(void) void StartupBase(void)
{ {
W32_SharedState *g = &W32_shared_state; W32_SharedState *g = &W32_shared_state;
g->tls_index = TlsAlloc(); g->tls_index = TlsAlloc();
@ -17,23 +17,30 @@ void StartupOs(void)
} }
//////////////////////////////// ////////////////////////////////
//~ @hookdef Core Panic hooks //~ @hookdef Core panic hooks
/* TODO: Remove stdio & printf */ /* TODO: Remove stdio & printf */
#include <stdio.h> #include <stdio.h>
void Panic(String msg) b32 Panic(String msg)
{ {
char msg_cstr[4096]; char msg_cstr[4096];
CstrFromStringToBuff(StringFromArray(msg_cstr), msg); CstrFromStringToBuff(StringFromArray(msg_cstr), msg);
ShowMessageBoxCstr("Fatal error", msg_cstr, 1); {
u32 mb_flags = MB_SETFOREGROUND | MB_ICONERROR;
MessageBoxExA(0, msg_cstr, "Fatal error", mb_flags, 0);
}
printf(msg_cstr); printf(msg_cstr);
fflush(stdout); fflush(stdout);
if ((1)) /* Supress unreachable code warning */
{
ExitProcess(1); ExitProcess(1);
}
return 0;
} }
//////////////////////////////// ////////////////////////////////
//~ @hookdef Core Debugger hooks //~ @hookdef Debugger hooks
b32 IsRunningInDebugger(void) b32 IsRunningInDebugger(void)
{ {
@ -41,28 +48,10 @@ b32 IsRunningInDebugger(void)
} }
//////////////////////////////// ////////////////////////////////
//~ @hookdef Core Thread hooks //~ @hookdef Thread hooks
i16 ThreadId(void) i16 ThreadId(void)
{ {
W32_SharedState *g = &W32_shared_state; W32_SharedState *g = &W32_shared_state;
return (i16)(i64)TlsGetValue(g->tls_index); return (i16)(i64)TlsGetValue(g->tls_index);
} }
////////////////////////////////
//~ @hookdef OS Message box hooks
void ShowMessageBox(String title, String msg, b32 error)
{
char title_cstr[256];
char msg_cstr[4096];
CstrFromStringToBuff(StringFromArray(title_cstr), title);
CstrFromStringToBuff(StringFromArray(msg_cstr), msg);
ShowMessageBoxCstr(title_cstr, msg_cstr, error);
}
void ShowMessageBoxCstr(char *title_cstr, char *msg_cstr, b32 error)
{
u32 mb_flags = MB_SETFOREGROUND | (!!error * MB_ICONERROR) | (!error * MB_ICONINFORMATION);
MessageBoxExA(0, msg_cstr, title_cstr, mb_flags, 0);
}

View File

@ -16,9 +16,3 @@ Struct(W32_SharedState)
}; };
extern W32_SharedState W32_shared_state; extern W32_SharedState W32_shared_state;
////////////////////////////////
//~ @hookdecl Message box
void ShowMessageBox(String title, String msg, b32 error);
void ShowMessageBoxCstr(char *title_cstr, char *msg_cstr, b32 error);

View File

@ -0,0 +1,2 @@
#include "meta_base_win32.h"
#include "meta_base_win32.c"

View File

View File

@ -0,0 +1,125 @@
////////////////////////////////
//~ Path helpers
String F_GetFull(Arena *arena, String path)
{
return OS_GetFullPath(arena, path);
}
String F_GetFileName(String path)
{
String result = ZI;
u64 start = path.len;
for (u64 i = path.len; i-- > 0;)
{
if (path.text[i] == '\\' || path.text[i] == '/')
{
start = i + 1;
break;
}
}
if (start < path.len)
{
result.text = &path.text[start];
result.len = path.len - start;
}
return result;
}
String F_GetParentDir(String path)
{
String result = ZI;
result.text = path.text;
u64 end = path.len;
for (u64 i = path.len; i-- > 0;)
{
if (path.text[i] == '\\' || path.text[i] == '/')
{
end = i + 1;
break;
}
}
if (end < path.len)
{
result.len = end;
}
return result;
}
String F_ExtensionFromFile(String path)
{
String result = ZI;
u64 start = path.len;
for (u64 i = path.len; i-- > 0;)
{
if (path.text[i] == '.')
{
start = i + 1;
break;
}
}
if (start < path.len)
{
result.text = &path.text[start];
result.len = path.len - start;
}
return result;
}
////////////////////////////////
//~ File read operations
String F_DataFromFile(Arena *arena, String path)
{
String result = ZI;
OS_File file = OS_OpenFile(path, OS_FileFlag_Read);
result = OS_ReadEntireFile(arena, file);
OS_CloseFile(file);
return result;
}
////////////////////////////////
//~ File write operations
void F_ClearWrite(String path, String data)
{
OS_File file = OS_OpenFile(path, OS_FileFlag_Write | OS_FileFlag_Create);
OS_ClearWriteFile(file, data);
OS_CloseFile(file);
}
////////////////////////////////
//~ File attribute helpers
b32 F_IsFile(String path)
{
return OS_FileExists(path);
}
b32 F_IsDir(String path)
{
return OS_DirExists(path);
}
////////////////////////////////
//~ File iter operations
void F_FilesFromDir(Arena *arena, StringList *list, String dir, F_IterFlag flags)
{
TempArena scratch = BeginScratch(arena);
StringList tmp = ZI;
String dir_full_path = F_GetFull(scratch.arena, dir);
OS_DirContentsFromFullPath(scratch.arena, &tmp, dir_full_path);
for (StringListNode *n = tmp.first; n; n = n->next)
{
String file_joined_path = StringF(arena, "%F/%F", FmtString(dir), FmtString(n->s));
PushStringToList(arena, list, file_joined_path);
if (flags & F_IterFlag_Recurse && F_IsDir(file_joined_path))
{
F_FilesFromDir(arena, list, file_joined_path, flags);
}
}
EndScratch(scratch);
}

View File

@ -0,0 +1,37 @@
////////////////////////////////
//~ File iter types
typedef i32 F_IterFlag; enum
{
F_IterFlag_None = 0,
F_IterFlag_Recurse = (1 << 0)
};
////////////////////////////////
//~ Path helpers
String F_GetFull(Arena *arena, String path);
String F_GetFileName(String path);
String F_GetParentDir(String path);
String F_ExtensionFromFile(String path);
////////////////////////////////
//~ File read operations
String F_DataFromFile(Arena *arena, String path);
////////////////////////////////
//~ File write operations
void F_ClearWrite(String path, String data);
////////////////////////////////
//~ File attribute helpers
b32 F_IsFile(String path);
b32 F_IsDir(String path);
////////////////////////////////
//~ File iter operations
void F_FilesFromDir(Arena *arena, StringList *list, String dir, F_IterFlag flags);

View File

@ -0,0 +1,2 @@
#include "meta_file.h"
#include "meta_file.c"

View File

@ -1,4 +0,0 @@
////////////////////////////////
//~ @hookdeclStartup hooks
void StartupOs(void);

View File

@ -0,0 +1,44 @@
////////////////////////////////
//~ File types
typedef i32 OS_FileFlag; enum
{
OS_FileFlag_None = 0,
OS_FileFlag_Read = (1 << 0),
OS_FileFlag_Write = (1 << 1),
OS_FileFlag_Create = (1 << 2),
OS_FileFlag_NoWait = (1 << 3)
};
Struct(OS_File)
{
u64 handle;
};
////////////////////////////////
//~ @hookdecl Startup hooks
void OS_Startup(void);
////////////////////////////////
//~ @hookdecl File system operations
OS_File OS_OpenFile(String path, OS_FileFlag flags);
void OS_CloseFile(OS_File file);
String OS_ReadEntireFile(Arena *arena, OS_File file);
void OS_ClearWriteFile(OS_File file, String data);
void OS_DirContentsFromFullPath(Arena *arena, StringList *list, String path);
String OS_GetFullPath(Arena *arena, String path);
b32 OS_FileOrDirExists(String path);
b32 OS_FileExists(String path);
b32 OS_DirExists(String path);
////////////////////////////////
//~ @hookdecl Directory helpers
void OS_Mkdir(String path);
////////////////////////////////
//~ @hookdecl Shell operations
void OS_RunCommand(String cmd);

View File

@ -0,0 +1,5 @@
#include "meta_os.h"
#if PlatformIsWindows
# include "meta_os_win32/meta_os_win32_inc.h"
#endif

View File

@ -0,0 +1,163 @@
////////////////////////////////
//~ Windows libs
#pragma comment(lib, "kernel32")
#pragma comment(lib, "user32")
////////////////////////////////
//~ @hookdef Startup hook
void OS_Startup(void)
{
W32_SharedState *g = &W32_shared_state;
g->tls_index = TlsAlloc();
TlsSetValue(g->tls_index, 0);
}
////////////////////////////////
//~ @hookdef File system hooks
OS_File OS_OpenFile(String path, OS_FileFlag flags)
{
TempArena scratch = BeginScratchNoConflict();
OS_File result = ZI;
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
b32 wait_for_access = 1;
u32 share_mode = FILE_SHARE_READ;
u32 create_mode = OPEN_EXISTING;
u32 access_flags = 0;
if (flags & OS_FileFlag_Read) access_flags |= GENERIC_READ;
if (flags & OS_FileFlag_Write) access_flags |= GENERIC_WRITE;
if (flags & OS_FileFlag_Create) create_mode = OPEN_ALWAYS;
if (flags & OS_FileFlag_NoWait) wait_for_access = 0;
i32 delay_ms = 1;
HANDLE handle;
while ((handle = CreateFileW(path_wstr, access_flags, share_mode, 0, create_mode, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE && wait_for_access)
{
if (GetLastError() == ERROR_SHARING_VIOLATION)
{
Sleep(delay_ms);
if (delay_ms < 1024)
{
delay_ms *= 2;
}
}
else
{
break;
}
}
EndScratch(scratch);
result.handle = (u64)handle;
return result;
}
void OS_CloseFile(OS_File file)
{
HANDLE handle = (HANDLE)file.handle;
CloseHandle(handle);
}
String OS_ReadEntireFile(Arena *arena, OS_File file)
{
String result = ZI;
HANDLE handle = (HANDLE)file.handle;
u32 chunk_size = Kibi(64);
result.text = PushDry(arena, u8);
for (;;)
{
u8 *chunk = PushStructsNoZero(arena, u8, chunk_size);
u32 chunk_bytes_read = 0;
ReadFile(handle, chunk, chunk_size, &chunk_bytes_read, 0);
result.len += chunk_bytes_read;
if (chunk_bytes_read < chunk_size)
{
PopStructsNoCopy(arena, u8, chunk_size - chunk_bytes_read);
break;
}
}
return result;
}
void OS_ClearWriteFile(OS_File file, String data)
{
HANDLE handle = (HANDLE)file.handle;
SetFilePointer(handle, 0, 0, FILE_BEGIN);
SetEndOfFile(handle);
WriteFile(handle, data.text, data.len, 0, 0);
}
void OS_DirContentsFromFullPath(Arena *arena, StringList *list, String path)
{
TempArena scratch = BeginScratch(arena);
WIN32_FIND_DATAW find_data = ZI;
String filter = StringF(scratch.arena, "%F\\*", FmtString(path));
wchar_t *filter_wstr = WstrFromString(scratch.arena, filter);
HANDLE find_handle = FindFirstFileExW(filter_wstr, FindExInfoStandard, &find_data, FindExSearchNameMatch, 0, FIND_FIRST_EX_CASE_SENSITIVE | FIND_FIRST_EX_LARGE_FETCH);
b32 found = find_handle && find_handle != INVALID_HANDLE_VALUE;
while (found) {
String file_name = StringFromWstrNoLimit(arena, find_data.cFileName);
if (!EqString(file_name, Lit(".")) && !EqString(file_name, Lit(".."))) {
PushStringToList(arena, list, file_name);
}
found = FindNextFileW(find_handle, &find_data);
}
EndScratch(scratch);
}
String OS_GetFullPath(Arena *arena, String path)
{
TempArena scratch = BeginScratch(arena);
wchar_t *rel_path_wstr = WstrFromString(scratch.arena, path);
wchar_t buff[4096];
wchar_t *full_path_wstr = _wfullpath(buff, rel_path_wstr, countof(buff));
String res = StringFromWstrNoLimit(arena, full_path_wstr);
EndScratch(scratch);
return res;
}
////////////////////////////////
//~ @hookdef Directory helper hooks
void OS_Mkdir(String path)
{
TempArena scratch = BeginScratchNoConflict();
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
CreateDirectoryW(path_wstr, 0);
EndScratch(scratch);
}
b32 OS_FileOrDirExists(String path)
{
TempArena scratch = BeginScratchNoConflict();
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
DWORD attributes = GetFileAttributesW(path_wstr);
EndScratch(scratch);
return attributes != INVALID_FILE_ATTRIBUTES;
}
b32 OS_FileExists(String path)
{
TempArena scratch = BeginScratchNoConflict();
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
DWORD attributes = GetFileAttributesW(path_wstr);
EndScratch(scratch);
return attributes != INVALID_FILE_ATTRIBUTES && !(attributes & FILE_ATTRIBUTE_DIRECTORY);
}
b32 OS_DirExists(String path)
{
TempArena scratch = BeginScratchNoConflict();
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
DWORD attributes = GetFileAttributesW(path_wstr);
EndScratch(scratch);
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY);
}
////////////////////////////////
//~ @hookdef Shell hooks
void OS_RunCommand(String cmd)
{
}

View File

@ -0,0 +1 @@
#include <stdlib.h> /* _wfullpath */

View File

@ -0,0 +1,2 @@
#include "meta_os_win32.h"
#include "meta_os_win32.c"

View File

@ -1,18 +1,15 @@
@Layer mixer @Layer mixer
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep sound @Dep sound
//////////////////////////////// //- Api
//~ Api @IncludeC mixer_core.h
@ApiC mixer_core //- Impl
@IncludeC mixer_core.c
//////////////////////////////// //- Startup
//~ Init @Startup MIX_StartupCore
@Init MIX_StartupCore

View File

@ -1,14 +1,10 @@
@Layer mp3 @Layer mp3
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC mp3_core.h
@ApiC mp3_core //- Mmf impl
@DefaultWindowsImpl mp3_mmf
//- Mmf
@ApiCWindows mp3_mmf

View File

@ -1,13 +1,12 @@
@Layer net @Layer net
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep bitbuff @Dep bitbuff
//////////////////////////////// //- Api
//~ Api @IncludeC net_core.h
@ApiC net_core //- Impl
@IncludeC net_core.c

View File

@ -1,21 +1,18 @@
@Layer platform @Layer platform
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
//////////////////////////////// //- Api
//~ Api @IncludeC platform_core.h
@IncludeC platform_log.h
@ApiC platform_core //- Impl
@ApiC platform_log @IncludeC platform_log.c
//- Win32 //- Win32 impl
@ApiCWindows platform_win32 @DefaultWindowsImpl platform_win32
//////////////////////////////// //- Startup
//~ Init @Startup P_StartupCore
@Startup P_StartupLog
@Init P_StartupCore
@Init P_StartupLog

View File

@ -1,21 +1,18 @@
@Layer playback @Layer playback
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep mixer @Dep mixer
//////////////////////////////// //- Api
//~ Api @IncludeC playback_core.h
@ApiC playback_core //- Impl
@IncludeC playback_core.c
//- Wasapi //- Wasapi impl
@ApiCWindows wasapi/playback_wasapi @DefaultWindowsImpl playback_wasapi
//////////////////////////////// //- Startup
//~ Init @Startup PB_StartupCore
@Init PB_StartupCore

View File

@ -1,8 +1,7 @@
@Layer pp @Layer pp
////////////////////////////////
//~ Dependencies
//- Dependencies
@Dep base @Dep base
@Dep gpu @Dep gpu
@Dep sprite @Dep sprite
@ -14,19 +13,36 @@
@Dep bitbuff @Dep bitbuff
@Dep rendertest @Dep rendertest
//////////////////////////////// //- Api
//~ Api @IncludeC pp_sim.h
@IncludeC pp_phys.h
@IncludeC pp_space.h
@IncludeC pp_ent.h
@IncludeC pp_step.h
@IncludeC pp_draw.h
@IncludeC pp_core.h
@IncludeGpu pp_draw.h
@ApiC pp_sim //- Impl
@ApiC pp_phys @IncludeC pp_sim.c
@ApiC pp_space @IncludeC pp_phys.c
@ApiC pp_ent @IncludeC pp_space.c
@ApiC pp_step @IncludeC pp_ent.c
@ApiC pp_draw @IncludeC pp_step.c
@ApiC pp_core @IncludeC pp_core.c
@IncludeGpu pp_draw.gpu
//////////////////////////////// //- Shaders
//~ Init @ShaderVS MaterialVS
@ShaderPS MaterialPS
@ShaderCS FloodCS
@ShaderVS UiBlitVS
@ShaderPS UiBlitPS
@ShaderVS UiRectVS
@ShaderPS UiRectPS
@ShaderVS UiShapeVS
@ShaderPS UiShapePS
@Init StartupSim //- Startup
@Init StartupUser @Startup StartupSim
@Startup StartupUser

View File

@ -1,20 +1,17 @@
@Layer rendertest @Layer rendertest
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep gpu @Dep gpu
@Dep sprite @Dep sprite
@Dep font @Dep font
@Dep collider @Dep collider
//////////////////////////////// //- Api
//~ Api @IncludeC rendertest_core.h
@ApiC rendertest_core //- Impl
@IncludeC rendertest_core.c
//////////////////////////////// //- Startup
//~ Init @Startup RT_StartupCore
@Init RT_StartupCore

View File

@ -1,19 +1,16 @@
@Layer resource @Layer resource
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep tar @Dep tar
@Dep inc @Dep inc
//////////////////////////////// //- Api
//~ Api @IncludeC resource_core.h
@ApiC resource_core //- Impl
@IncludeC resource_core.c
//////////////////////////////// //- Startup
//~ Init @Startup RES_StartupCore
@Init RES_StartupCore

View File

@ -1,13 +1,12 @@
@Layer settings @Layer settings
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep json @Dep json
//////////////////////////////// //- Api
//~ Api @IncludeC settings_core.h
@ApiC settings_core //- Impl
@IncludeC settings_core.c

View File

@ -1,15 +1,14 @@
@Layer sound @Layer sound
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep mp3 @Dep mp3
@Dep resource @Dep resource
@Dep asset_cache @Dep asset_cache
//////////////////////////////// //- Api
//~ Api @IncludeC sound_core.h
@ApiC sound_core //- Impl
@IncludeC sound_core.c

View File

@ -1,8 +1,6 @@
@Layer sprite @Layer sprite
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep gpu @Dep gpu
@ -10,12 +8,11 @@
@Dep resource @Dep resource
@Dep watch @Dep watch
//////////////////////////////// //- Api
//~ Api @IncludeC sprite_core.h
@ApiC sprite_core //- Impl
@IncludeC sprite_core.c
//////////////////////////////// //- Startup
//~ Init @Startup S_StartupCore
@Init S_StartupCore

View File

@ -1,13 +1,12 @@
@Layer tar @Layer tar
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
@Dep bitbuff @Dep bitbuff
//////////////////////////////// //- Api
//~ Api @IncludeC tar_core.h
@ApiC tar_core //- Impl
@IncludeC tar_core.c

View File

@ -1,41 +1,10 @@
//////////////////////////////// @Layer ttf
//~ Dependencies
AddDep("../base/base.h"); //- Dependencies
AddDep("../gpu/gpu.h"); @Dep base
AddDep("../sprite/sprite.h");
AddDep("../font/font.h");
AddDep("../collider/collider.h");
AddDep("../draw/draw.h");
AddDep("../net/net.h");
AddDep("../mixer/mixer.h");
AddDep("../bitbuff/bitbuff.h");
AddDep("../rendertest/rendertest.h");
//////////////////////////////// //- Api
//~ Headers @IncludeC ttf_core.h
AddHeader("pp_sim.h"); //- DirectWrite impl
AddHeader("pp_phys.h"); @DefaultWindowsImpl ttf_dwrite
AddHeader("pp_space.h");
AddHeader("pp_ent.h");
AddHeader("pp_step.h");
AddHeader("pp_draw.h");
AddHeader("pp_core.h");
////////////////////////////////
//~ Sources
AddCSource("pp_ent.c");
AddCSource("pp_phys.c");
AddCSource("pp_step.c");
AddCSource("pp_space.c");
AddCSource("pp_sim.c");
AddCSource("pp_core.c");
////////////////////////////////
//~ Init
AddInit(StartupPpDeps);
AddInit(StartupSim);
AddInit(StartupUser);

View File

@ -1,17 +1,14 @@
@Layer watch @Layer watch
//////////////////////////////// //- Dependencies
//~ Dependencies
@Dep base @Dep base
@Dep platform @Dep platform
//////////////////////////////// //- Api
//~ Api @IncludeC watch_core.h
@ApiC watch_core //- Impl
@IncludeC watch_core.c
//////////////////////////////// //- Startup
//~ Init @Startup W_StartupCore
@Init W_StartupCore