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

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

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
Raymarcher_Update()
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
frame_number += 1
TotalTime += frame_time
@@ -203,3 +201,6 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
new_frame_time = Time() - frame_start_time
frame_time = new_frame_time
if CStringCompare(lpCmdLine, "testing")
ExitProcess(0)