Automatic closing of examples, revise drawing example

This commit is contained in:
Krzosa Karol
2022-09-28 14:09:20 +02:00
parent 4510f39397
commit 83ffc82f79
6 changed files with 27 additions and 31 deletions

View File

@@ -264,7 +264,7 @@ compile_file(String filename, U32 compile_flags = COMPILE_NULL){
} }
if(is_flag_set(compile_flags, COMPILE_AND_RUN)){ if(is_flag_set(compile_flags, COMPILE_AND_RUN)){
int result = system("a.exe"); int result = system("a.exe testing");
assert(result != -1); assert(result != -1);
if(result == 0){ if(result == 0){
log_info(PRINTF_GREEN "OK!" PRINTF_RESET); log_info(PRINTF_GREEN "OK!" PRINTF_RESET);

View File

@@ -1076,13 +1076,11 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
node->index_original_type = left.type; node->index_original_type = left.type;
node->resolved_type = left.type->arr.base; node->resolved_type = left.type->arr.base;
if(is_string(left.type)){ if(left.type == type_pointer_to_char){
if(left.type == type_pointer_to_char){ node->resolved_type = type_char;
node->resolved_type = type_char; }
} else if(is_string(left.type)) {
else { node->resolved_type = type_u8;
node->resolved_type = type_u8;
}
} }
// @todo: type_architecture? // @todo: type_architecture?

View File

@@ -1,5 +1,5 @@
#import "base.kl" #import "base.kl"
Arena :: #import "arena.kl" #import "arena.kl"
#import "os_windows.kl" #import "os_windows.kl"
#import "kernel32.kl" #import "kernel32.kl"
#import "gdi32.kl" #import "gdi32.kl"
@@ -9,6 +9,8 @@ Arena :: #import "arena.kl"
Vec2I :: struct;; x: S64; y: S64 Vec2I :: struct;; x: S64; y: S64
Vec2 :: struct;; x: F32; y: F32 Vec2 :: struct;; x: F32; y: F32
AppIsRunning := true
Windows_Bitmap :: struct Windows_Bitmap :: struct
size: Vec2I size: Vec2I
data: *U32 data: *U32
@@ -44,8 +46,6 @@ CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
result.hdc = CreateCompatibleDC(hdc) result.hdc = CreateCompatibleDC(hdc)
return result return result
AppIsRunning := true
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
if msg == WM_DESTROY if msg == WM_DESTROY
PostQuitMessage(0) PostQuitMessage(0)
@@ -57,7 +57,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
good_scheduling = true good_scheduling = true
arena: Arena.Arena arena: Arena
window_name := StringToString16(&arena, "Have a wonderful day! 你好世界 ") window_name := StringToString16(&arena, "Have a wonderful day! 你好世界 ")
w := WNDCLASSW{ w := WNDCLASSW{
@@ -98,21 +98,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
SelectObject(bitmap.hdc, bitmap.dib) SelectObject(bitmap.hdc, bitmap.dib)
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY) BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)
Sleep(100)
if CStringCompare(lpCmdLine, "testing")
frame_time := Time() - frame_start_time ExitProcess(0)
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

View File

@@ -182,11 +182,9 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
Screen = bitmap.data; X = bitmap.size.x; Y = bitmap.size.y Screen = bitmap.data; X = bitmap.size.x; Y = bitmap.size.y
Raymarcher_Update() Raymarcher_Update()
SelectObject(bitmap.hdc, bitmap.dib) SelectObject(bitmap.hdc, bitmap.dib)
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY) BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)
frame_time := Time() - frame_start_time frame_time := Time() - frame_start_time
frame_number += 1 frame_number += 1
TotalTime += frame_time TotalTime += frame_time
@@ -203,3 +201,6 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
new_frame_time = Time() - frame_start_time new_frame_time = Time() - frame_start_time
frame_time = new_frame_time frame_time = new_frame_time
if CStringCompare(lpCmdLine, "testing")
ExitProcess(0)

View File

@@ -94,6 +94,16 @@ StringToString16 :: (arena: *Arena, in: String): String16
result.str[result.len] = 0 result.str[result.len] = 0
return result return result
CStringCompare :: (a: *char, b: *char): Bool
i := 0
for , a[i] != 0, i+=1
if a[i] != b[i]
return false
if a[i] != b[i]
return false
return true
TestUnicode :: (arena: *Arena) TestUnicode :: (arena: *Arena)
string := " 豈 更 車 賈 滑 串 句 龜 龜 契 金 喇 奈 懶 癩 羅 蘿 螺 裸 邏 樂 洛 烙 珞 落 酪 駱 亂 卵 欄 爛 蘭 鸞 嵐 濫 藍 襤 拉 臘 蠟 廊 朗 浪 狼 郎 來 冷 勞 擄 櫓 爐 盧 老 蘆 虜 路 露 魯 鷺 碌 祿 綠 菉 錄 鹿 論 壟 弄 籠 聾 牢 磊 賂 雷 壘 屢 樓 淚 漏 累 縷 陋 勒 肋 凜 凌 稜 綾 菱 陵 讀 拏 樂 諾 丹 寧 怒 率 異 北 磻 便 復 不 泌 數 索 參 塞 省 葉 說 殺 辰 沈 拾 若 掠 略 亮 兩 凉 梁 糧 良 諒 量 勵 ..." string := " 豈 更 車 賈 滑 串 句 龜 龜 契 金 喇 奈 懶 癩 羅 蘿 螺 裸 邏 樂 洛 烙 珞 落 酪 駱 亂 卵 欄 爛 蘭 鸞 嵐 濫 藍 襤 拉 臘 蠟 廊 朗 浪 狼 郎 來 冷 勞 擄 櫓 爐 盧 老 蘆 虜 路 露 魯 鷺 碌 祿 綠 菉 錄 鹿 論 壟 弄 籠 聾 牢 磊 賂 雷 壘 屢 樓 淚 漏 累 縷 陋 勒 肋 凜 凌 稜 綾 菱 陵 讀 拏 樂 諾 丹 寧 怒 率 異 北 磻 便 復 不 泌 數 索 參 塞 省 葉 說 殺 辰 沈 拾 若 掠 略 亮 兩 凉 梁 糧 良 諒 量 勵 ..."
string_result := StringToString16(arena, string) string_result := StringToString16(arena, string)

View File

@@ -54,6 +54,7 @@ WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfChars
WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL
__debugbreak :: #foreign () __debugbreak :: #foreign ()
ExitProcess :: #foreign (uExitCode: UINT)
GetLastError :: #foreign (): DWORD GetLastError :: #foreign (): DWORD
QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL
QueryPerformanceCounter :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL QueryPerformanceCounter :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL