Working on code in language, fixing bugs

This commit is contained in:
Krzosa Karol
2022-06-17 17:00:34 +02:00
parent 5b55852619
commit 871ff65ec2
9 changed files with 71 additions and 131 deletions

View File

@@ -1,31 +1,13 @@
#import "base.kl"
#import "os_windows.kl"
#import "kernel32.kl"
#import "gdi32.kl"
#import "user32.kl"
#import "os.kl"
#import "Windows.kl"
process_heap: HANDLE
allocate :: (size: U64): *void
if process_heap == 0
process_heap = GetProcessHeap()
return HeapAlloc(process_heap, 0, size)
test_unicode :: (arena: *Arena)
string := " 豈 更 車 賈 滑 串 句 龜 龜 契 金 喇 奈 懶 癩 羅 蘿 螺 裸 邏 樂 洛 烙 珞 落 酪 駱 亂 卵 欄 爛 蘭 鸞 嵐 濫 藍 襤 拉 臘 蠟 廊 朗 浪 狼 郎 來 冷 勞 擄 櫓 爐 盧 老 蘆 虜 路 露 魯 鷺 碌 祿 綠 菉 錄 鹿 論 壟 弄 籠 聾 牢 磊 賂 雷 壘 屢 樓 淚 漏 累 縷 陋 勒 肋 凜 凌 稜 綾 菱 陵 讀 拏 樂 諾 丹 寧 怒 率 異 北 磻 便 復 不 泌 數 索 參 塞 省 葉 說 殺 辰 沈 拾 若 掠 略 亮 兩 凉 梁 糧 良 諒 量 勵 ..."
string_result := string_to_string16(arena, string)
print(string_result)
s32, s32_len := utf8_to_utf32(&"A"[0], 1)
assert(s32 == 'A, "Invalid decode") // '
s32_2, s32_len_2 := utf8_to_utf32(&"ć"[0], 2)
assert(s32_2 == 0x107, "Invalid decode")
s32_3, s32_len_3 := utf8_to_utf32(&"ó"[0], 2)
assert(s32_3 == 0xF3, "Invalid decode")
#import "winmm.kl"
Vec2I :: struct;; x: S64; y: S64
Vec2 :: struct;; x: F32; y: F32
Windows_Bitmap :: struct
size: Vec2I
data: *U32
@@ -67,7 +49,11 @@ window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRE
return 0
else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
_gcvt :: #foreign (value: F64, digits: int, buffer: *char): *char
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
good_scheduling = true
arena: Arena
window_name := string_to_string16(&arena, "Have a wonderful day! 豈 更 車 賈 滑 串 句 龜 ")
w := WNDCLASSW{
@@ -77,6 +63,8 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
}
assert(RegisterClassW(&w) != 0)
buff: *char = allocate(100)
screen_size: Vec2I = {1280, 720}
window := CreateWindowExW(
dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0,
@@ -91,6 +79,11 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
window_dc := GetDC(window)
bitmap := create_bitmap(screen_size)
requested_time_per_frame := 1.0 / 60.0
frame_start_time := time()
frame_number: S64
total_time: F64
for app_is_running
msg: MSG
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
@@ -104,3 +97,23 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
SelectObject(bitmap.hdc, bitmap.dib)
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)
frame_time := time() - frame_start_time
_gcvt(frame_time, 10, buff)
OutputDebugStringA("\n")
OutputDebugStringA(buff)
if frame_time < requested_time_per_frame
if good_scheduling
time_to_sleep := (requested_time_per_frame - frame_time) * 1000
if time_to_sleep > 0
time_to_sleep_dword := time_to_sleep->DWORD
// @check if time_to_sleep_dword truncates down
Sleep(time_to_sleep_dword)
new_frame_time := time()
for new_frame_time < requested_time_per_frame
new_frame_time = time() - frame_start_time
frame_time = new_frame_time
frame_number += 1
total_time += frame_time