mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Merge branch 'master' of https://github.com/odin-lang/Odin
This commit is contained in:
@@ -113,8 +113,11 @@ _buffer_grow :: proc(b: ^Buffer, n: int) -> int {
|
|||||||
if i, ok := _buffer_try_grow(b, n); ok {
|
if i, ok := _buffer_try_grow(b, n); ok {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.buf == nil && n <= SMALL_BUFFER_SIZE {
|
if b.buf == nil && n <= SMALL_BUFFER_SIZE {
|
||||||
b.buf = make([dynamic]byte, n, SMALL_BUFFER_SIZE)
|
// Fixes #2756 by preserving allocator if already set on Buffer via init_buffer_allocator
|
||||||
|
reserve(&b.buf, SMALL_BUFFER_SIZE)
|
||||||
|
resize(&b.buf, n)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+31
-11
@@ -5,6 +5,7 @@ Package core:math/rand implements various random number generators
|
|||||||
package rand
|
package rand
|
||||||
|
|
||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
|
import "core:math"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
|
||||||
Rand :: struct {
|
Rand :: struct {
|
||||||
@@ -454,13 +455,13 @@ int_max :: proc(n: int, r: ^Rand = nil) -> (val: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generates a random double floating point value in the range `(0, 1]` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
Generates a random double floating point value in the range `[0, 1)` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- r: The random number generator to use, or nil for the global generator
|
- r: The random number generator to use, or nil for the global generator
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- val: A random double floating point value in the range `(0, 1]`
|
- val: A random double floating point value in the range `[0, 1)`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
import "core:math/rand"
|
import "core:math/rand"
|
||||||
@@ -479,13 +480,13 @@ Example:
|
|||||||
@(require_results) float64 :: proc(r: ^Rand = nil) -> (val: f64) { return f64(int63_max(1<<53, r)) / (1 << 53) }
|
@(require_results) float64 :: proc(r: ^Rand = nil) -> (val: f64) { return f64(int63_max(1<<53, r)) / (1 << 53) }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generates a random single floating point value in the range `(0, 1]` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
Generates a random single floating point value in the range `[0, 1)` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- r: The random number generator to use, or nil for the global generator
|
- r: The random number generator to use, or nil for the global generator
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- val: A random single floating point value in the range `(0, 1]`
|
- val: A random single floating point value in the range `[0, 1)`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
import "core:math/rand"
|
import "core:math/rand"
|
||||||
@@ -501,10 +502,12 @@ Example:
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@(require_results) float32 :: proc(r: ^Rand = nil) -> (val: f32) { return f32(float64(r)) }
|
@(require_results) float32 :: proc(r: ^Rand = nil) -> (val: f32) { return f32(int31_max(1<<24, r)) / (1 << 24) }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generates a random double floating point value in the range `(low, high]` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
Generates a random double floating point value in the range `[low, high)` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
||||||
|
|
||||||
|
WARNING: Panics if `high < low`
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- low: The lower bounds of the value, this value is inclusive
|
- low: The lower bounds of the value, this value is inclusive
|
||||||
@@ -512,7 +515,7 @@ Inputs:
|
|||||||
- r: The random number generator to use, or nil for the global generator
|
- r: The random number generator to use, or nil for the global generator
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- val: A random double floating point value in the range `(low, high]`
|
- val: A random double floating point value in the range [low, high)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
import "core:math/rand"
|
import "core:math/rand"
|
||||||
@@ -528,10 +531,17 @@ Example:
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@(require_results) float64_range :: proc(low, high: f64, r: ^Rand = nil) -> (val: f64) { return (high-low)*float64(r) + low }
|
@(require_results) float64_range :: proc(low, high: f64, r: ^Rand = nil) -> (val: f64) {
|
||||||
|
assert(low <= high, "low must be lower than or equal to high")
|
||||||
|
val = (high-low)*float64(r) + low
|
||||||
|
if val >= high {
|
||||||
|
val = max(low, high * (1 - math.F64_EPSILON))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generates a random single floating point value in the range `(low, high]` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
Generates a random single floating point value in the range `[low, high)` using the provided random number generator. If no generator is provided the global random number generator will be used.
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- low: The lower bounds of the value, this value is inclusive
|
- low: The lower bounds of the value, this value is inclusive
|
||||||
@@ -539,7 +549,9 @@ Inputs:
|
|||||||
- r: The random number generator to use, or nil for the global generator
|
- r: The random number generator to use, or nil for the global generator
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- val: A random single floating point value in the range `(low, high]`
|
- val: A random single floating point value in the range [low, high)
|
||||||
|
|
||||||
|
WARNING: Panics if `high < low`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
import "core:math/rand"
|
import "core:math/rand"
|
||||||
@@ -555,10 +567,18 @@ Example:
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@(require_results) float32_range :: proc(low, high: f32, r: ^Rand = nil) -> (val: f32) { return (high-low)*float32(r) + low }
|
@(require_results) float32_range :: proc(low, high: f32, r: ^Rand = nil) -> (val: f32) {
|
||||||
|
assert(low <= high, "low must be lower than or equal to high")
|
||||||
|
val = (high-low)*float32(r) + low
|
||||||
|
if val >= high {
|
||||||
|
val = max(low, high * (1 - math.F32_EPSILON))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Fills a byte slice with random values using the provided random number generator. If no generator is provided the global random number generator will be used.
|
Fills a byte slice with random values using the provided random number generator. If no generator is provided the global random number generator will be used.
|
||||||
|
Due to floating point precision there is no guarantee if the upper and lower bounds are inclusive/exclusive with the exact floating point value.
|
||||||
|
|
||||||
Inputs:
|
Inputs:
|
||||||
- p: The byte slice to fill
|
- p: The byte slice to fill
|
||||||
|
|||||||
@@ -749,6 +749,7 @@ dynamic_pool_alloc_bytes :: proc(p: ^Dynamic_Pool, bytes: int) -> ([]byte, Alloc
|
|||||||
n := bytes
|
n := bytes
|
||||||
extra := p.alignment - (n % p.alignment)
|
extra := p.alignment - (n % p.alignment)
|
||||||
n += extra
|
n += extra
|
||||||
|
if n > p.block_size do return nil, .Invalid_Argument
|
||||||
if n >= p.out_band_size {
|
if n >= p.out_band_size {
|
||||||
assert(p.block_allocator.procedure != nil)
|
assert(p.block_allocator.procedure != nil)
|
||||||
memory, err := p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc,
|
memory, err := p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc,
|
||||||
|
|||||||
Vendored
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
package objc_Foundation
|
package objc_Foundation
|
||||||
|
|
||||||
foreign import "system:Foundation.framework"
|
foreign import "system:Foundation.framework"
|
||||||
|
// NOTE: Most of our bindings are reliant on Cocoa (everything under appkit) so just unconditionally import it
|
||||||
|
@(require) foreign import "system:Cocoa.framework"
|
||||||
|
|
||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
import "core:c"
|
import "core:c"
|
||||||
@@ -76,4 +78,4 @@ objc_class_internals :: struct {
|
|||||||
cache: rawptr,
|
cache: rawptr,
|
||||||
protocols: rawptr,
|
protocols: rawptr,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+10
@@ -233,6 +233,8 @@ Event :: struct {
|
|||||||
|
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
|
|
||||||
|
_key_len: int,
|
||||||
|
_code_len: int,
|
||||||
_key_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
_key_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
||||||
_code_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
_code_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
||||||
},
|
},
|
||||||
@@ -343,7 +345,15 @@ do_event_callback :: proc(user_data: rawptr, callback: proc(e: Event)) {
|
|||||||
user_data = user_data,
|
user_data = user_data,
|
||||||
callback = callback,
|
callback = callback,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
init_event_raw(&event)
|
init_event_raw(&event)
|
||||||
|
|
||||||
|
if event.kind == .Key_Up || event.kind == .Key_Down || event.kind == .Key_Press {
|
||||||
|
event.key.key = string(event.key._key_buf[:event.key._key_len])
|
||||||
|
event.key.code = string(event.key._code_buf[:event.key._code_len])
|
||||||
|
}
|
||||||
|
|
||||||
callback(event)
|
callback(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+17
-2
@@ -99,6 +99,11 @@ class WasmMemoryInterface {
|
|||||||
storeF64(addr, value) { this.mem.setFloat64(addr, value, true); }
|
storeF64(addr, value) { this.mem.setFloat64(addr, value, true); }
|
||||||
storeInt(addr, value) { this.mem.setInt32 (addr, value, true); }
|
storeInt(addr, value) { this.mem.setInt32 (addr, value, true); }
|
||||||
storeUint(addr, value) { this.mem.setUint32 (addr, value, true); }
|
storeUint(addr, value) { this.mem.setUint32 (addr, value, true); }
|
||||||
|
|
||||||
|
storeString(addr, value) {
|
||||||
|
const bytes = this.loadBytes(addr, value.length);
|
||||||
|
new TextEncoder("utf-8").encodeInto(value, bytes);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebGLInterface {
|
class WebGLInterface {
|
||||||
@@ -1384,6 +1389,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
|
|
||||||
wmi.storeUint(off(W), event_temp_data.id_ptr);
|
wmi.storeUint(off(W), event_temp_data.id_ptr);
|
||||||
wmi.storeUint(off(W), event_temp_data.id_len);
|
wmi.storeUint(off(W), event_temp_data.id_len);
|
||||||
|
wmi.storeUint(off(W), 0); // padding
|
||||||
|
|
||||||
wmi.storeF64(off(8), e.timeStamp*1e-3);
|
wmi.storeF64(off(8), e.timeStamp*1e-3);
|
||||||
|
|
||||||
@@ -1417,8 +1423,12 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
wmi.storeI16(off(2), e.button);
|
wmi.storeI16(off(2), e.button);
|
||||||
wmi.storeU16(off(2), e.buttons);
|
wmi.storeU16(off(2), e.buttons);
|
||||||
} else if (e instanceof KeyboardEvent) {
|
} else if (e instanceof KeyboardEvent) {
|
||||||
let keyOffset = off(W*2, W);
|
// Note: those strigs are constructed
|
||||||
let codeOffet = off(W*2, W);
|
// on the native side from buffers that
|
||||||
|
// are filled later, so skip them
|
||||||
|
const keyPtr = off(W*2, W);
|
||||||
|
const codePtr = off(W*2, W);
|
||||||
|
|
||||||
wmi.storeU8(off(1), e.location);
|
wmi.storeU8(off(1), e.location);
|
||||||
|
|
||||||
wmi.storeU8(off(1), !!e.ctrlKey);
|
wmi.storeU8(off(1), !!e.ctrlKey);
|
||||||
@@ -1427,6 +1437,11 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
wmi.storeU8(off(1), !!e.metaKey);
|
wmi.storeU8(off(1), !!e.metaKey);
|
||||||
|
|
||||||
wmi.storeU8(off(1), !!e.repeat);
|
wmi.storeU8(off(1), !!e.repeat);
|
||||||
|
|
||||||
|
wmi.storeI32(off(W), e.key.length)
|
||||||
|
wmi.storeI32(off(W), e.code.length)
|
||||||
|
wmi.storeString(off(16, 1), e.key);
|
||||||
|
wmi.storeString(off(16, 1), e.code);
|
||||||
} else if (e instanceof WheelEvent) {
|
} else if (e instanceof WheelEvent) {
|
||||||
wmi.storeF64(off(8), e.deltaX);
|
wmi.storeF64(off(8), e.deltaX);
|
||||||
wmi.storeF64(off(8), e.deltaY);
|
wmi.storeF64(off(8), e.deltaY);
|
||||||
|
|||||||
Reference in New Issue
Block a user