Working on multimedia

This commit is contained in:
Krzosa Karol
2022-10-01 17:07:36 +02:00
parent c85f16f673
commit d866ebb231
5 changed files with 56 additions and 25 deletions

View File

@@ -8,7 +8,7 @@ OS :: struct
bitmap: Bitmap
window_dc: HDC
window: HWND
good_scheduling: Bool
Bitmap :: struct
size: Vec2I
@@ -59,8 +59,10 @@ DrawBitmapInCompatibleDC :: (b: *Bitmap)
StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"): Mu
mu: Mu
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
good_scheduling = true
if timeBeginPeriod(1) == TIMERR_NOERROR
mu.os.good_scheduling = true
mu.time.start = Time()
hInstance := GetModuleHandleA(0)
window_name := StringToString16(&mu.frame_arena, title)
@@ -80,7 +82,7 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
hInstance = hInstance
)
Assert(mu.os.window != 0)
ShowWindow(mu.os.window, ShowCmd)
ShowWindow(mu.os.window, SW_SHOW)
mu.os.window_dc = GetDC(mu.os.window)
mu.os.bitmap = W32.CreateBitmap(mu.os.window_dc, {x,y})
@@ -91,24 +93,24 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
return mu
ShowCmd: int
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
ShowCmd = nShowCmd
// for AppIsRunning
// msg: MSG
// for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
// TranslateMessage(&msg)
// DispatchMessageW(&msg)
UpdateMultimedia :: (mu: *Mu): Bool
mu.frame_count += 1
frame_time := Time() - mu.time.frame_start
mu.time.total += frame_time
if frame_time < mu.time.delta
if mu.os.good_scheduling
time_to_sleep := (mu.time.delta - 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)
// for y := 0, y < bitmap.size.y, y+=1
// for x := 0, x < bitmap.size.x, x+=1
// bitmap.data[x + y*bitmap.size.x] = 0xFFFF0000
// W32.DrawBitmapInCompatibleDC(&bitmap)
// Sleep(100)
return 0
new_frame_time := Time()
for new_frame_time < mu.time.delta
new_frame_time = Time() - mu.time.frame_start
mu.time.frame_start = Time()
return !mu.quit
AppIsRunning := true
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT