mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-14 09:52:23 -07:00
Merge remote-tracking branch 'offical/master'
This commit is contained in:
@@ -425,4 +425,97 @@ clear_soa_dynamic_array :: proc(array: ^$T/#soa[dynamic]$E) {
|
||||
@builtin
|
||||
clear_soa :: proc{
|
||||
clear_soa_dynamic_array,
|
||||
}
|
||||
}
|
||||
|
||||
// Converts soa slice into a soa dynamic array without cloning or allocating memory
|
||||
@(require_results)
|
||||
into_dynamic_soa :: proc(array: $T/#soa[]$E) -> #soa[dynamic]E {
|
||||
d: #soa[dynamic]E
|
||||
footer := raw_soa_footer_dynamic_array(&d)
|
||||
footer^ = {
|
||||
cap = len(array),
|
||||
len = 0,
|
||||
allocator = nil_allocator(),
|
||||
}
|
||||
|
||||
field_count: uintptr
|
||||
when intrinsics.type_is_array(E) {
|
||||
field_count = len(E)
|
||||
} else {
|
||||
field_count = uintptr(intrinsics.type_struct_field_count(E))
|
||||
}
|
||||
|
||||
array := array
|
||||
dynamic_data := ([^]rawptr)(&d)[:field_count]
|
||||
slice_data := ([^]rawptr)(&array)[:field_count]
|
||||
copy(dynamic_data, slice_data)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
// `unordered_remove_soa` removed the element at the specified `index`. It does so by replacing the current end value
|
||||
// with the old value, and reducing the length of the dynamic array by 1.
|
||||
//
|
||||
// Note: This is an O(1) operation.
|
||||
// Note: If you the elements to remain in their order, use `ordered_remove_soa`.
|
||||
// Note: If the index is out of bounds, this procedure will panic.
|
||||
@builtin
|
||||
unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, index: int, loc := #caller_location) #no_bounds_check {
|
||||
bounds_check_error_loc(loc, index, len(array))
|
||||
if index+1 < len(array) {
|
||||
ti := type_info_of(typeid_of(T))
|
||||
ti = type_info_base(ti)
|
||||
si := &ti.variant.(Type_Info_Struct)
|
||||
|
||||
field_count: uintptr
|
||||
when intrinsics.type_is_array(E) {
|
||||
field_count = len(E)
|
||||
} else {
|
||||
field_count = uintptr(intrinsics.type_struct_field_count(E))
|
||||
}
|
||||
|
||||
data := uintptr(array)
|
||||
for i in 0..<field_count {
|
||||
type := si.types[i].variant.(Type_Info_Pointer).elem
|
||||
|
||||
offset := rawptr((^uintptr)(data)^ + uintptr(index*type.size))
|
||||
final := rawptr((^uintptr)(data)^ + uintptr((len(array)-1)*type.size))
|
||||
mem_copy(offset, final, type.size)
|
||||
data += size_of(rawptr)
|
||||
}
|
||||
}
|
||||
raw_soa_footer_dynamic_array(array).len -= 1
|
||||
}
|
||||
|
||||
// `ordered_remove_soa` removed the element at the specified `index` whilst keeping the order of the other elements.
|
||||
//
|
||||
// Note: This is an O(N) operation.
|
||||
// Note: If you the elements do not have to remain in their order, prefer `unordered_remove_soa`.
|
||||
// Note: If the index is out of bounds, this procedure will panic.
|
||||
@builtin
|
||||
ordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, index: int, loc := #caller_location) #no_bounds_check {
|
||||
bounds_check_error_loc(loc, index, len(array))
|
||||
if index+1 < len(array) {
|
||||
ti := type_info_of(typeid_of(T))
|
||||
ti = type_info_base(ti)
|
||||
si := &ti.variant.(Type_Info_Struct)
|
||||
|
||||
field_count: uintptr
|
||||
when intrinsics.type_is_array(E) {
|
||||
field_count = len(E)
|
||||
} else {
|
||||
field_count = uintptr(intrinsics.type_struct_field_count(E))
|
||||
}
|
||||
|
||||
data := uintptr(array)
|
||||
for i in 0..<field_count {
|
||||
type := si.types[i].variant.(Type_Info_Pointer).elem
|
||||
|
||||
offset := (^uintptr)(data)^ + uintptr(index*type.size)
|
||||
length := type.size*(len(array) - index - 1)
|
||||
mem_copy(rawptr(offset), rawptr(offset + uintptr(type.size)), length)
|
||||
data += size_of(rawptr)
|
||||
}
|
||||
}
|
||||
raw_soa_footer_dynamic_array(array).len -= 1
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package runtime
|
||||
import "base:intrinsics"
|
||||
|
||||
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
WRITE :: 0x20000004
|
||||
WRITE :: 0x2000004
|
||||
STDERR :: 2
|
||||
ret := intrinsics.syscall(WRITE, STDERR, uintptr(raw_data(data)), uintptr(len(data)))
|
||||
if ret < 0 {
|
||||
|
||||
@@ -2711,6 +2711,7 @@ to_quaternion :: proc{
|
||||
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix2f16) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2721,6 +2722,7 @@ matrix2_orthonormalize_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix2f
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix2f32) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2731,6 +2733,7 @@ matrix2_orthonormalize_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix2f
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix2f64) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2748,6 +2751,7 @@ matrix2_orthonormalize :: proc{
|
||||
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix3f16) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2763,6 +2767,7 @@ matrix3_orthonormalize_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix3f
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix3f32) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2778,6 +2783,7 @@ matrix3_orthonormalize_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix3f
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix3f64) #no_bounds_check {
|
||||
r = m
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
|
||||
Vendored
+16
-7
@@ -520,6 +520,13 @@ foreign xlib {
|
||||
colors: [^]XColor,
|
||||
ncolors: i32,
|
||||
) ---
|
||||
XQueryExtension :: proc(
|
||||
display: ^Display,
|
||||
name: cstring,
|
||||
major_opcode_return: ^i32,
|
||||
first_event_return: ^i32,
|
||||
first_error_return: ^i32,
|
||||
) -> b32 ---
|
||||
XcmsQueryColor :: proc(
|
||||
display: ^Display,
|
||||
colormap: Colormap,
|
||||
@@ -1278,13 +1285,15 @@ foreign xlib {
|
||||
XEnableAccessControl :: proc(display: ^Display) ---
|
||||
XDisableAccessControl :: proc(display: ^Display) ---
|
||||
// Events
|
||||
XSelectInput :: proc(display: ^Display, window: Window, mask: EventMask) ---
|
||||
XFlush :: proc(display: ^Display) ---
|
||||
XSync :: proc(display: ^Display) ---
|
||||
XEventsQueued :: proc(display: ^Display, mode: EventQueueMode) -> i32 ---
|
||||
XPending :: proc(display: ^Display) -> i32 ---
|
||||
XNextEvent :: proc(display: ^Display, event: ^XEvent) ---
|
||||
XPeekEvent :: proc(display: ^Display, event: ^XEvent) ---
|
||||
XSelectInput :: proc(display: ^Display, window: Window, mask: EventMask) ---
|
||||
XFlush :: proc(display: ^Display) ---
|
||||
XSync :: proc(display: ^Display) ---
|
||||
XEventsQueued :: proc(display: ^Display, mode: EventQueueMode) -> i32 ---
|
||||
XPending :: proc(display: ^Display) -> i32 ---
|
||||
XNextEvent :: proc(display: ^Display, event: ^XEvent) ---
|
||||
XPeekEvent :: proc(display: ^Display, event: ^XEvent) ---
|
||||
XGetEventData :: proc(display: ^Display, cookie: ^XGenericEventCookie) -> b32 ---
|
||||
XFreeEventData :: proc(display: ^Display, cookie: ^XGenericEventCookie) ---
|
||||
// Selecting events using a predicate procedure
|
||||
XIfEvent :: proc(
|
||||
display: ^Display,
|
||||
|
||||
Vendored
+1
-1
@@ -708,7 +708,7 @@ XGenericEventCookie :: struct {
|
||||
type: EventType,
|
||||
serial: uint,
|
||||
send_event: b32,
|
||||
display: Display,
|
||||
display: ^Display,
|
||||
extension: i32,
|
||||
evtype: i32,
|
||||
cookie: u32,
|
||||
|
||||
Reference in New Issue
Block a user