diff --git a/.gitignore b/.gitignore index d524b1c..513b9d9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ zig-out/ zig-pkg/ bin/ +build/ diff --git a/build.zig b/build.zig index d899e27..eb71b0b 100644 --- a/build.zig +++ b/build.zig @@ -21,6 +21,9 @@ pub fn build(b: *Build) !void { if (optimize == .Debug or tracy_enable) { odin_exec.addArg("-debug"); } + if (optimize == .ReleaseFast) { + odin_exec.addArg("-disable-assert"); + } if (tracy_enable) { odin_exec.addArg("-define:TRACY_ENABLE=true"); odin_exec.addArg(b.fmt("-define:TRACY_CALLSTACK={}", .{tracy_callstack})); diff --git a/build_web.sh b/build_web.sh new file mode 100755 index 0000000..6b7f369 --- /dev/null +++ b/build_web.sh @@ -0,0 +1,37 @@ +#!/bin/bash -eu + +# Point this to where you installed emscripten. Optional on systems that already +# have `emcc` in the path. +EMSCRIPTEN_SDK_DIR="$HOME/repos/emsdk" +OUT_DIR="build/web" + +mkdir -p $OUT_DIR + +export EMSDK_QUIET=1 +[[ -f "$EMSCRIPTEN_SDK_DIR/emsdk_env.sh" ]] && . "$EMSCRIPTEN_SDK_DIR/emsdk_env.sh" + +# Note RAYLIB_WASM_LIB=env.o -- env.o is an internal WASM object file. You can +# see how RAYLIB_WASM_LIB is used inside /vendor/raylib/raylib.odin. +# +# The emcc call will be fed the actual raylib library file. That stuff will end +# up in env.o +# +# Note that there is a rayGUI equivalent: -define:RAYGUI_WASM_LIB=env.o +odin build src/main_web -target:js_wasm32 -build-mode:obj -define:RAYLIB_WASM_LIB=env.o -define:RAYGUI_WASM_LIB=env.o -out:$OUT_DIR/game.wasm.obj + +ODIN_PATH=$(odin root) + +cp $ODIN_PATH/core/sys/wasm/js/odin.js $OUT_DIR + +files="$OUT_DIR/game.wasm.obj ${ODIN_PATH}/vendor/raylib/wasm/libraylib.web.a ${ODIN_PATH}/vendor/raylib/wasm/libraygui.a" + +# index_template.html contains the javascript code that calls the procedures in +# source/main_web/main_web.odin +flags="-sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0 -sASSERTIONS --shell-file src/main_web/index_template.html" + +# For debugging: Add `-g` to `emcc` (gives better error callstack in chrome) +emcc -o $OUT_DIR/index.html $files $flags + +rm $OUT_DIR/game.wasm.obj + +echo "Web build created in ${OUT_DIR}" diff --git a/src/assets/Coustard-Regular.ttf b/src/assets/Coustard-Regular.ttf new file mode 100644 index 0000000..cfbbe9a Binary files /dev/null and b/src/assets/Coustard-Regular.ttf differ diff --git a/src/assets/sdf.gl100.glsl b/src/assets/sdf.gl100.glsl new file mode 100644 index 0000000..b5d5727 --- /dev/null +++ b/src/assets/sdf.gl100.glsl @@ -0,0 +1,25 @@ +#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add your custom variables here +const float smoothing = 1.0/8.0; + +void main() +{ + // Texel color fetching from texture sampler + // NOTE: Calculate alpha using signed distance field (SDF) + float distance = texture2D(texture0, fragTexCoord).a; + float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance); + + // Calculate final fragment color + gl_FragColor = vec4(fragColor.rgb, fragColor.a*alpha); +} diff --git a/src/assets/sdf.gl330.glsl b/src/assets/sdf.gl330.glsl new file mode 100644 index 0000000..782e712 --- /dev/null +++ b/src/assets/sdf.gl330.glsl @@ -0,0 +1,26 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add your custom variables here + +void main() +{ + // Texel color fetching from texture sampler + // NOTE: Calculate alpha using signed distance field (SDF) + float distanceFromOutline = texture(texture0, fragTexCoord).a - 0.5; + float distanceChangePerFragment = length(vec2(dFdx(distanceFromOutline), dFdy(distanceFromOutline))); + float alpha = smoothstep(-distanceChangePerFragment, distanceChangePerFragment, distanceFromOutline); + + // Calculate final fragment color + finalColor = vec4(fragColor.rgb, fragColor.a*alpha); +} diff --git a/src/cards.odin b/src/cards.odin index 2ebefb4..bbcbe67 100644 --- a/src/cards.odin +++ b/src/cards.odin @@ -80,3 +80,65 @@ CARDS := [Card_Handle(TAROT_COUNT)]Card { {.Wand, 13}, {.Wand, 14}, } + +card_full_name :: proc(card: Card) -> (name: string) { + suit_name: string + switch card.suit { + case .Major: + switch card.number { + case 0: + return "The Fool" + case 1: + return "The Magician" + case 2: + return "The High Priestess" + case 3: + return "The Empress" + case 4: + return "The Emperor" + case 5: + return "The Hierophant" + case 6: + return "The Lovers" + case 7: + return "The Chariot" + case 8: + return "Strength" + case 9: + return "The Hermit" + case 10: + return "Wheel of Fortune" + case 11: + return "Justice" + case 12: + return "The Hanged Man" + case 13: + return "Death" + case 14: + return "Temperance" + case 15: + return "The Devil" + case 16: + return "The Tower" + case 17: + return "The Star" + case 18: + return "The Moon" + case 19: + return "The Sun" + case 20: + return "Judgment" + case 21: + return "The World" + } + case .Chalice: + suit_name = "of Chalices" + case .Coin: + suit_name = "of Coins" + case .Sword: + suit_name = "of Swords" + case .Wand: + suit_name = "of Wands" + } + return name +} diff --git a/src/game.odin b/src/game.odin index 3d5d01b..06e9ee3 100644 --- a/src/game.odin +++ b/src/game.odin @@ -24,30 +24,44 @@ import "vendor:raylib/rlgl" MAJOR_COUNT :: 22 MINOR_COUNT :: 14 TAROT_COUNT :: MAJOR_COUNT + 4 * MINOR_COUNT +MINOR_SUIT_COUNT :: 4 CARD_PROPORTIONS :: 4.75 / 2.75 -CARD_SIZE :: Vec2{100, 100 * CARD_PROPORTIONS} +CARD_SIZE :: Vec2{125, 125 * CARD_PROPORTIONS} CARD_ROUNDNESS :: 0.05 +CARD_HEADER_TEXT_SIZE :: 26 +CARD_BOTTOM_TEXT_SIZE :: 20 SUIT_TEX_SIZE :: Vec2{128, 128} COLUMN_COUNT :: 11 COLUMN_HEIGHT :: 28 ROUNDED_RECT_SEGMENTS :: 6 GAP :: 16 -CARD_SEPARATION :: 24 -CARD_DAMPING :: 70 +CARD_SEPARATION :: CARD_HEADER_TEXT_SIZE * 1.15 +CARD_DAMPING :: 60 AUTO_MOVE_INTERVAL :: 0.1 +BOARD_SIZE :: Vec2 { + 11 * (CARD_SIZE.x + GAP) + GAP, + 2 * (CARD_SIZE.y + GAP) + 2 * GAP + 20 * CARD_SEPARATION, +} +when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 { + GLSL_VERSION :: "100" +} else { + GLSL_VERSION :: "330" +} game: Game Game :: struct { + ctx: runtime.Context, run: bool, assets: map[string]runtime.Load_Directory_File, static_arena: mem.Arena, - static_arena_data: [1 * mem.Megabyte]byte, + static_arena_data: [128 * mem.Kilobyte]byte, // Allocations here will never be freed static_allocator: runtime.Allocator, entities: [TAROT_COUNT]Card_Entity, state: State, displayed_state: State, - card_font: ray.Font, + card_top_font: ray.Font, + card_bottom_font: ray.Font, suit_textures: [Suit]ray.Texture, dragged_card: Maybe(Card_Handle), dragged_card_position: Vec2, @@ -55,6 +69,17 @@ Game :: struct { auto_moves: queue.Queue(Move), auto_move_cooldown: f32, suits_overlay_opacity: f32, + hovered_draggable: Maybe(Card_Handle), + last_highlight_card: Maybe(Card_Handle), + highlight_opacity: f32, + phase: Phase, + random_game_count: int, + camera: ray.Camera2D, + sdf_shader: ray.Shader, +} +Phase :: enum { + Searching, + Playing, } Vec2 :: [2]f32 Card :: struct { @@ -87,7 +112,7 @@ Card_State_Kind :: enum { State :: struct { columns: [COLUMN_COUNT]Column, major: [Major_Pile_Kind][dynamic; MAJOR_COUNT]Card_Handle, - minor: [4][dynamic; MINOR_COUNT]Card_Handle, + minor: [MINOR_SUIT_COUNT][dynamic; MINOR_COUNT]Card_Handle, aside: [dynamic; 1]Card_Handle, } Canonical_State :: struct { @@ -126,10 +151,6 @@ init :: proc() { ray.SetConfigFlags({.WINDOW_RESIZABLE, .VSYNC_HINT, .MSAA_4X_HINT}) ray.InitWindow(1600, 900, "Fortune's Foundation") - {ray.BeginDrawing(); defer ray.EndDrawing() - ray.ClearBackground(ray.RAYWHITE) - ray.DrawText("Generating puzzle,\nPlease wait...", 20, 20, 20, ray.GRAY) - } // NOTE(lilith): Sorting statically included assets assets := #load_directory("assets") @@ -153,52 +174,118 @@ init :: proc() { ray.SetTextureFilter(game.suit_textures[suit], .TRILINEAR) } - game.card_font = ray.LoadFontFromMemory( - ".ttf", - psz_from_slice(game.assets["Besley-Bold.ttf"].data), - fontSize = 24, + game.card_top_font.baseSize = 32 + game.card_top_font.glyphCount = 95 + game.card_top_font.glyphs = ray.LoadFontData( + psz_from_slice(game.assets["Coustard-Regular.ttf"].data), + fontSize = 32, codepoints = nil, codepointCount = 0, + type = .SDF, + glyphCount = &game.card_top_font.glyphCount, ) - - auto_moves := make([dynamic]Move, context.temp_allocator) - - random_game_count: int - for { - random_game_count += 1 - log.debugf("generating random game %d", random_game_count) - state_init_fully_random(&game.state) - // if state_trivially_removable_count(game.state) > 0 { - // log.debugf("rejecting due to trivial solves") - // continue - // } - log.debugf("searching solution") - if ok := state_is_solvable(game.state); ok { - break - } - free_all(context.temp_allocator) - log.debugf("gave up on the solution") - } - game.displayed_state = game.state - log.debugf("Generated game: %#v", game.state) - // #reverse for move in reverse_moves { - // queue.append(&game.auto_moves, move) - // } - state_make_stacks_with_effects(&game.state, &auto_moves) - queue.append(&game.auto_moves, ..auto_moves[:]) - // solution, _ := state_find_solution(game.state, context.temp_allocator) - // log.infof("Solution: %v", solution) - for &entity in game.entities { - entity.position = card_position({.Column, 5}) - } + atlas := ray.GenImageFontAtlas( + game.card_top_font.glyphs, + &game.card_top_font.recs, + codepointCount = 0, + fontSize = 32, + padding = 0, + packMethod = 1, + ) + defer ray.UnloadImage(atlas) + game.card_top_font.texture = ray.LoadTextureFromImage(atlas) + game.card_bottom_font = game.card_top_font + game.sdf_shader = ray.LoadShaderFromMemory( + nil, + strings.clone_to_cstring( + string(game.assets[fmt.tprintf("sdf.gl%s.glsl", GLSL_VERSION)].data), + context.temp_allocator, + ), + ) + ray.SetTextureFilter(game.card_top_font.texture, .BILINEAR) + game.ctx = context } update :: proc() { tracy.Zone() + + ray.BeginDrawing(); defer ray.EndDrawing() + render_size := Vec2{f32(ray.GetRenderWidth()), f32(ray.GetRenderHeight())} + zoom_v := render_size / BOARD_SIZE + zoom := min(zoom_v.x, zoom_v.y) + rendered_board_size := zoom * BOARD_SIZE + extra_offset := (render_size - rendered_board_size) / 2 + game.camera = ray.Camera2D { + offset = (rendered_board_size / 2) + extra_offset, + target = BOARD_SIZE / 2, + zoom = zoom, + rotation = 0, + } + + ray.BeginMode2D(game.camera); defer ray.EndMode2D() + ray.ClearBackground({40, 65, 52, 255}) + + switch game.phase { + case .Searching: + game_update_searching() + case .Playing: + game_update() + } +} + +game_update_searching :: proc() { + start_time := ray.GetTime() + for ray.GetTime() < start_time + f64(1.0 / 30.0) { + game.random_game_count += 1 + log.debugf("generating random game %d", game.random_game_count) + state_init_fully_random(&game.state) + + log.debugf("searching solution") + if ok := state_is_solvable(game.state); ok { + game.displayed_state = game.state + auto_moves := make([dynamic]Move, context.temp_allocator) + state_make_stacks_with_effects(&game.state, &auto_moves) + queue.append(&game.auto_moves, ..auto_moves[:]) + for &entity in game.entities { + entity.position = card_position({.Column, 5}) + } + game.phase = .Playing + return + } + + log.debugf("gave up on the solution") + free_all(context.temp_allocator) + } + + text := fmt.ctprintf( + "Generating puzzle,\nPlease wait...\n\nAttempt: %d", + game.random_game_count, + ) + {ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode() + ray.DrawTextEx( + game.card_top_font, + text, + Vec2{CARD_HEADER_TEXT_SIZE, CARD_HEADER_TEXT_SIZE}, + CARD_HEADER_TEXT_SIZE, + 0, + text_color(CARDS[1]), + ) + } +} + +game_update :: proc() { free_all(context.temp_allocator) delta := ray.GetFrameTime() - ray.BeginDrawing(); defer ray.EndDrawing() - ray.ClearBackground({30, 50, 40, 255}) + + ray.DrawRectangleV(Vec2{}, Vec2{BOARD_SIZE.x, 10 * BOARD_SIZE.y}, {25, 40, 43, 255}) + ray.DrawRectangleGradientEx( + rrect_from_pos_sz({0, 0}, BOARD_SIZE), + {30, 50, 40, 255}, + {25, 40, 43, 255}, + {25, 40, 43, 255}, + {30, 50, 40, 255}, + ) + ray.DrawRectangleV(Vec2{}, Vec2{BOARD_SIZE.x, CARD_SIZE.y + 2 * GAP}, {40, 35, 50, 255}) for &entity in game.entities {entity.is_draggable = false} for &column in game.state.columns { @@ -210,23 +297,27 @@ update :: proc() { game.entities[game.state.aside[0]].is_draggable = true } - mouse_position := ray.GetMousePosition() + mouse_position := ray.GetScreenToWorld2D(ray.GetMousePosition(), game.camera) game.dragged_card_position = mouse_position - if ray.IsMouseButtonPressed(.LEFT) { - for &obj, index in game_cards_zipped() { - handle := Card_Handle(index) - if rect_contains( - rrect_from_pos_sz(obj.entity.position - CARD_SIZE * 0.5, CARD_SIZE), - mouse_position, - ) && - game.entities[int(handle)].is_draggable { - game.dragged_card = handle - obj.entity.state = .Dragged - break - } + + game.hovered_draggable = nil + for &obj, index in game_cards_zipped() { + handle := Card_Handle(index) + if rect_contains( + rrect_from_pos_sz(obj.entity.position - CARD_SIZE * 0.5, CARD_SIZE), + mouse_position, + ) && + game.entities[int(handle)].is_draggable { + game.hovered_draggable = handle + break } } + if ray.IsMouseButtonPressed(.LEFT) && game.hovered_draggable != nil { + game.dragged_card = game.hovered_draggable.? + game.entities[game.dragged_card.?].state = .Dragged + } + game.dragged_card_rotation = 0 hovered_place := place_from_position(mouse_position) draggin_card_over_aside := @@ -241,7 +332,7 @@ update :: proc() { if dragged_card, ok := game.dragged_card.?; ok { obj := &game_cards_zipped()[int(dragged_card)] if ray.IsMouseButtonReleased(.LEFT) { - old_place := state_card_place(&game.state, dragged_card) + old_place := state_card_place(game.state, dragged_card) new_place := place_from_position(mouse_position) move := Move { from = old_place, @@ -288,8 +379,8 @@ update :: proc() { place := Place{.Major, i8(major_pile_kind)} position := card_position(place) slot_draw(position) - for handle in major_pile { - game.entities[int(handle)].target_position = position + for handle, height in major_pile { + game.entities[int(handle)].target_position = card_position(place, height) } } for handle in game.displayed_state.aside { @@ -382,6 +473,31 @@ update :: proc() { card_draw(game.displayed_state.aside[0]) } + { + target_highlight_card_handle := game.dragged_card + if target_highlight_card_handle == + nil {target_highlight_card_handle = game.hovered_draggable} + if handle, ok := target_highlight_card_handle.?; ok { + game.last_highlight_card = handle + game.highlight_opacity = min(1, game.highlight_opacity + delta * 3) + } else { + game.highlight_opacity = max(0, game.highlight_opacity - delta * 3) + } + if handle, ok := game.last_highlight_card.?; ok { + place := state_card_place(game.state, handle) + for column, column_index in game.state.columns { + to := Place{.Column, i8(column_index)} + move := Move { + from = place, + to = to, + card = handle, + } + if !state_is_move_valid(game.state, move) {continue} + highlight_draw(card_position(to, len(column))) + } + } + } + if handle, ok := game.dragged_card.?; ok { card_draw(handle) } @@ -396,6 +512,32 @@ slot_draw :: proc(position: Vec2) { ) } +highlight_draw :: proc(position: Vec2) { + t := f32(math.cos(ray.GetTime() * 1.6)) * 0.5 + 0.5 + shiny_color := ray.ColorFromHSV(f32(ray.GetTime() * 30), 0.2, 0.8) + shiny_color.a = u8((t * 40 + 30) * game.highlight_opacity) + ray.DrawRectangleRounded( + rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE), + CARD_ROUNDNESS, + ROUNDED_RECT_SEGMENTS, + color = shiny_color, + ) + ray.DrawRectangleRoundedLinesEx( + rrect_from_pos_sz(position - CARD_SIZE * 0.5 - 1, CARD_SIZE + 2), + CARD_ROUNDNESS, + ROUNDED_RECT_SEGMENTS, + lineThick = t * 2 + 1, + color = ray.Color{0, 0, 0, u8(140 * game.highlight_opacity)}, + ) + ray.DrawRectangleRoundedLinesEx( + rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE), + CARD_ROUNDNESS, + ROUNDED_RECT_SEGMENTS, + lineThick = t * 2, + color = ray.Color{255, 255, 230, u8(140 * game.highlight_opacity)}, + ) +} + card_draw :: proc(handle: Card_Handle) { obj := game_cards_zipped()[int(handle)] card := obj.card @@ -406,6 +548,15 @@ card_draw :: proc(handle: Card_Handle) { rlgl.Rotatef(entity.rotation * math.DEG_PER_RAD, 0, 0, 1) rlgl.Translatef(-entity.position.x, -entity.position.y, 0) + glow_color := card_glow_color(card) + glow_color.a = 120 + ray.DrawRectangleRoundedLinesEx( + rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE), + CARD_ROUNDNESS, + ROUNDED_RECT_SEGMENTS, + lineThick = 4, + color = glow_color, + ) ray.DrawRectangleRounded( rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE), CARD_ROUNDNESS, @@ -420,36 +571,75 @@ card_draw :: proc(handle: Card_Handle) { color = outline_color(card), ) text := strings.clone_to_cstring(short_title(card), context.temp_allocator) - font_size := f32(24) - text_size := ray.MeasureTextEx(game.card_font, text, font_size, spacing = 0) + font_size := f32(CARD_HEADER_TEXT_SIZE) + text_size := ray.MeasureTextEx(game.card_top_font, text, font_size, spacing = 0) offset: Vec2 #partial switch card.suit { case .Major: offset = {(CARD_SIZE.x - text_size.x) * 0.5, 0} case: - offset = {4, 0} + offset = {6, 0} } offset -= CARD_SIZE * 0.5 - ray.DrawTextEx( - game.card_font, - text, - position = entity.position + offset, - fontSize = font_size, - spacing = 0, - tint = text_color(card), - ) + {ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode() + ray.DrawTextEx( + game.card_top_font, + text, + position = entity.position + offset, + fontSize = font_size, + spacing = 0, + tint = text_color(card), + ) + } if card.suit != .Major { ray.DrawTexturePro( game.suit_textures[card.suit], source = rrect_from_pos_sz({0, 0}, SUIT_TEX_SIZE), dest = rrect_from_pos_sz( - entity.position + offset + {text_size.x, 3}, + entity.position + offset + {text_size.x, text_size.y * 0.1}, text_size.yy * 0.7, ), origin = {0, 0}, rotation = 0, tint = text_color(card), ) + } else { + bottom_text := strings.clone_to_cstring(card_full_name(card), context.temp_allocator) + text_size := ray.MeasureTextEx( + game.card_bottom_font, + bottom_text, + CARD_BOTTOM_TEXT_SIZE, + spacing = 0, + ) + offset := Vec2{(CARD_SIZE.x - text_size.x) * 0.5, CARD_SIZE.y - text_size.y * 1.3} + offset -= CARD_SIZE * 0.5 + {ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode() + ray.DrawTextEx( + game.card_bottom_font, + bottom_text, + position = entity.position + offset, + fontSize = CARD_BOTTOM_TEXT_SIZE, + spacing = 0, + tint = text_color(card), + ) + } + } +} + +state_init_solved :: proc(state: ^State) { + state^ = {} + for &suit_pile, suit_index in state.minor { + suit := Suit(suit_index + 1) + for number in 1 ..= MINOR_COUNT { + append(&suit_pile, Card_Handle(MAJOR_COUNT + suit_index * MINOR_COUNT + number - 1)) + } + } + major_split := rand.int_range(0, MAJOR_COUNT + 1) + for number in 0 ..< major_split { + append(&state.major[.Low], Card_Handle(number)) + } + for number := MAJOR_COUNT - 1; number >= major_split; number -= 1 { + append(&state.major[.High], Card_Handle(number)) } } @@ -475,379 +665,18 @@ state_init_fully_random :: proc(state: ^State) { } } -state_init_solved :: proc(state: ^State) { - state^ = {} - for &suit_pile, suit_index in state.minor { - suit := Suit(suit_index + 1) - for number in 1 ..= MINOR_COUNT { - append(&suit_pile, Card_Handle(MAJOR_COUNT + suit_index * MINOR_COUNT + number - 1)) - } - } - major_split := rand.int_range(0, MAJOR_COUNT + 1) - for number in 0 ..< major_split { - append(&state.major[.Low], Card_Handle(number)) - } - for number := MAJOR_COUNT - 1; number >= major_split; number -= 1 { - append(&state.major[.High], Card_Handle(number)) - } -} - -state_init_weird :: proc(state: ^State) { - state^ = {} - outer_column_idcs: [COLUMN_COUNT - 1]int - for index in 0 ..< COLUMN_COUNT - 1 {outer_column_idcs[index] = index >= 5 ? index + 1 : index} - rand.shuffle(outer_column_idcs[:]) - for suit_index in 0 ..< 4 { - suit := Suit(suit_index + 1) - for number in 1 ..= MINOR_COUNT { - append( - &state.columns[outer_column_idcs[suit_index]], - Card_Handle(MAJOR_COUNT + suit_index * MINOR_COUNT + number - 1), - ) - } - } - for number in 0 ..< 11 { - append(&state.columns[outer_column_idcs[4]], Card_Handle(number)) - } - for number := MAJOR_COUNT - 1; number >= 11; number -= 1 { - append(&state.columns[outer_column_idcs[5]], Card_Handle(number)) - } -} - -state_init_reverse :: proc(state: ^State) -> (moves: [dynamic]Move) { - state_init_solved(state) - Initializer :: struct { - moves: [dynamic]Move, - states_seen: map[State_Bytes]struct{}, - state: ^State, - } - initializer := Initializer { - moves = make([dynamic]Move, context.temp_allocator), - states_seen = make(map[State_Bytes]struct{}, context.temp_allocator), - state = state, - } - column_indices: [COLUMN_COUNT]int - for index in 0 ..< COLUMN_COUNT {column_indices[index] = index} - outer_column_idcs: [COLUMN_COUNT - 1]int - for index in 0 ..< COLUMN_COUNT - 1 {outer_column_idcs[index] = index >= 5 ? index + 1 : index} - avoid_column := rand.int_range(0, COLUMN_COUNT - 1) - avoid_column = avoid_column >= 5 ? avoid_column + 1 : avoid_column - - // NOTE(lilith): Create some buried top cards - rand.shuffle(outer_column_idcs[:]) - bury_majors := rand.float32() < 1 - if bury_majors { - clear(&state.major[.Low]) - clear(&state.major[.High]) - for number in 0 ..< 11 { - append(&state.columns[outer_column_idcs[COLUMN_COUNT - 2]], Card_Handle(number)) - } - for number := MAJOR_COUNT - 1; number >= 11; number -= 1 { - append(&state.columns[outer_column_idcs[COLUMN_COUNT - 3]], Card_Handle(number)) - } - } - suits := []Suit{.Chalice, .Coin, .Sword, .Wand} - rand.shuffle(suits) - for suit in suits[:rand.int_range(0, 2) + (bury_majors ? 2 : 3)] { - suit_index := int(suit) - 1 - clear(&state.minor[suit_index]) - append( - &state.columns[outer_column_idcs[suit_index + 4]], - Card_Handle(MAJOR_COUNT + suit_index * MINOR_COUNT), - ) - for number in 2 ..= MINOR_COUNT { - append( - &state.columns[outer_column_idcs[suit_index]], - Card_Handle(MAJOR_COUNT + suit_index * MINOR_COUNT + number - 1), - ) - } - } - - initial_shuffle: for _ in 0 ..< 50 { - shuffle(&initializer, random_chance = 0) - } - - reverse_moves: for _ in 0 ..< 1000 { - stowed_majors: int - for major_pile in state.major {stowed_majors += len(major_pile)} - stowed_minors: int - for minor_pile in state.minor {stowed_minors += len(minor_pile)} - if stowed_majors + stowed_minors == 0 {break} - if rand.float32() < f32(stowed_majors) / f32(stowed_majors + stowed_minors) { - major_clear: for &major_pile, major_pile_kind in state.major { - if len(major_pile) > 0 { - rand.shuffle(outer_column_idcs[:]) - for from_column_index in outer_column_idcs { - if from_column_index == avoid_column {continue} - from_column := &state.columns[from_column_index] - if len(from_column) >= 8 {continue} - to_handle := slice.last(major_pile[:]) - to_card := card_from_handle(to_handle) - if len(from_column) > 1 { - if !cards_are_stackable( - to_card, - card_from_handle(slice.last(from_column[:])), - ) {continue} - } - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Major, i8(major_pile_kind)}, - card = slice.last(major_pile[:]), - } - state_reverse_single_move(state, move) - append(&initializer.moves, move) - continue major_clear - } - if rand.float32() > 0.05 {continue} - rand.shuffle(outer_column_idcs[:]) - for from_column_index in outer_column_idcs { - from_column := &state.columns[from_column_index] - if len(from_column) >= 8 {continue} - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Major, i8(major_pile_kind)}, - card = slice.last(major_pile[:]), - } - state_reverse_single_move(state, move) - append(&initializer.moves, move) - continue major_clear - } - } - } - } else { - suit_clear: for &suit_pile, suit_index in state.minor { - if len(state.aside) > 0 {break} - if len(suit_pile) > 0 { - rand.shuffle(outer_column_idcs[:]) - for from_column_index in outer_column_idcs { - if from_column_index == avoid_column {continue} - from_column := &state.columns[from_column_index] - if len(from_column) >= 8 {continue} - to_handle := slice.last(suit_pile[:]) - to_card := card_from_handle(to_handle) - if len(from_column) > 1 { - if !cards_are_stackable( - to_card, - card_from_handle(slice.last(from_column[:])), - ) {continue} - } - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Suit, i8(suit_index)}, - card = to_handle, - } - state_reverse_single_move(state, move) - append(&initializer.moves, move) - continue suit_clear - } - if rand.float32() > 0.05 {continue} - rand.shuffle(outer_column_idcs[:]) - for from_column_index in outer_column_idcs { - from_column := &state.columns[from_column_index] - if len(from_column) >= 8 {continue} - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Suit, i8(suit_index)}, - card = slice.last(suit_pile[:]), - } - state_reverse_single_move(state, move) - append(&initializer.moves, move) - continue suit_clear - } - } - } - } - small_shuffle: for _ in 0 ..< (rand.float32() < 0.15 ? 0 : 20) { - shuffle(&initializer) - } - } - - if len(state.aside) > 0 { - for &column, column_index in state.columns { - if len(column) >= 8 {continue} - if len(column) >= 7 && column_index >= 10 {continue} - if len(column) >= 0 && column_index == 5 {continue} - move := Move { - from = {.Column, i8(column_index)}, - to = {.Aside, 0}, - card = state.aside[0], - } - state_reverse_single_move(state, move) - break - } - } - // for len(state.columns[5]) > 0 { - // for &column, column_index in state.columns { - // if len(column) >= 8 {continue} - // if len(column) >= 7 && column_index >= 10 {continue} - // if column_index == 5 {continue} - // move := Move { - // from = {.Column, column_index}, - // to = {.Column, 5}, - // card = slice.last(state.columns[5][:]), - // } - // state_reverse_single_move(state, move) - // break - // } - // } - - return initializer.moves - - SHUFFLE_BRANCHING :: 2 - SHUFFLE_BRANCHING_DEPTH :: 3 - SHUFFLE_ROLLOUT_DEPTH :: 50 - - state_random_shuffle_move :: proc(state: ^State) -> (move: Move, ok: bool) { - column_indices: [COLUMN_COUNT]int - for index in 0 ..< COLUMN_COUNT {column_indices[index] = index} - for _ in 0 ..< 10 { - switch rand.float32() { - case 0 ..< 0.4: - rand.shuffle(column_indices[:]) - for from_column_index in column_indices { - from_column := &state.columns[from_column_index] - for &to_column, to_column_index in state.columns { - if len(to_column) == 0 {continue} - if len(to_column) == 1 && len(from_column) == 0 {continue} - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Column, i8(to_column_index)}, - card = slice.last(to_column[:]), - } - if len(from_column) > 0 { - if !cards_are_stackable( - card_from_handle(slice.last(to_column[:])), - card_from_handle(slice.last(from_column[:])), - ) {continue} - } - if state_is_move_valid_reverse(state, move) { - return move, true - } - } - } - case 0.4 ..< 0.7: - rand.shuffle(column_indices[:]) - for from_column_index in column_indices { - from_column := &state.columns[from_column_index] - for &to_column, to_column_index in state.columns { - if len(to_column) == 0 {continue} - if len(to_column) == 1 && len(from_column) == 0 {continue} - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Column, i8(to_column_index)}, - card = slice.last(to_column[:]), - } - if state_is_move_valid_reverse(state, move) { - return move, true - } - } - } - case 0.7 ..= 1: - rand.shuffle(column_indices[:]) - if len(state.aside) == 0 { - for to_column_index in column_indices { - to_column := &state.columns[to_column_index] - if len(to_column) == 0 {continue} - move := Move { - from = {.Aside, 0}, - to = {.Column, i8(to_column_index)}, - card = slice.last(to_column[:]), - } - if state_is_move_valid_reverse(state, move) { - return move, true - } - } - } else { - if rand.float32() < 0.7 {return} - for from_column_index in column_indices { - from_column := &state.columns[from_column_index] - move := Move { - from = {.Column, i8(from_column_index)}, - to = {.Aside, 0}, - card = state.aside[0], - } - if state_is_move_valid_reverse(state, move) { - return move, true - } - } - } - } - } - return {}, false - } - - recurse_max_difficulty :: proc(state: State, depth: int) -> (difficulty: int = -200000000) { - state := state - difficulty = state_difficulty_score(&state) - if depth >= SHUFFLE_ROLLOUT_DEPTH { - return - } - for _ in 0 ..< (depth < SHUFFLE_BRANCHING_DEPTH ? SHUFFLE_BRANCHING : 1) { - move, ok := state_random_shuffle_move(&state) - if !ok {continue} - clone := state - state_reverse_single_move(&clone, move) - difficulty = max(difficulty, recurse_max_difficulty(clone, depth + 1)) - } - return - } - - shuffle :: proc(init: ^Initializer, random_chance := f32(0.05)) { - state := init.state - move: Move - if rand.float32() < random_chance { - move, _ = state_random_shuffle_move(state) - } else { - moves: [8]Move - difficulties: [8]int - for index in 0 ..< 8 { - ok: bool - moves[index], ok = state_random_shuffle_move(state) - if !ok {continue} - clone := state^ - state_reverse_single_move(&clone, moves[index]) - difficulties[index] = recurse_max_difficulty(clone, 0) - } - max_index := slice.max_index(difficulties[:]) - move = moves[max_index] - } - if state_is_move_valid_reverse(state, move) { - try_move(init, move) - } - } - - try_move :: proc(init: ^Initializer, move: Move) -> (ok: bool) { - state := init.state^ - state_reverse_single_move(&state, move) - if state_to_bytes(state) in init.states_seen {return false} - init.state^ = state - init.states_seen[state_to_bytes(state)] = {} - append(&init.moves, move) - return true - } - -} - State_Bytes :: [TAROT_COUNT * 2]byte state_to_bytes :: proc(state: State) -> State_Bytes { return transmute(State_Bytes)canonical_state_from_state(state) } -state_reverse_single_move :: proc(state: ^State, move: Move) { - moved_card, pop_ok := state_pop(state, move.to) - assert(pop_ok) - assert(moved_card == move.card) - state_push(state, move.from, moved_card) -} - state_is_solvable :: proc(state: State) -> (is_solution: bool) { tracy.Zone() runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD() allocator := context.temp_allocator context.allocator = allocator TRIAL_LIMIT :: 10_000 - NO_PROGRESS_TRIAL_BASE_LIMIT :: 50 - NO_PROGRESS_TRIAL_SCALING_LIMIT :: 10 + NO_PROGRESS_TRIAL_BASE_LIMIT :: 800 Searcher :: struct { queue: pq.Priority_Queue(Search_Item), @@ -880,18 +709,14 @@ state_is_solvable :: proc(state: State) -> (is_solution: bool) { for search_item in pq.pop_safe(&searcher.queue) { searcher.trial_count += 1 if searcher.trial_count > TRIAL_LIMIT {return false} - // log.debugf("search item: %v", search_item) state := search_item.state if search_item.distance < searcher.best_distance { searcher.best_distance = search_item.distance searcher.no_progress_count = 0 - log.debugf("new best distance: %d", searcher.best_distance) } else { searcher.no_progress_count += 1 - if searcher.no_progress_count > - NO_PROGRESS_TRIAL_BASE_LIMIT + - (searcher.trial_count / NO_PROGRESS_TRIAL_SCALING_LIMIT) { + if searcher.no_progress_count > NO_PROGRESS_TRIAL_BASE_LIMIT { return false } } @@ -1011,17 +836,16 @@ canonical_state_from_state :: proc(state: State) -> (canonical: Canonical_State) state_solution_distance :: proc(state: State) -> (distance: int) #no_bounds_check { state := state - open_cards: bit_set[Card_Handle(0) ..< TAROT_COUNT] + // open_cards: bit_set[Card_Handle(0) ..< TAROT_COUNT] open_card_list := [6]Card_Handle { 0 ..< 6 = TAROT_COUNT, } for &minor_pile, suit_index in state.minor { suit := Suit(suit_index + 1) - next_number := - len(minor_pile) == 0 ? 1 : card_from_handle(slice.last(minor_pile[:])).number + 1 + next_number := i8(len(minor_pile)) + 1 if next_number <= MINOR_COUNT { - open_cards += {handle_from_card({suit, next_number})} + // open_cards += {handle_from_card({suit, next_number})} open_card_list[suit_index] = handle_from_card({suit, next_number}) } } @@ -1029,14 +853,12 @@ state_solution_distance :: proc(state: State) -> (distance: int) #no_bounds_chec for &major_pile, major_pile_kind in state.major { next_number: i8 if major_pile_kind == .Low { - next_number = - len(major_pile) == 0 ? 0 : card_from_handle(slice.last(major_pile[:])).number + 1 + next_number = i8(len(major_pile)) } else { - next_number = - len(major_pile) == 0 ? MAJOR_COUNT - 1 : card_from_handle(slice.last(major_pile[:])).number - 1 + next_number = MAJOR_COUNT - 1 - i8(len(major_pile)) } if 0 <= next_number && next_number < MAJOR_COUNT { - open_cards += {handle_from_card({.Major, next_number})} + // open_cards += {handle_from_card({.Major, next_number})} open_card_list[4 + int(major_pile_kind)] = handle_from_card({.Major, next_number}) } } @@ -1059,7 +881,7 @@ state_solution_distance :: proc(state: State) -> (distance: int) #no_bounds_chec depth := lens - (height + 1) handles := simd.gather( column_ptrs, - #simd[16]Card_Handle{0 ..< 16 = TAROT_COUNT + 1}, + splat(#simd[16]Card_Handle, TAROT_COUNT + 1), column_mask, ) for open_card_handle in open_card_list { @@ -1067,9 +889,9 @@ state_solution_distance :: proc(state: State) -> (distance: int) #no_bounds_chec handles, #simd[16]Card_Handle{0 ..< 16 = open_card_handle}, ) - under_len := simd.lanes_lt(#simd[16]i8{0 ..< 16 = height}, lens) + under_len := simd.lanes_lt(splat(#simd[16]i8, height), lens) mask := simd.bit_and(eq, under_len) - bury_depth_sums += simd.select(mask, depth, #simd[16]i8{0 ..< 16 = 0}) + bury_depth_sums += simd.select(mask, depth, splat(#simd[16]i8, 0)) } column_ptrs = (#simd[16]rawptr)( (#simd[16]uintptr)(column_ptrs) + uintptr(size_of(Card_Handle)), @@ -1094,99 +916,17 @@ state_solution_distance :: proc(state: State) -> (distance: int) #no_bounds_chec return 10 * cards_in_play + bury_depth } -state_difficulty_score :: proc(state: ^State) -> int { - return( - 10000 * len(state.aside) + - 10 * state_nonsequential_count(state) - - 0 * state_trivially_removable_count(state^) + - 0 * state_stacking_score(state) \ - ) +splat_vec :: proc($T: typeid/[$N]$E, e: E) -> T { + return {0 ..< N = e} +} +splat_simd :: proc($T: typeid/#simd[$N]$E, e: E) -> T { + return {0 ..< N = e} +} +splat :: proc { + splat_vec, + splat_simd, } -state_stacking_score :: proc(state: ^State) -> (count: int) { - for &column in state.columns { - len := len(column) - count += len * len - } - return count -} - -state_nonsequential_count :: proc(state: ^State) -> (count: int) { - for &column in state.columns { - if len(column) < 2 {continue} - - for top_handle, top_idx in column[1:] { - top_card := card_from_handle(top_handle) - bottom_handle := column[top_idx] - bottom_card := card_from_handle(bottom_handle) - if top_card.suit != bottom_card.suit { - count += 1 - } else if abs(top_card.number - bottom_card.number) > 1 { - count += 1 - } - } - } - return count - -} - -state_trivially_removable_count :: proc(state: State) -> (count: int) { - state := state - moves := make([dynamic]Move, context.temp_allocator) - if len(state.aside) > 1 { - for &column, column_index in state.columns { - copied := state - moves := make([dynamic]Move, context.temp_allocator) - state_make_stacks_with_effects(&copied, &moves) - count = max(count, len(moves)) - clear(&moves) - } - } - copied := state - state_make_stacks_with_effects(&copied, &moves) - return len(moves) -} - -state_minor_inversion_count :: proc(state: ^State) -> (count: int) { - for &column in state.columns { - if len(column) < 2 {continue} - for top_handle, top_idx in column[1:] { - top_card := card_from_handle(top_handle) - if top_card.suit == .Major {continue} - for bottom_handle, bottom_idx in column[:top_idx] { - bottom_card := card_from_handle(bottom_handle) - if bottom_card.suit == .Major {continue} - if top_card.number >= bottom_card.number {count += 1} - } - } - } - return count -} - -state_major_inversion_count :: proc(state: ^State) -> (count: int) { - for &column in state.columns { - if len(column) < 2 {continue} - for top_handle, top_idx in column[1:] { - top_card := card_from_handle(top_handle) - if top_card.suit != .Major {continue} - for bottom_handle, bottom_idx in column[:top_idx] { - bottom_card := card_from_handle(bottom_handle) - if bottom_card.suit != .Major {continue} - if top_card.number >= 11 && - bottom_card.number >= 11 && - top_card.number < bottom_card.number { - count += 1 - } - if top_card.number <= 10 && - bottom_card.number <= 10 && - top_card.number > bottom_card.number { - count += 1 - } - } - } - } - return count -} state_is_solved :: proc(state: State) -> bool { state := state @@ -1368,14 +1108,16 @@ state_push :: proc(state: ^State, place: Place, handle: Card_Handle) { append(&state.columns[place.index], handle) case .Major: card := card_from_handle(handle) + assert(card.suit == .Major) if state_can_stack_major_low(state^, handle) { append(&state.major[.Low], handle) } else { append(&state.major[.High], handle) } case .Suit: + card := card_from_handle(handle) if state_can_stack_suit(state^, handle) { - suit_index := int(card_from_handle(handle).suit) - 1 + suit_index := int(card.suit) - 1 suit_pile := &state.minor[suit_index] append(&state.minor[suit_index], handle) } else { @@ -1393,43 +1135,43 @@ state_can_stack_suit :: proc(state: State, handle: Card_Handle) -> bool { if card.suit == .Major {return false} suit_index := int(card.suit) - 1 suit_pile := &state.minor[suit_index] - if len(suit_pile) == 0 {return card.number == 1} - return card.number - 1 == card_from_handle(slice.last(suit_pile[:])).number + return i8(len(suit_pile)) == card.number - 1 } state_can_stack_major_low :: proc(state: State, handle: Card_Handle) -> bool { state := state card := card_from_handle(handle) if card.suit != .Major {return false} - if len(state.major[.Low]) == 0 {return card.number == 0} - return card.number - 1 == card_from_handle(slice.last(state.major[.Low][:])).number + return i8(len(state.major[.Low])) == card.number } state_can_stack_major_high :: proc(state: State, handle: Card_Handle) -> bool { state := state card := card_from_handle(handle) if card.suit != .Major {return false} - if len(state.major[.High]) == 0 {return card.number == MAJOR_COUNT - 1} - return card.number + 1 == card_from_handle(slice.last(state.major[.High][:])).number + return MAJOR_COUNT - i8(len(state.major[.High])) == card.number + 1 } -state_is_move_valid :: proc(state: State, move: Move) -> (ok: bool) { +state_is_move_valid :: proc(state: State, move: Move) -> (ok: bool) #no_bounds_check { state := state if move.from == move.to {return false} moved_card := card_from_handle(move.card) - from_pile := state_get_pile(&state, move.from) - if len(from_pile) == 0 {return false} - if slice.last(from_pile) != move.card {return false} + when !ODIN_DISABLE_ASSERT { + from_pile := state_get_pile(&state, move.from) + assert(len(from_pile) > 0) + assert(slice.last(from_pile) == move.card) + } - to_pile := state_get_pile(&state, move.to) #partial switch move.from.kind { case .Major, .Suit: return false } #partial switch move.to.kind { case .Column: - if len(to_pile) == 0 {return true} - top_card := card_from_handle(slice.last(to_pile)) + assert(0 <= move.to.index && move.to.index < COLUMN_COUNT) + column := state.columns[move.to.index] + if len(column) == 0 {return true} + top_card := card_from_handle(slice.last(column[:])) return cards_are_stackable(moved_card, top_card) case .Major: return( @@ -1477,7 +1219,7 @@ cards_are_stackable :: proc(a, b: Card) -> bool { return a.suit == b.suit && abs(a.number - b.number) == 1 } -state_get_pile :: proc(state: ^State, place: Place) -> (pile: []Card_Handle) { +state_get_pile :: proc(state: ^State, place: Place) -> (pile: []Card_Handle) #no_bounds_check { switch place.kind { case .Column: assert(0 <= place.index && place.index < COLUMN_COUNT) @@ -1493,7 +1235,8 @@ state_get_pile :: proc(state: ^State, place: Place) -> (pile: []Card_Handle) { unreachable() } -state_card_place :: proc(state: ^State, handle: Card_Handle) -> Place { +state_card_place :: proc(state: State, handle: Card_Handle) -> Place { + state := state for column_index in 0 ..< COLUMN_COUNT { if slice.contains( state.columns[column_index][:], @@ -1511,7 +1254,23 @@ state_card_place :: proc(state: ^State, handle: Card_Handle) -> Place { } -card_from_handle :: proc(handle: Card_Handle) -> Card #no_bounds_check {return CARDS[int(handle)]} +// card_from_handle :: proc(handle: Card_Handle) -> Card #no_bounds_check {return CARDS[int(handle)]} +card_from_handle :: proc(handle: Card_Handle) -> (card: Card) #no_bounds_check { + assert(0 <= handle && handle < TAROT_COUNT) + if handle < MAJOR_COUNT { + return {.Major, i8(handle)} + } else { + index := i8(handle - MAJOR_COUNT) + assert(index < MINOR_COUNT * 4) + suit_index := index / MINOR_COUNT + assert(0 <= suit_index && suit_index < 4) + suit := Suit(suit_index + 1) + assert(.Chalice <= suit && suit <= .Wand) + number := index - suit_index * MINOR_COUNT + 1 + assert(1 <= number && number <= MINOR_COUNT) + return {suit, number} + } +} handle_from_card :: proc(card: Card) -> Card_Handle { return Card_Handle( card.suit == .Major ? card.number : (MAJOR_COUNT + (i8(card.suit) - 1) * MINOR_COUNT + card.number - 1), @@ -1528,7 +1287,11 @@ card_position :: proc(place: Place, pile_index: int = 0) -> (position: Vec2) { column_offset := Vec2{f32(place.index) * (CARD_SIZE.x + GAP), 0} + column_section_offset position = Vec2{0, f32(pile_index) * CARD_SEPARATION} + column_offset case .Major: - position = top_section_offset + Vec2{f32(place.index) * (CARD_SIZE.x + GAP), 0} + base_position := top_section_offset + Vec2{f32(place.index) * 3 * (CARD_SIZE.x + GAP), 0} + offset_direction: f32 = place.index == 0 ? 1 : -1 + offset := + offset_direction * f32(pile_index) * (2 * (CARD_SIZE.x + GAP) + GAP) / MAJOR_COUNT + position = base_position + Vec2{offset, 0} case .Suit: position = suits_section_offset + Vec2{f32(place.index) * (CARD_SIZE.x + GAP), 0} case .Aside: @@ -1588,7 +1351,8 @@ text_color :: proc(card: Card) -> ray.Color { switch card.suit { case .Major: // return ray.Color{250, 220, 120, 255} - return ray.Color{250, 230, 190, 255} + // return ray.Color{250, 230, 190, 255} + return ray.Color{230, 230, 220, 255} case .Chalice: return ray.Color{20, 50, 70, 255} case .Coin: @@ -1628,6 +1392,23 @@ outline_color :: proc(card: Card) -> ray.Color { // unreachable() } +card_glow_color :: proc(card: Card) -> ray.Color { + switch card.suit { + case .Major: + return ray.Color{0, 0, 0, 255} + // return ray.ColorFromHSV(f32(ray.GetTime() * 0.2), 0.4, 0.8) + case .Chalice: + return ray.Color{0, 120, 180, 255} + case .Coin: + return ray.Color{20, 120, 30, 255} + case .Sword: + return ray.Color{200, 190, 0, 255} + case .Wand: + return ray.Color{170, 0, 0, 255} + } + unreachable() +} + short_title :: proc(card: Card) -> string { if card.suit == .Major { return fmt.tprintf("%d", card.number) @@ -1741,3 +1522,39 @@ rect_contains :: proc(rect: ray.Rectangle, p: Vec2) -> bool { p.y <= rect.y + rect.height \ ) } +// raylib_set_os_api :: proc() { +// // Forward raylib's logging to Odin's logging. +// ray.SetTraceLogLevel(.INFO) +// ray.SetTraceLogCallback(raylib_log_proc) +// raylib_log_proc :: proc "c" (rl_level: ray.TraceLogLevel, text: cstring, args: ^libc.va_list) { +// context = game.ctx +// level: log.Level +// switch rl_level { +// case .NONE: +// level = .Fatal +// case .FATAL: +// level = .Fatal +// case .ERROR: +// level = .Error +// case .WARNING: +// level = .Warning +// case .INFO: +// level = .Info +// case .DEBUG: +// level = .Debug +// case .TRACE: +// level = .Debug +// case .ALL: +// level = .Debug +// } +// BUFFER_SIZE :: 1024 +// @(static) buffer: [BUFFER_SIZE]u8 +// result := libc.vsnprintf(raw_data(buffer[:]), BUFFER_SIZE, text, args) +// if result < 0 { +// log.warn("Failed to format a message from raylib. Format string was: \"%s\"", text) +// return +// } +// context.logger = game.rl_logger +// log.logf(level, "%s", buffer[:result], location = {}) +// } +// } diff --git a/src/main_web/index_template.html b/src/main_web/index_template.html index 39579c5..b98464b 100644 --- a/src/main_web/index_template.html +++ b/src/main_web/index_template.html @@ -4,19 +4,19 @@ - Odin + Raylib on the web - - + Fortune's Foundation + +