diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-03 18:18:45 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-03 18:18:45 +0100 |
| commit | 7f884ed25187416bb3994e498eae30fe65233940 (patch) | |
| tree | d7386614920f6d56ea184efd638d9132a34ea682 /examples | |
| parent | 11205f968ad2bf4893fa75df3fc3331f960039d1 (diff) | |
Start implementing Tagged Unions
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo.odin | 62 | ||||
| -rw-r--r-- | examples/game.odin | 6 |
2 files changed, 10 insertions, 58 deletions
diff --git a/examples/demo.odin b/examples/demo.odin index a780bef1d..969b958fc 100644 --- a/examples/demo.odin +++ b/examples/demo.odin @@ -3,62 +3,20 @@ #load "game.odin" main :: proc() { - - print_ints :: proc(args: ..int) { - for i := 0; i < len(args); i++ { - print_int(args[i]) - nl() + Entity :: type union { + FROG: struct { + jump_height: f32 + } + HELICOPTER: struct { + weight: f32 + blade_code: int } - } - // print_ints() - // print_ints(1) - print_ints(1, 2, 3, 4, 5) - - // print_int(min(1, 2)); nl() - // print_int(max(1, 2)); nl() - // print_int(abs(-1337)); nl() - - // a, b, c := 1, 2, -1337 - - // print_int(min(a, b)); nl() - // print_int(max(a, b)); nl() - // print_int(abs(c) as int); nl() - - // nl() -/* - Vec3 :: type struct { x, y, z: f32 } - Entity :: type struct { - using pos: Vec3 - name: string - } - - Amp :: type struct { - using entity: Entity - jump_height: f32 - } - Frog :: type struct { - using amp: Amp - volume: f64 - } - - f := Frog{}; - f.name = "ribbit" - f.jump_height = 1337 - - e := ^f.entity - parent := e down_cast ^Frog - - print_name :: proc(using e: Entity, v: Vec3) { - print_string(name); nl() - print_int(v.x as int); nl() } - print_f32(f.jump_height); nl() - print_f32(parent.jump_height); nl() + e: Entity + f: Entity = Entity.FROG{1}; + h: Entity = Entity.HELICOPTER{123, 4}; - print_name(f, Vec3{1, 2, 3}) - print_name(parent, Vec3{3, 2, 1}) -*/ } nl :: proc() { print_nl() } diff --git a/examples/game.odin b/examples/game.odin index 4420ce448..1568ebabe 100644 --- a/examples/game.odin +++ b/examples/game.odin @@ -122,12 +122,6 @@ display_window :: proc(w: ^Window) { } -Entity :: type struct { - pos: Vec2 - dim: Vec2 -} - - run_game :: proc() { win32_proc :: proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT #no_inline { if msg == WM_DESTROY || msg == WM_CLOSE || msg == WM_QUIT { |