formatting fix

This commit is contained in:
Matthew 2025-09-15 05:15:01 +10:00
parent 1e9d82f00e
commit 2581fcb18c
6 changed files with 162 additions and 162 deletions

View File

@ -129,7 +129,7 @@ AllocAlign(Arena* arena, u64 size, u64 alignment)
Node!(ArenaPool)* node = arena.pools.first;
while (true)
{
if (node == null)
if(node == null)
{
AddArenaPool(arena);
node = arena.pools.first;
@ -139,7 +139,7 @@ AllocAlign(Arena* arena, u64 size, u64 alignment)
current = mem_pos + node.value.pos;
offset = AlignPow2(current, alignment) - mem_pos;
if (offset+size <= arena.pool_length)
if(offset+size <= arena.pool_length)
{
break;
}
@ -190,7 +190,7 @@ Free(T)(T* ptr)
void
ResetScratch(u64 size)
{
if (!g_scratch.init)
if(!g_scratch.init)
{
g_scratch.arena = CreateArena(size);
g_scratch.init = true;

View File

@ -134,11 +134,11 @@ bool g_DIR_SET = false;
void
SetDir()
{
if (exists("assets"))
if(exists("assets"))
{
chdir("./assets");
}
else if (exists("Gears") || exists("Gears.exe"))
else if(exists("Gears") || exists("Gears.exe"))
{
chdir("../assets");
}
@ -153,7 +153,7 @@ SetDir()
u8[]
LoadAssetData(Arena* arena, string name)
{
if (!g_DIR_SET)
if(!g_DIR_SET)
{
SetDir();
}
@ -179,7 +179,7 @@ else
void
OpenAssetPack()
{
if (!Asset_Pack_Opened)
if(!Asset_Pack_Opened)
{
bool success = true;
string file_path = exists("build/assets.sgp") ? "build/assets.sgp" : "assets.sgp";
@ -215,7 +215,7 @@ OpenAssetPack()
pragma(inline) void
CheckAssetPack()
{
if (!Asset_Pack_Opened)
if(!Asset_Pack_Opened)
{
OpenAssetPack();
}
@ -231,7 +231,7 @@ GetAssetInfo(string name)
AssetInfo asset_info;
foreach(i, info; Asset_Info)
{
if (info.hash == hash)
if(info.hash == hash)
{
asset_info = info;
break;
@ -253,7 +253,7 @@ LoadAssetData(Arena* arena, string name)
foreach(i, info; Asset_Info)
{
if (info.hash == hash)
if(info.hash == hash)
{
data = AllocArray!(u8)(arena, info.length);
Asset_File.seek(info.offset);
@ -277,9 +277,9 @@ LoadAssetData(string name)
foreach(i, info; Asset_Info)
{
if (info.hash == hash)
if(info.hash == hash)
{
if (Asset_Data[i].ptr == null)
if(Asset_Data[i].ptr == null)
{
Asset_Data[i] = AllocArray!(u8)(info.length);
Asset_File.seek(info.offset);
@ -302,9 +302,9 @@ UnloadAssetData(string name)
foreach(i, info; Asset_Info)
{
if (info.hash == hash)
if(info.hash == hash)
{
if (Asset_Data[i] != null)
if(Asset_Data[i] != null)
{
FreeArray(Asset_Data[i]);
break;

16
fonts.d
View File

@ -65,7 +65,7 @@ InitFreeType()
void
CloseFreeType()
{
if (FT_LIB)
if(FT_LIB)
{
FT_Done_FreeType(FT_LIB);
}
@ -82,7 +82,7 @@ OpenFont(u8[] data)
void
CloseFont(FontFace font)
{
if (font != null)
if(font != null)
{
FT_Done_Face(font);
}
@ -116,7 +116,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
};
// TODO: proper packing algorithm
if (font != null)
if(font != null)
{
i64 f_ascent = cast(i64)(font.size.metrics.ascender >> 6);
i64 f_descent = cast(i64)(font.size.metrics.descender >> 6);
@ -133,14 +133,14 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
{
FT_Set_Char_Size(font, font_size, 0, 0, 0);
FT_Error res = FT_Load_Char(font, char_code, cast(FT_Int32)FT_LOAD_RENDER);
if (res != 0)
if(res != 0)
{
continue;
}
u32 bmp_w = font.glyph.bitmap.width;
u32 bmp_h = font.glyph.bitmap.rows;
if (max_w + bmp_w > dimension)
if(max_w + bmp_w > dimension)
{
max_h += current_h;
max_w = 0;
@ -164,7 +164,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
{
FT_Set_Char_Size(font, font_size, 0, 0, 0);
FT_Error res = FT_Load_Char(font, char_code, cast(FT_Int32)FT_LOAD_RENDER);
if (res != 0)
if(res != 0)
{
continue;
}
@ -174,7 +174,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
i32 top = font.glyph.bitmap_top;
i32 left = font.glyph.bitmap_left;
if (max_w + bmp.rows > dimension)
if(max_w + bmp.rows > dimension)
{
max_h += cast(u32)(size) + PADDING;
max_w = PADDING;
@ -217,7 +217,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
y = cast(i32)(max_h + r);
foreach(c; 0 .. bmp.width)
{
if ((c & 7) == 0)
if((c & 7) == 0)
{
bits = *buf_ptr;
buf_ptr += 1;

122
math.d
View File

@ -62,13 +62,13 @@ struct Vector(T, int N)
T y;
alias y g;
static if (N > 2)
static if(N > 2)
{
T z;
alias z b;
}
static if (N > 3)
static if(N > 3)
{
T w;
alias w a;
@ -76,7 +76,7 @@ struct Vector(T, int N)
};
}
this(Vec3, f32)(Vec3 v3, f32 f) if (N == 4 && is(T: f32))
this(Vec3, f32)(Vec3 v3, f32 f) if(N == 4 && is(T: f32))
{
x = v3.x;
y = v3.y;
@ -84,22 +84,22 @@ struct Vector(T, int N)
w = f;
}
this(Arr)(Arr arr) if (is(Arr: typeof(v)))
this(Arr)(Arr arr) if(is(Arr: typeof(v)))
{
this.v = arr;
}
this(Args...)(Args args)
{
static if (args.length == 1)
static if(args.length == 1)
{
opAssign!(Args[0])(args[0]);
}
else static if (args.length == N)
else static if(args.length == N)
{
mixin(GenerateLoop!("v[@] = args[@];", N)());
}
else static if (args.length == 2 && N == 4)
else static if(args.length == 2 && N == 4)
{
v[0] = args[0];
v[1] = args[0];
@ -112,19 +112,19 @@ struct Vector(T, int N)
}
}
ref Vector opAssign(U)(U x) if (is(U: T) || isAssignable!(T, U))
ref Vector opAssign(U)(U x) if(is(U: T) || isAssignable!(T, U))
{
mixin(GenerateLoop!("v[@] = x;", N)());
return this;
}
ref Vector opAssign(U)(U u) if (isStaticArray!(U) && U.length == N && isAssignable!(T, typeof(*U.init.ptr)))
ref Vector opAssign(U)(U u) if(isStaticArray!(U) && U.length == N && isAssignable!(T, typeof(*U.init.ptr)))
{
mixin(GenerateLoop!("v[@] = u[@];", N)());
return this;
}
ref Vector opAssign(U)(U u) if (is(U : Vector))
ref Vector opAssign(U)(U u) if(is(U : Vector))
{
v[] = u.v[];
return this;
@ -135,13 +135,13 @@ struct Vector(T, int N)
return v.ptr;
}
bool opEquals(U)(U other) if (is(U: Vector!(T, N)))
bool opEquals(U)(U other) if(is(U: Vector!(T, N)))
{
bool result = true;
foreach(i; 0 .. N)
{
if (fabsf(v[i] - other.v[i]) > 0.0000009)
if(fabsf(v[i] - other.v[i]) > 0.0000009)
{
result = false;
break;
@ -161,26 +161,26 @@ struct Vector(T, int N)
return v[];
}
Vector opUnary(string op)() if (op == "+" || op == "-" || op == "~" || op == "!")
Vector opUnary(string op)() if(op == "+" || op == "-" || op == "~" || op == "!")
{
Vector result;
mixin(GenerateLoop!("res.v[@] = " ~ op ~ " v[@];", N)());
return res;
}
ref Vector opOpAssign(string op, U)(U value) if (is(U: Vector))
ref Vector opOpAssign(string op, U)(U value) if(is(U: Vector))
{
mixin(GenerateLoop!("v[@] " ~ op ~ "= value.v[@];", N)());
return this;
}
ref Vector opOpAssign(string op, U)(U value) if (IsConvertible!(U))
ref Vector opOpAssign(string op, U)(U value) if(IsConvertible!(U))
{
Vector conv = value;
return opOpAssign!(op)(conv);
}
@property auto opDispatch(string op, U = void)() if (ValidSwizzle!(op) && op.length <= 4)
@property auto opDispatch(string op, U = void)() if(ValidSwizzle!(op) && op.length <= 4)
{
Vector!(T, op.length) result;
enum index_tuple = SwizzleTuple!(op);
@ -191,7 +191,7 @@ struct Vector(T, int N)
return result;
}
@property void opDispatch(string op, U)(U x) if ((op.length > 1) && ValidUniqueSwizzle!(op) && is(typeof(Vector!(T, op.length)(x))))
@property void opDispatch(string op, U)(U x) if((op.length > 1) && ValidUniqueSwizzle!(op) && is(typeof(Vector!(T, op.length)(x))))
{
Vector!(T, op.length) conv = x;
enum index_tuple = SwizzleTuple!(op);
@ -201,9 +201,9 @@ struct Vector(T, int N)
}
}
static if (N == 4)
static if(N == 4)
{
Vector opBinary(string op, U)(U operand) if ((is(U: Vector!(f32, 4)) && is(T: f32)) && (op == "*" || op == "+" || op == "-" || op == "/"))
Vector opBinary(string op, U)(U operand) if((is(U: Vector!(f32, 4)) && is(T: f32)) && (op == "*" || op == "+" || op == "-" || op == "/"))
{
Vector result;
f32* l = &x;
@ -218,10 +218,10 @@ struct Vector(T, int N)
movups XMM0, x.offsetof[R8];
movups XMM1, operand.x.offsetof[R9];
}
static if (op == "*") asm { mulps XMM0, XMM1; }
else static if (op == "-") asm { subps XMM0, XMM1; }
else static if (op == "+") asm { addps XMM0, XMM1; }
else static if (op == "/") asm { divps XMM0, XMM1; }
static if(op == "*") asm { mulps XMM0, XMM1; }
else static if(op == "-") asm { subps XMM0, XMM1; }
else static if(op == "+") asm { addps XMM0, XMM1; }
else static if(op == "/") asm { divps XMM0, XMM1; }
asm
{
movups result.x.offsetof[R10], XMM0;
@ -230,7 +230,7 @@ struct Vector(T, int N)
return result;
}
Vector opBinary(string op, U)(U operand) if (IsConvertible!(U) && (op == "*" || op == "+" || op == "-" || op == "/"))
Vector opBinary(string op, U)(U operand) if(IsConvertible!(U) && (op == "*" || op == "+" || op == "-" || op == "/"))
{
Vector result;
Vector other = operand;
@ -246,10 +246,10 @@ struct Vector(T, int N)
movups XMM0, x.offsetof[R8];
movups XMM1, other.x.offsetof[R9];
}
static if (op == "*") asm { mulps XMM0, XMM1; }
else static if (op == "-") asm { subps XMM0, XMM1; }
else static if (op == "+") asm { addps XMM0, XMM1; }
else static if (op == "/") asm { divps XMM0, XMM1; }
static if(op == "*") asm { mulps XMM0, XMM1; }
else static if(op == "-") asm { subps XMM0, XMM1; }
else static if(op == "+") asm { addps XMM0, XMM1; }
else static if(op == "/") asm { divps XMM0, XMM1; }
asm
{
movups result.x.offsetof[R8], XMM0;
@ -260,14 +260,14 @@ struct Vector(T, int N)
}
else
{
Vector opBinary(string op, U)(U operand) if (is(U: Vector) && U._N == N && (op == "*" || op == "+" || op == "-" || op == "/"))
Vector opBinary(string op, U)(U operand) if(is(U: Vector) && U._N == N && (op == "*" || op == "+" || op == "-" || op == "/"))
{
Vector res;
mixin(GenerateLoop!("res.v[@] = v[@] " ~ op ~ " operand.v[@];", N)());
return res;
}
Vector opBinary(string op, U)(U operand) if (IsConvertible!(U) && (op == "*" || op == "+" || op == "-" || op == "/"))
Vector opBinary(string op, U)(U operand) if(IsConvertible!(U) && (op == "*" || op == "+" || op == "-" || op == "/"))
{
Vector res;
Vector other = operand;
@ -288,7 +288,7 @@ struct Vector(T, int N)
return v[i] = x;
}
U opCast(U)() if (IsVector!(U) && (U._N == _N))
U opCast(U)() if(IsVector!(U) && (U._N == _N))
{
U result;
mixin(GenerateLoop!("res.v[@] = cast(U._T)v[@];", N)());
@ -302,13 +302,13 @@ struct Vector(T, int N)
template SwizzleIndex(char c)
{
static if ((c == 'x' || c == 'r') && N > 0)
static if((c == 'x' || c == 'r') && N > 0)
enum SwizzleIndex = 0;
else static if ((c == 'y' || c == 'g') && N > 1)
else static if((c == 'y' || c == 'g') && N > 1)
enum SwizzleIndex = 1;
else static if ((c == 'z' || c == 'b') && N > 2)
else static if((c == 'z' || c == 'b') && N > 2)
enum SwizzleIndex = 2;
else static if ((c == 'w' || c == 'a') && N > 3)
else static if((c == 'w' || c == 'a') && N > 3)
enum SwizzleIndex = 3;
else
enum SwizzleIndex = -1;
@ -316,9 +316,9 @@ struct Vector(T, int N)
template SwizzleSet(char c)
{
static if (c == 'x' || c == 'y' || c == 'z' || c == 'w')
static if(c == 'x' || c == 'y' || c == 'z' || c == 'w')
enum SwizzleSet = 0;
else static if (c == 'r' || c == 'g' || c == 'b' || c == 'a')
else static if(c == 'r' || c == 'g' || c == 'b' || c == 'a')
enum SwizzleSet = 1;
else
enum SwizzleSet = -1;
@ -327,7 +327,7 @@ struct Vector(T, int N)
template SwizzleTuple(string op)
{
enum op_length = op.length;
static if (op.length == 0)
static if(op.length == 0)
enum SwizzleTuple = [];
else
enum SwizzleTuple = [ SwizzleIndex!(op[0])] ~ SwizzleTuple!(op[1 .. op.length]);
@ -335,7 +335,7 @@ struct Vector(T, int N)
template SearchString(char c, string s)
{
static if (s.length == 0)
static if(s.length == 0)
{
enum bool result = false;
}
@ -348,7 +348,7 @@ struct Vector(T, int N)
template UniqueChars(string s)
{
static if (s.length == 1)
static if(s.length == 1)
{
enum bool result = true;
}
@ -361,7 +361,7 @@ struct Vector(T, int N)
template ValidSwizzle(string op, int last_swizzle = -1)
{
static if (op.length == 0)
static if(op.length == 0)
{
enum bool ValidSwizzle = true;
}
@ -376,7 +376,7 @@ struct Vector(T, int N)
template ValidUniqueSwizzle(string op)
{
static if (ValidSwizzle!(op))
static if(ValidSwizzle!(op))
{
enum ValidUniqueSwizzle = UniqueChars!(op).result;
}
@ -404,23 +404,23 @@ align(16) struct Matrix(T, int D)
T[N] v = 0;
Row[D] rows;
MatrixVec[D] vec;
static if (D == 4) mat4 glm_mat;
static if (D == 3) mat3 glm_mat;
static if (D == 2) mat2 glm_mat;
static if(D == 4) mat4 glm_mat;
static if(D == 3) mat3 glm_mat;
static if(D == 2) mat2 glm_mat;
}
// TODO: setup
this(U...)(U values)
{
static if ((U.length == N) && allSatisfy!(IsTypeAssignable, U))
static if((U.length == N) && allSatisfy!(IsTypeAssignable, U))
{
static foreach(i, x; values)
{
v[i] = x;
}
}
else static if ((U.length == 1) && (isAssignable!(U[0])) && (!is(U[0] : Matrix)))
else static if((U.length == 1) && (isAssignable!(U[0])) && (!is(U[0] : Matrix)))
{
v[] = values[0];
}
@ -460,7 +460,7 @@ align(16) struct Matrix(T, int D)
return this;
}
ref Matrix opAssign(U)(U x) if (IsMatrixInstantiation!(U) && is(U._T : _T) && (!is(U: Matrix) && (U.N != N)))
ref Matrix opAssign(U)(U x) if(IsMatrixInstantiation!(U) && is(U._T : _T) && (!is(U: Matrix) && (U.N != N)))
{
static foreach(i; 0 .. N)
{
@ -480,13 +480,13 @@ align(16) struct Matrix(T, int D)
return v[(i * D) + j] = x;
}
bool opEquals(U)(U other) if (is(U: Matrix!(T, D)))
bool opEquals(U)(U other) if(is(U: Matrix!(T, D)))
{
bool result = true;
static foreach(i; 0 .. N)
{
if (fabsf(this.v[i] - other.v[i]) > 0.0000009)
if(fabsf(this.v[i] - other.v[i]) > 0.0000009)
{
result = false;
}
@ -495,7 +495,7 @@ align(16) struct Matrix(T, int D)
return result;
}
Matrix opBinary(string op)(T scalar) if (op == "*")
Matrix opBinary(string op)(T scalar) if(op == "*")
{
Matrix result;
@ -507,16 +507,16 @@ align(16) struct Matrix(T, int D)
return result;
}
static if (D == 4)
static if(D == 4)
{
Vec4 opBinary(string op, U)(U x) if (is(U: Vec4) && is(T: f32) && (op == "*"))
Vec4 opBinary(string op, U)(U x) if(is(U: Vec4) && is(T: f32) && (op == "*"))
{
Vec4 result = 0.0;
glm_mat4_mulv(glm_mat.ptr, x.v.ptr, result.v.ptr);
return result;
}
Matrix opBinary(string op, U)(U x) if (is(U: Matrix!(T, D)) && is(T: f32) && D == 4 && (op == "*"))
Matrix opBinary(string op, U)(U x) if(is(U: Matrix!(T, D)) && is(T: f32) && D == 4 && (op == "*"))
{
Matrix result;
MatZero(&result);
@ -563,14 +563,14 @@ struct Quat
vec.w = w;
}
U opCast(U)() if (is(U: Mat4))
U opCast(U)() if(is(U: Mat4))
{
Mat4 result;
glm_quat_mat4(vec.ptr, result.glm_mat.ptr);
return result;
}
Quat opBinary(string op, U)(U r) if (op == "*" && is(U: Quat))
Quat opBinary(string op, U)(U r) if(op == "*" && is(U: Quat))
{
Quat q;
@ -778,11 +778,11 @@ Norm(Vec4* v)
}
pragma(inline) void
Normalize(T)(T* vec) if (is(T: Vec2) || is(T: Vec3) || is(T: Vec4))
Normalize(T)(T* vec) if(is(T: Vec2) || is(T: Vec3) || is(T: Vec4))
{
f32 length = Norm(vec);
if (length < f32.epsilon)
if(length < f32.epsilon)
{
mixin(GenerateLoop!("vec.v[@] = 0.0;", vec._N)());
}
@ -793,7 +793,7 @@ Normalize(T)(T* vec) if (is(T: Vec2) || is(T: Vec3) || is(T: Vec4))
}
pragma(inline) T
Normalize(T)(T vec) if (is(T: Vec2) || is(T: Vec3) || is(T: Vec4))
Normalize(T)(T vec) if(is(T: Vec2) || is(T: Vec3) || is(T: Vec4))
{
Normalize(&vec);
return vec;
@ -804,7 +804,7 @@ Normalize(Quat q)
{
f32 dot = Norm(&q.vec);
if (dot <= 0.0)
if(dot <= 0.0)
{
q = Quat(1.0, 0.0, 0.0, 0.0);
}
@ -968,7 +968,7 @@ unittest
{
foreach(i; 0 .. mat.N)
{
if (i % 4 == 0)
if(i % 4 == 0)
{
printf("\n");
}

View File

@ -187,7 +187,7 @@ struct MessageQueue
MessageQueue
CreateMessageQueue()
{
if (g_NIL_MSG == null)
if(g_NIL_MSG == null)
{
g_NIL_MSG = cast(DNode!(SysMessage)*)&g_sys_message;
}
@ -232,7 +232,7 @@ Push(PlatformWindow* w, SysMessageType msg)
Lock(&w.msg_queue.mut);
DNode!(SysMessage)* node = g_NIL_MSG;
if (Nil(w.msg_queue.free_list.first))
if(Nil(w.msg_queue.free_list.first))
{
node = Alloc!(DNode!(SysMessage))(&w.msg_queue.arena);
}
@ -533,7 +533,7 @@ LockCursor(PlatformWindow* window)
{
bool result = window.locked_cursor;
if (!window.locked_cursor)
if(!window.locked_cursor)
{
u32 counter = 0;
for(;;)
@ -548,13 +548,13 @@ LockCursor(PlatformWindow* window)
pureFree(grab_reply);
}
if (grab_reply.status == XCB_GRAB_STATUS_SUCCESS)
if(grab_reply.status == XCB_GRAB_STATUS_SUCCESS)
{
result = true;
break;
}
if (counter > 5)
if(counter > 5)
{
break;
}
@ -573,7 +573,7 @@ LockCursor(PlatformWindow* window)
void
UnlockCursor(PlatformWindow* window)
{
if (window.locked_cursor)
if(window.locked_cursor)
{
xcb_ungrab_pointer(window.conn, XCB_CURRENT_TIME);
ShowCursor(window);
@ -619,14 +619,14 @@ HandleEvents(void* window_ptr)
for(;;)
{
if (w.close)
if(w.close)
{
Kill();
}
sys_msg = Pop(&w.msg_queue);
if (!Nil(sys_msg))
if(!Nil(sys_msg))
{
SysMessage msg = sys_msg.value;
@ -640,7 +640,7 @@ HandleEvents(void* window_ptr)
{
for(u64 i = 0; i < 5; i += 1)
{
if (LockCursor(w))
if(LockCursor(w))
{
break;
}
@ -654,7 +654,7 @@ HandleEvents(void* window_ptr)
{
for (u64 i = 0; i < 5; i += 1)
{
if (HideCursor(w))
if(HideCursor(w))
{
break;
}
@ -664,7 +664,7 @@ HandleEvents(void* window_ptr)
{
for(u64 i = 0; i < 5; i += 1)
{
if (ShowCursor(w))
if(ShowCursor(w))
{
break;
}
@ -676,7 +676,7 @@ HandleEvents(void* window_ptr)
e = xcb_poll_for_event(w.conn);
if (e)
if(e)
{
Inputs* inputs = GetInputs(w);
@ -685,12 +685,12 @@ HandleEvents(void* window_ptr)
case XCB_CLIENT_MESSAGE:
{
xcb_client_message_event_t* msg = cast(xcb_client_message_event_t*)e;
if (msg.window != w.window)
if(msg.window != w.window)
{
break;
}
if (msg.data.data32[0] == w.close_event)
if(msg.data.data32[0] == w.close_event)
{
w.close = true;
}
@ -709,13 +709,13 @@ HandleEvents(void* window_ptr)
static foreach(md; modifiers)
{
if (input == md)
if(input == md)
{
w.modifier = cast(Modifier)(pressed ? (w.modifier | md) : (w.modifier & ~md));
}
}
if (input != Input.None)
if(input != Input.None)
{
Push(inputs, input, keyboard_event.event_x, keyboard_event.event_y, pressed, w.modifier);
}
@ -735,14 +735,14 @@ HandleEvents(void* window_ptr)
default: break;
}
if (input != Input.None)
if(input != Input.None)
{
Push(inputs, input, mouse_event.event_x, mouse_event.event_y, pressed, w.modifier);
}
} break;
case XCB_MOTION_NOTIFY:
{
if (ignore_mouse_events) continue;
if(ignore_mouse_events) continue;
xcb_motion_notify_event_t* move_event = cast(xcb_motion_notify_event_t*)e;
@ -750,14 +750,14 @@ HandleEvents(void* window_ptr)
i16 y = move_event.event_y;
static bool first = true;
if (first)
if(first)
{
w.mouse_prev_x = x;
w.mouse_prev_y = y;
first = false;
}
if (x > 0 || y > 0)
if(x > 0 || y > 0)
{
PushMotion(inputs, w.mouse_prev_x-x, w.mouse_prev_y-y, x, y);
}
@ -765,7 +765,7 @@ HandleEvents(void* window_ptr)
w.mouse_prev_x = x;
w.mouse_prev_y = y;
if (w.locked_cursor &&
if(w.locked_cursor &&
(x < WINDOW_EDGE_BUFFER || y < WINDOW_EDGE_BUFFER || x > w.w - WINDOW_EDGE_BUFFER || y > w.h - WINDOW_EDGE_BUFFER))
{
i16 new_x = cast(i16)(w.w / 2);
@ -779,7 +779,7 @@ HandleEvents(void* window_ptr)
case XCB_CONFIGURE_NOTIFY:
{
xcb_configure_notify_event_t* config_event = cast(xcb_configure_notify_event_t*)e;
if (w.w != config_event.width || w.h != config_event.height)
if(w.w != config_event.width || w.h != config_event.height)
{
w.w = config_event.width;
w.h = config_event.height;
@ -1008,7 +1008,7 @@ WatchDirectory(string dir, WatchType type, bool blocking = false)
watcher.handle = inotify_init();
assert(watcher.dir_handle >= 0, "WatchDirectory failure: unable to initialize");
if (!blocking)
if(!blocking)
{
fcntl(watcher.handle, F_SETFL, fcntl(watcher.handle, F_GETFL) | O_NONBLOCK);
}
@ -1028,7 +1028,7 @@ ViewChanges(Watcher* watcher)
WatchEvent[] events;
i64 length = read(watcher.handle, watcher.buffer.ptr, watcher.buffer.length);
if (length > 0)
if(length > 0)
{
i64 count = 0;
i64 i = 0;
@ -1042,7 +1042,7 @@ ViewChanges(Watcher* watcher)
i += inotify_event.sizeof + event.len;
}
if (count > 0)
if(count > 0)
{
struct Moved
{
@ -1059,36 +1059,36 @@ ViewChanges(Watcher* watcher)
while (i < length)
{
inotify_event* event = (cast(inotify_event*)(watcher.buffer.ptr + i));
if (event.len > 0)
if(event.len > 0)
{
u8[] file_name = (cast(u8*)event.name)[0 .. strlen(event.name.ptr)];
if (event.mask & IN_MOVED_FROM || event.mask & IN_MOVED_TO)
if(event.mask & IN_MOVED_FROM || event.mask & IN_MOVED_TO)
{
bool from = (event.mask & IN_MOVED_FROM) > 0;
Moved* m;
foreach(j; 0 .. m_count)
{
if (moved[j].cookie == event.cookie)
if(moved[j].cookie == event.cookie)
{
m = moved.ptr + j;
}
}
if (m != null)
if(m != null)
{
if (from && m.to >= 0)
if(from && m.to >= 0)
{
events[m.to].names[0] = file_name;
if (watcher.watched_dir == file_name)
if(watcher.watched_dir == file_name)
{
events[m.to].type &= ~(WET.File | WET.Dir);
events[m.to].type |= WET.Self;
}
}
else if (!from && m.from >= 0)
else if(!from && m.from >= 0)
{
events[m.from].names[1] = file_name;
}
@ -1101,13 +1101,13 @@ ViewChanges(Watcher* watcher)
moved[m_count].cookie = event.cookie;
if (from)
if(from)
{
ev.names[0] = file_name;
moved[m_count].from = count;
moved[m_count].to = -1;
if (watcher.watched_dir == file_name)
if(watcher.watched_dir == file_name)
{
ev.type &= ~(WET.File | WET.Dir);
ev.type |= WET.Self;
@ -1130,7 +1130,7 @@ ViewChanges(Watcher* watcher)
ev.type = (event.mask & IN_ISDIR) ? WET.Dir : WET.File;
ev.names[0] = file_name;
if (ev.names[0] == watcher.watched_dir)
if(ev.names[0] == watcher.watched_dir)
{
ev.type = WET.Self;
}
@ -1161,23 +1161,23 @@ ViewChanges(Watcher* watcher)
void
SetEventType(WatchEvent* ev, u32 mask)
{
if (mask & IN_ACCESS)
if(mask & IN_ACCESS)
{
ev.type |= WET.Accessed;
}
else if (mask & IN_ATTRIB)
else if(mask & IN_ATTRIB)
{
ev.type |= WET.Metadata;
}
else if (mask & IN_CREATE)
else if(mask & IN_CREATE)
{
ev.type |= WET.Created;
}
else if (mask & IN_MODIFY)
else if(mask & IN_MODIFY)
{
ev.type |= WET.Modified;
}
else if (mask & IN_DELETE)
else if(mask & IN_DELETE)
{
ev.type |= WET.Deleted;
}

78
util.d
View File

@ -75,7 +75,7 @@ GB(u64 v)
pragma(inline) void
ConvertColor(Vec4 *dst, u32 src)
{
if (src == 0)
if(src == 0)
{
dst.rgb = 0.0;
dst.a = 1.0;
@ -117,9 +117,9 @@ struct DLList(T)
void
ConcatInPlace(T)(T* list, T* to_concat)
{
if (to_concat.first)
if(to_concat.first)
{
if (list.first)
if(list.first)
{
list.last.next = to_concat.first;
list.last = to_concat.last;
@ -139,7 +139,7 @@ DLLPop(T, U)(T* list, U* nil)
{
U* node = list.first;
if (list.first == list.last)
if(list.first == list.last)
{
list.first = list.last = nil;
}
@ -155,16 +155,16 @@ DLLPop(T, U)(T* list, U* nil)
void
DLLRemove(T, U)(T* list, U* node, U* nil)
{
if (list.first == list.last)
if(list.first == list.last)
{
list.first = list.last = nil;
}
else if (list.first == node)
else if(list.first == node)
{
list.first = node.next;
list.first.prev = nil;
}
else if (list.last == node)
else if(list.last == node)
{
node.prev.next = nil;
list.last = node.prev;
@ -181,7 +181,7 @@ DLLPushFront(T, U)(T* list, U* node, U* nil)
{
node.prev = node.next = nil;
if (CheckNil(nil, list.first))
if(CheckNil(nil, list.first))
{
list.first = list.last = node;
}
@ -199,7 +199,7 @@ DLLPush(T, U)(T* list, U* node, U* nil)
{
node.prev = node.next = nil;
if (CheckNil(nil, list.first))
if(CheckNil(nil, list.first))
{
list.first = list.last = node;
}
@ -223,7 +223,7 @@ void
SPush(T)(Arena* arena, Stack!(T)* stack, T value)
{
Node!(T)* node;
if (!CheckNil(stack.nil, stack.free))
if(!CheckNil(stack.nil, stack.free))
{
node = stack.free;
stack.free = node.next;
@ -235,7 +235,7 @@ SPush(T)(Arena* arena, Stack!(T)* stack, T value)
node.value = value;
if (CheckNil(stack.nil, stack.top))
if(CheckNil(stack.nil, stack.top))
{
stack.top = node;
node.next = stack.nil;
@ -252,7 +252,7 @@ SPop(T)(Stack!(T)* stack)
{
T result;
if (!CheckNil(stack.nil, stack.top))
if(!CheckNil(stack.nil, stack.top))
{
result = stack.top.value;
@ -288,7 +288,7 @@ SLLPop(T, U)(T* list, U* nil)
{
U* node = list.first;
if (list.first == list.last)
if(list.first == list.last)
{
list.first = list.last = nil;
}
@ -303,15 +303,15 @@ SLLPop(T, U)(T* list, U* nil)
pragma(inline) void
SLLRemove(T, U)(T* list, U* node, U* prev, U* nil)
{
if (list.first == list.last)
if(list.first == list.last)
{
list.first = list.last = nil;
}
else if (list.first == node)
else if(list.first == node)
{
list.first = node.next;
}
else if (list.last == node)
else if(list.last == node)
{
list.last = prev;
prev.next = nil;
@ -327,7 +327,7 @@ SLLPushFront(T, U)(T* list, U* node, U* nil)
{
node.next = nil;
if (CheckNil(nil, list.first))
if(CheckNil(nil, list.first))
{
list.first = list.last = node;
}
@ -343,7 +343,7 @@ SLLPush(T, U)(T* list, U* node, U* nil)
{
node.next = nil;
if (CheckNil(nil, list.first))
if(CheckNil(nil, list.first))
{
list.first = list.last = node;
}
@ -388,7 +388,7 @@ struct HashTable(K, V)
P* pair = Search(&this, key);
Result!(V) result = { ok: false };
if (pair != null)
if(pair != null)
{
result.value = pair.value;
result.ok = true;
@ -443,7 +443,7 @@ Push(K, V)(HashTable!(K, V)* ht, K key, V value)
N* node = ht.nil;
if (!CheckNil(ht.nil, ht.free_lists.first))
if(!CheckNil(ht.nil, ht.free_lists.first))
{
node = SLLPop(&ht.free_lists, ht.nil);
}
@ -471,7 +471,7 @@ Search(K, V)(HashTable!(K, V)* ht, K key)
auto list = GetList(ht, key);
for(auto node = list.first; !CheckNil(ht.nil, node); node = node.next)
{
if (node.value.key == key)
if(node.value.key == key)
{
result = &node.value;
break;
@ -498,7 +498,7 @@ Delete(K, V)(HashTable!(K, V)* ht, K key)
auto prev = ht.nil;
for(auto node = list.first; !CheckNil(ht.nil, node); node = node.next)
{
if (node.value.key == key)
if(node.value.key == key)
{
Remove(list, node, prev, ht.nil);
@ -549,19 +549,19 @@ Hash(void* ptr_1, u64 len_1, void* ptr_2, u64 len_2)
}
pragma(inline) u64
Hash(T, U)(T value_1, U value_2) if (isArray!(T) && isArray!(U))
Hash(T, U)(T value_1, U value_2) if(isArray!(T) && isArray!(U))
{
return Hash(value_1.ptr, value_1.length*T.sizeof, value_2.ptr, value_2.length*U.sizeof);
}
pragma(inline) u64
Hash(T, U)(T value_1, U value_2) if (isArray!(T) && !isArray!(U))
Hash(T, U)(T value_1, U value_2) if(isArray!(T) && !isArray!(U))
{
return Hash(value_1.ptr, value_1.length*value_1[0].sizeof, &value_2, U.sizeof);
}
pragma(inline) u64
Hash(T, U)(T value_1, U value_2) if (!isArray!(T) && !isArray!(U))
Hash(T, U)(T value_1, U value_2) if(!isArray!(T) && !isArray!(U))
{
return Hash(&value_1, T.sizeof, &value_2, U.sizeof);
}
@ -651,7 +651,7 @@ CreateTimer(u64 fps)
u64 cpu_end = RDTSC();
u64 cpu_elapsed = cpu_end - cpu_start;
u64 cpu_freq = 0;
if (os_elapsed)
if(os_elapsed)
{
cpu_freq = os_freq * cpu_elapsed / os_elapsed;
}
@ -668,7 +668,7 @@ CheckTimer(IntervalTimer* t)
{
bool result = false;
u64 time = RDTSC();
if (time - t.prev > t.interval)
if(time - t.prev > t.interval)
{
result = true;
t.prev = time;
@ -705,7 +705,7 @@ CreateTimer()
u64 cpu_end = RDTSC();
u64 cpu_elapsed = cpu_end - cpu_start;
u64 cpu_freq = 0;
if (os_elapsed)
if(os_elapsed)
{
cpu_freq = os_freq * cpu_elapsed / os_elapsed;
}
@ -733,7 +733,7 @@ IntToStr(int n) nothrow pure @safe
string result;
static immutable string[] table = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
if (n < table.length)
if(n < table.length)
{
result = table[n];
}
@ -763,7 +763,7 @@ MemCpy(void* dst_p, void* src_p, u64 length)
u8* src = cast(u8*)src_p;
u64 remaining = length;
if (remaining >= 64)
if(remaining >= 64)
{
for(u64 i = 0; i + 64 < length; i += 64)
{
@ -789,7 +789,7 @@ MemCpy(void* dst_p, void* src_p, u64 length)
}
}
if (remaining >= 32)
if(remaining >= 32)
{
for(u64 i = length - remaining; i + 32 < length; i += 32)
{
@ -811,7 +811,7 @@ MemCpy(void* dst_p, void* src_p, u64 length)
}
}
if (remaining > 0)
if(remaining > 0)
{
dst[length-remaining .. length] = src[length-remaining .. length];
}
@ -855,7 +855,7 @@ unittest
assert(n != null);
assert(v == n.value);
if (i == result.length-1)
if(i == result.length-1)
{
assert(n.next == null);
assert(n == list.last);
@ -892,12 +892,12 @@ unittest
assert(n != null);
assert(v == n.value);
if (i > 0)
if(i > 0)
{
assert(n.prev != null);
}
if (i == result.length-1)
if(i == result.length-1)
{
assert(n.next == null);
assert(n == list.last);
@ -912,12 +912,12 @@ unittest
assert(n != null);
assert(v == n.value);
if (i == result.length-1)
if(i == result.length-1)
{
assert(n.next == null);
}
if (i == 0)
if(i == 0)
{
assert(n.prev == null);
assert(n == list.first);
@ -989,7 +989,7 @@ unittest
u32 count = 0;
foreach(i, v; test_bytes[100 .. 132])
{
if (v != bytes[count])
if(v != bytes[count])
{
Logf("Failed %d %d %d", i, v, bytes[count]);
assert(false);
@ -1018,7 +1018,7 @@ unittest
foreach(i, v; test_bytes[0 .. 96])
{
if (v != bytes[i])
if(v != bytes[i])
{
assert(false);
}