Working on multimedia
This commit is contained in:
@@ -35,4 +35,5 @@ main :: (): int
|
|||||||
|
|
||||||
mu: Mu = Start(x = 1280, y = 720)
|
mu: Mu = Start(x = 1280, y = 720)
|
||||||
Assert(mu.x == 1280 && mu.y == 720)
|
Assert(mu.x == 1280 && mu.y == 720)
|
||||||
|
|
||||||
return 0
|
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
|
x : S64
|
||||||
y : S64
|
y : S64
|
||||||
|
|
||||||
|
frame_count: U64
|
||||||
|
time: MuTime
|
||||||
|
quit: Bool
|
||||||
|
|
||||||
frame_arena: Arena
|
frame_arena: Arena
|
||||||
os: W32.OS
|
os: W32.OS
|
||||||
|
|
||||||
StartMultimedia :: W32.StartMultimedia
|
MuTime :: struct
|
||||||
// UpdateMultimedia :: W32.UpdateMultimedia
|
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_NOREMOVE :: 0
|
||||||
PM_REMOVE :: 0x0001
|
PM_REMOVE :: 0x0001
|
||||||
PM_NOYIELD :: 0x0002
|
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
|
bitmap: Bitmap
|
||||||
window_dc: HDC
|
window_dc: HDC
|
||||||
window: HWND
|
window: HWND
|
||||||
|
good_scheduling: Bool
|
||||||
|
|
||||||
Bitmap :: struct
|
Bitmap :: struct
|
||||||
size: Vec2I
|
size: Vec2I
|
||||||
@@ -59,8 +59,10 @@ DrawBitmapInCompatibleDC :: (b: *Bitmap)
|
|||||||
|
|
||||||
StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"): Mu
|
StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"): Mu
|
||||||
mu: Mu
|
mu: Mu
|
||||||
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
|
if timeBeginPeriod(1) == TIMERR_NOERROR
|
||||||
good_scheduling = true
|
mu.os.good_scheduling = true
|
||||||
|
|
||||||
|
mu.time.start = Time()
|
||||||
|
|
||||||
hInstance := GetModuleHandleA(0)
|
hInstance := GetModuleHandleA(0)
|
||||||
window_name := StringToString16(&mu.frame_arena, title)
|
window_name := StringToString16(&mu.frame_arena, title)
|
||||||
@@ -80,7 +82,7 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
|
|||||||
hInstance = hInstance
|
hInstance = hInstance
|
||||||
)
|
)
|
||||||
Assert(mu.os.window != 0)
|
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.window_dc = GetDC(mu.os.window)
|
||||||
mu.os.bitmap = W32.CreateBitmap(mu.os.window_dc, {x,y})
|
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
|
return mu
|
||||||
|
|
||||||
ShowCmd: int
|
UpdateMultimedia :: (mu: *Mu): Bool
|
||||||
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
|
mu.frame_count += 1
|
||||||
ShowCmd = nShowCmd
|
frame_time := Time() - mu.time.frame_start
|
||||||
// for AppIsRunning
|
mu.time.total += frame_time
|
||||||
// msg: MSG
|
if frame_time < mu.time.delta
|
||||||
// for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
|
if mu.os.good_scheduling
|
||||||
// TranslateMessage(&msg)
|
time_to_sleep := (mu.time.delta - frame_time) * 1000
|
||||||
// DispatchMessageW(&msg)
|
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
|
new_frame_time := Time()
|
||||||
// for x := 0, x < bitmap.size.x, x+=1
|
for new_frame_time < mu.time.delta
|
||||||
// bitmap.data[x + y*bitmap.size.x] = 0xFFFF0000
|
new_frame_time = Time() - mu.time.frame_start
|
||||||
|
|
||||||
// W32.DrawBitmapInCompatibleDC(&bitmap)
|
|
||||||
// Sleep(100)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
mu.time.frame_start = Time()
|
||||||
|
return !mu.quit
|
||||||
|
|
||||||
AppIsRunning := true
|
AppIsRunning := true
|
||||||
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
|
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
|
||||||
|
|||||||
Reference in New Issue
Block a user