Working on multimedia
This commit is contained in:
@@ -35,4 +35,5 @@ main :: (): int
|
||||
|
||||
mu: Mu = Start(x = 1280, y = 720)
|
||||
Assert(mu.x == 1280 && mu.y == 720)
|
||||
|
||||
return 0
|
||||
7
examples/using_multimedia.core
Normal file
7
examples/using_multimedia.core
Normal file
@@ -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
|
||||
@@ -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()
|
||||
|
||||
|
||||
StartMultimedia :: W32.StartMultimedia
|
||||
UpdateMultimedia :: W32.UpdateMultimedia
|
||||
|
||||
@@ -52,3 +52,16 @@ WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
|
||||
PM_NOREMOVE :: 0
|
||||
PM_REMOVE :: 0x0001
|
||||
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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user