diff --git a/examples/constant_expressions.core b/examples/constant_expressions.core index 5d867d5..aa6a78e 100644 --- a/examples/constant_expressions.core +++ b/examples/constant_expressions.core @@ -35,4 +35,5 @@ main :: (): int mu: Mu = Start(x = 1280, y = 720) Assert(mu.x == 1280 && mu.y == 720) + return 0 \ No newline at end of file diff --git a/examples/using_multimedia.core b/examples/using_multimedia.core new file mode 100644 index 0000000..a516882 --- /dev/null +++ b/examples/using_multimedia.core @@ -0,0 +1,7 @@ +#import "Multimedia.core" + +WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int + mu := StartMultimedia(title = "Hello, people!") + + for UpdateMultimedia(&mu) + pass \ No newline at end of file diff --git a/modules/Multimedia.core b/modules/Multimedia.core index a5df198..f113f18 100644 --- a/modules/Multimedia.core +++ b/modules/Multimedia.core @@ -13,12 +13,20 @@ Mu :: struct x : S64 y : S64 + frame_count: U64 + time: MuTime + quit: Bool frame_arena: Arena os: W32.OS -StartMultimedia :: W32.StartMultimedia -// UpdateMultimedia :: W32.UpdateMultimedia +MuTime :: struct + total : F64 + delta : F64 // @modifiable + start : F64 + frame_start: F64 -start :: () - mu := StartMultimedia() \ No newline at end of file + + +StartMultimedia :: W32.StartMultimedia +UpdateMultimedia :: W32.UpdateMultimedia diff --git a/modules/USER32.core b/modules/USER32.core index d3b68bd..2254c53 100644 --- a/modules/USER32.core +++ b/modules/USER32.core @@ -51,4 +51,17 @@ WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | PM_NOREMOVE :: 0 PM_REMOVE :: 0x0001 -PM_NOYIELD :: 0x0002 \ No newline at end of file +PM_NOYIELD :: 0x0002 + +SW_HIDE :: 0 +SW_NORMAL :: 1 +SW_SHOWMINIMIZED :: 2 +SW_SHOWMAXIMIZED :: 3 +SW_SHOWNOACTIVATE :: 4 +SW_SHOW :: 5 +SW_MINIMIZE :: 6 +SW_SHOWMINNOACTIVE :: 7 +SW_SHOWNA :: 8 +SW_RESTORE :: 9 +SW_SHOWDEFAULT :: 10 +SW_FORCEMINIMIZE :: 11 \ No newline at end of file diff --git a/modules/win32_multimedia.core b/modules/win32_multimedia.core index d1e88c1..0ea00d7 100644 --- a/modules/win32_multimedia.core +++ b/modules/win32_multimedia.core @@ -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