Basic proc gen with hash noise
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package game
|
||||
|
||||
import "core:math"
|
||||
|
||||
Vec2i :: struct {
|
||||
x: int,
|
||||
y: int,
|
||||
@@ -13,14 +15,12 @@ vec2_to_vec2i :: proc(v2:[2]f32) -> Vec2i {
|
||||
return {int(v2.x), int(v2.y)}
|
||||
}
|
||||
|
||||
to_bytes :: proc(v: $T) -> [size_of(T)]u8 {
|
||||
val := v
|
||||
encoded_bytes := (^[size_of(T)]u8)(&val)
|
||||
return encoded_bytes^
|
||||
hash_noise :: proc(x, y: int, seed: u32) -> f32 {
|
||||
h: u32 = u32(x) * 374761393
|
||||
h *= u32(y) * 668265263
|
||||
h *= seed
|
||||
h *= 3266489917
|
||||
h >>= 16
|
||||
return f32(h & 0xFFFF) / 65535.0
|
||||
}
|
||||
|
||||
from_bytes :: proc($T:typeid, data: [size_of(T)]u8) -> T {
|
||||
bytes := data
|
||||
decoded_value := (^T)(&bytes)^
|
||||
return decoded_value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user