Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions win32/game_of_life/game_of_life.odin
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import win32 "core:sys/windows"
import "core:time"

// aliases
L :: intrinsics.constant_utf16_cstring
Color :: [4]u8
Int2 :: [2]i32

// constants
TITLE :: "Game of Life"
CLASS_NAME :: "OdinMainClass"
WORLD_SIZE :: Int2 {128, 64}
ZOOM :: 12 // pixel size
FPS :: 20
Expand Down Expand Up @@ -263,7 +263,7 @@ WM_PAINT :: proc(hwnd: win32.HWND) -> win32.LRESULT {
rect := HELP_RECT
win32.RoundRect(hdc, rect.left, rect.top, rect.right, rect.bottom, 20, 20)
win32.InflateRect(&rect, -10, -10)
win32.DrawTextW(hdc, L(HELP_TEXT), -1, &rect, .DT_TOP)
win32.DrawTextW(hdc, HELP_TEXT, -1, &rect, .DT_TOP)
}

return 0
Expand Down Expand Up @@ -330,7 +330,7 @@ wndproc :: proc "system" (hwnd: win32.HWND, msg: win32.UINT, wparam: win32.WPARA
}

register_class :: proc(instance: win32.HINSTANCE) -> win32.ATOM {
icon: win32.HICON = win32.LoadIconW(instance, win32.MAKEINTRESOURCEW(101))
icon: win32.HICON = win32.LoadIconW(instance, cstring16(win32.MAKEINTRESOURCEW(101)))
if icon == nil {icon = win32.LoadIconW(nil, win32.wstring(win32._IDI_APPLICATION))}
if icon == nil {show_error_and_panic("Missing icon")}
cursor := win32.LoadCursorW(nil, win32.wstring(win32._IDC_ARROW))
Expand All @@ -341,14 +341,14 @@ register_class :: proc(instance: win32.HINSTANCE) -> win32.ATOM {
hInstance = instance,
hIcon = icon,
hCursor = cursor,
lpszClassName = L("OdinMainClass"),
lpszClassName = CLASS_NAME,
}
return win32.RegisterClassW(&wcx)
}

unregister_class :: proc(atom: win32.ATOM, instance: win32.HINSTANCE) {
if atom == 0 {show_error_and_panic("atom is zero")}
if !win32.UnregisterClassW(win32.LPCWSTR(uintptr(atom)), instance) {show_error_and_panic("UnregisterClassW")}
if !win32.UnregisterClassW(CLASS_NAME, instance) {show_error_and_panic("UnregisterClassW")}
}

adjust_size_for_style :: proc(size: ^Int2, dwStyle: win32.DWORD) {
Expand All @@ -374,7 +374,7 @@ create_window :: #force_inline proc(instance: win32.HINSTANCE, atom: win32.ATOM,
if .CENTER in game.window.control_flags {
center_window(&pos, size)
}
return win32.CreateWindowW(win32.LPCWSTR(uintptr(atom)), game.window.name, style, pos.x, pos.y, size.x, size.y, nil, nil, instance, game)
return win32.CreateWindowW(CLASS_NAME, game.window.name, style, pos.x, pos.y, size.x, size.y, nil, nil, instance, game)
}

message_loop :: proc() -> int {
Expand All @@ -394,7 +394,7 @@ run :: proc() -> int {
colors = {BLACK, WHITE},
size = WORLD_SIZE,
zoom = ZOOM,
window = Window{name = L(TITLE), size = WORLD_SIZE * ZOOM, fps = FPS, control_flags = {.CENTER}},
window = Window{name = TITLE, size = WORLD_SIZE * ZOOM, fps = FPS, control_flags = {.CENTER}},
}
for i in 0 ..< PALETTE_COUNT {
c := u8((255 * int(i)) / (PALETTE_COUNT - 1))
Expand Down
Loading