diff options
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 32 | ||||
| -rw-r--r-- | code/game.odin | 7 | ||||
| -rw-r--r-- | code/math.odin | 180 |
3 files changed, 6 insertions, 213 deletions
diff --git a/code/demo.odin b/code/demo.odin index ee353c884..a72fbea6a 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,32 +1,6 @@ -x: i64 = 123 - -Vec2 :: struct { - x, y: i64 -} - +#import "fmt.odin" +#import "game.odin" main :: proc() { - foo :: proc() -> i64 { - bar :: proc() -> (i64, i64) { - a := [3]i64{7, 4, 2} - v := Vec2{a[0], 2} - return v.x, v.y - } - - x, y := bar() - - return x + y - } - - test :: proc(s: string) -> string { - return s - } - - foo() - x = test("Hello").count as i64 - xp := ^x - p := xp^ - - z := [..]i64{1, 2, 3, 4} - z[0] = p + fmt.println("Hellope, everybody!") } diff --git a/code/game.odin b/code/game.odin index 31b6b28f1..c5d0c52f2 100644 --- a/code/game.odin +++ b/code/game.odin @@ -107,9 +107,7 @@ make_window :: proc(title: string, msg, height: int, window_proc: win32.WNDPROC) 0, // NOTE(bill): tells the proc that this is the end of attribs } - wgl_string := "wglCreateContextAttribsARB\x00" - c_wgl_string := ^wgl_string[0] - wglCreateContextAttribsARB := wglGetProcAddress(c_wgl_string) as wglCreateContextAttribsARBType + wglCreateContextAttribsARB := wglGetProcAddress(("wglCreateContextAttribsARB\x00" as string).data) as wglCreateContextAttribsARBType w.rc = wglCreateContextAttribsARB(w.dc, 0, ^attribs[0]) wglMakeCurrent(w.dc, w.rc) SwapBuffers(w.dc) @@ -145,6 +143,7 @@ run :: proc() { } defer destroy_window(^window) + gl.init() prev_time := time_now() @@ -205,7 +204,7 @@ run :: proc() { gl.Color3f(1, 0, 0); gl.Vertex3f(x, y, 0) } - draw_rect(pos[0], pos[1], 50, 50) + draw_rect(pos.x, pos.y, 50, 50) display_window(^window) ms_to_sleep := (16 - 1000*dt) as i32 diff --git a/code/math.odin b/code/math.odin deleted file mode 100644 index e9554f6b5..000000000 --- a/code/math.odin +++ /dev/null @@ -1,180 +0,0 @@ -TAU :: 6.28318530717958647692528676655900576 -PI :: 3.14159265358979323846264338327950288 -ONE_OVER_TAU :: 0.636619772367581343075535053490057448 -ONE_OVER_PI :: 0.159154943091895335768883763372514362 - -E :: 2.71828182845904523536 -SQRT_TWO :: 1.41421356237309504880168872420969808 -SQRT_THREE :: 1.73205080756887729352744634150587236 -SQRT_FIVE :: 2.23606797749978969640917366873127623 - -LOG_TWO :: 0.693147180559945309417232121458176568 -LOG_TEN :: 2.30258509299404568401799145468436421 - -EPSILON :: 1.19209290e-7 - -τ :: TAU -π :: PI - -// Vec2 :: type raw_union { -// using xy_: struct {x, y: f32} -// v: {2}f32 -// e: [2]f32 -// } -// Vec3 :: type raw_union { -// using xyz_: struct {x, y, z: f32} -// xy: Vec2 -// v: {3}f32 -// e: [3]f32 -// } -// Vec4 :: type raw_union { -// using xyzw_: struct {x, y, z, w: f32} -// xy: Vec2 -// xyz: Vec3 -// v: {4}f32 -// e: [4]f32 -// } -Vec2 :: type {2}f32 -Vec3 :: type {3}f32 -Vec4 :: type {4}f32 - -Mat2 :: type {4}f32 -Mat3 :: type {9}f32 -Mat4 :: type {16}f32 - - -sqrt32 :: proc(x: f32) -> f32 #foreign "llvm.sqrt.f32" -sqrt64 :: proc(x: f64) -> f64 #foreign "llvm.sqrt.f64" - -sin32 :: proc(x: f32) -> f32 #foreign "llvm.sin.f32" -sin64 :: proc(x: f64) -> f64 #foreign "llvm.sin.f64" - -cos64 :: proc(x: f64) -> f64 #foreign "llvm.cos.f64" -cos32 :: proc(x: f32) -> f32 #foreign "llvm.cos.f32" - -lerp32 :: proc(a, b, t: f32) -> f32 { return a*(1-t) + b*t } -lerp64 :: proc(a, b, t: f64) -> f64 { return a*(1-t) + b*t } - -clamp32 :: proc(x, lower, upper: f32) -> f32 { return min(max(x, lower), upper) } -clamp64 :: proc(x, lower, upper: f64) -> f64 { return min(max(x, lower), upper) } - -sign32 :: proc(x: f32) -> f32 { if x >= 0 { return +1 } return -1 } -sign64 :: proc(x: f64) -> f64 { if x >= 0 { return +1 } return -1 } - - - -copy_sign :: proc(x, y: f32) -> f32 { - ix := x transmute u32 - iy := y transmute u32 - ix &= 0x7fffffff - ix |= iy & 0x80000000 - return ix transmute f32 -} -round :: proc(x: f32) -> f32 { - if x >= 0 { - return floor(x + 0.5) - } - return ceil(x - 0.5) -} -floor :: proc(x: f32) -> f32 { - if x >= 0 { - return x as int as f32 - } - return (x-0.5) as int as f32 -} -ceil :: proc(x: f32) -> f32 { - if x < 0 { - return x as int as f32 - } - return ((x as int)+1) as f32 -} - -remainder :: proc(x, y: f32) -> f32 { - return x - round(x/y) * y -} - -fmod :: proc(x, y: f32) -> f32 { - y = abs(y) - result := remainder(abs(x), y) - if sign32(result) < 0 { - result += y - } - return copy_sign(result, x) -} - - -to_radians :: proc(degrees: f32) -> f32 { return degrees * TAU / 360 } -to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU } - - - - -dot2 :: proc(a, b: Vec2) -> f32 { c := a*b; return c[0] + c[1] } -dot3 :: proc(a, b: Vec3) -> f32 { c := a*b; return c[0] + c[1] + c[2] } -dot4 :: proc(a, b: Vec4) -> f32 { c := a*b; return c[0] + c[1] + c[2] + c[3] } - -cross :: proc(x, y: Vec3) -> Vec3 { - a := swizzle(x, 1, 2, 0) * swizzle(y, 2, 0, 1) - b := swizzle(x, 2, 0, 1) * swizzle(y, 1, 2, 0) - return a - b -} - - -vec2_mag :: proc(v: Vec2) -> f32 { return sqrt32(dot2(v, v)) } -vec3_mag :: proc(v: Vec3) -> f32 { return sqrt32(dot3(v, v)) } -vec4_mag :: proc(v: Vec4) -> f32 { return sqrt32(dot4(v, v)) } - -vec2_norm :: proc(v: Vec2) -> Vec2 { return v / Vec2{vec2_mag(v)} } -vec3_norm :: proc(v: Vec3) -> Vec3 { return v / Vec3{vec3_mag(v)} } -vec4_norm :: proc(v: Vec4) -> Vec4 { return v / Vec4{vec4_mag(v)} } - -vec2_norm0 :: proc(v: Vec2) -> Vec2 { - m := vec2_mag(v) - if m == 0 { - return Vec2{0} - } - return v / Vec2{m} -} - -vec3_norm0 :: proc(v: Vec3) -> Vec3 { - m := vec3_mag(v) - if m == 0 { - return Vec3{0} - } - return v / Vec3{m} -} - -vec4_norm0 :: proc(v: Vec4) -> Vec4 { - m := vec4_mag(v) - if m == 0 { - return Vec4{0} - } - return v / Vec4{m} -} - - -F32_DIG :: 6 -F32_EPSILON :: 1.192092896e-07 -F32_GUARD :: 0 -F32_MANT_DIG :: 24 -F32_MAX :: 3.402823466e+38 -F32_MAX_10_EXP :: 38 -F32_MAX_EXP :: 128 -F32_MIN :: 1.175494351e-38 -F32_MIN_10_EXP :: -37 -F32_MIN_EXP :: -125 -F32_NORMALIZE :: 0 -F32_RADIX :: 2 -F32_ROUNDS :: 1 - -F64_DIG :: 15 // # of decimal digits of precision -F64_EPSILON :: 2.2204460492503131e-016 // smallest such that 1.0+F64_EPSILON != 1.0 -F64_MANT_DIG :: 53 // # of bits in mantissa -F64_MAX :: 1.7976931348623158e+308 // max value -F64_MAX_10_EXP :: 308 // max decimal exponent -F64_MAX_EXP :: 1024 // max binary exponent -F64_MIN :: 2.2250738585072014e-308 // min positive value -F64_MIN_10_EXP :: -307 // min decimal exponent -F64_MIN_EXP :: -1021 // min binary exponent -F64_RADIX :: 2 // exponent radix -F64_ROUNDS :: 1 // addition rounding: near |