Improving multimedia, trying to add a single c library mode

This commit is contained in:
Krzosa Karol
2022-10-02 12:53:29 +02:00
parent 5baff3585e
commit e098663d82
9 changed files with 152 additions and 100 deletions

View File

@@ -1,20 +1,25 @@
#import "Base.core"
#import "Math.core"
#import "Arena.core"
W32 :: #load "win32_multimedia.core"
/*
Library for making games/graphical applications
* The api is very simple, very few function calls
* You retrieve information about the state of application from "Mu" struct
* Data is available in many different formats to avoid format conversions in user code
API and name inspired by one of Per Vognsen streams
https://www.youtube.com/watch?v=NG_mUhc8LRw&list=PLU94OURih-CjrtFuazwZ5GYzTrupOMDL7&index=19
All of his channel is recommended watch for programmers.
*/
StartMultimedia :: W32.StartMultimedia
UpdateMultimedia :: W32.UpdateMultimedia
Mu: MU
MU :: struct
scrn: *U32
x : S64
y : S64
screen: *U32
window: MUWindow
key: [Key.Count]KeyState
mouse: Mouse
frame_count: U64
time: MUTime
quit: Bool
@@ -22,6 +27,12 @@ MU :: struct
frame_arena: Arena
os: W32.OS
MUWindow :: struct
x: S64
y: S64
sizef: Vec2
MUTime :: struct
total : F64
delta : F64 // @modifiable
@@ -29,7 +40,7 @@ MUTime :: struct
frame_start: F64
KeyState :: struct
is_down: Bool
down: Bool
Key :: enum
Nil
@@ -41,5 +52,13 @@ Key :: enum
K2;K3;K4;K5;K6;K7;K8;K9
Count
StartMultimedia :: W32.StartMultimedia
UpdateMultimedia :: W32.UpdateMultimedia
Mouse :: struct
left: KeyState
right: KeyState
middle: KeyState
wheel: S64
#import "Base.core"
#import "Math.core"
#import "Arena.core"
W32 :: #load "win32_multimedia.core"

View File

@@ -103,21 +103,24 @@ WM_SYSKEYUP :: 0x0105
WM_SYSCHAR :: 0x0106
WM_SYSDEADCHAR :: 0x0107
WM_MOUSEFIRST :: 0x0200
WM_MOUSEMOVE :: 0x0200
WM_LBUTTONDOWN :: 0x0201
WM_LBUTTONUP :: 0x0202
WM_LBUTTONDBLCLK :: 0x0203
WM_RBUTTONDOWN :: 0x0204
WM_RBUTTONUP :: 0x0205
WM_RBUTTONDBLCLK :: 0x0206
WM_MBUTTONDOWN :: 0x0207
WM_MBUTTONUP :: 0x0208
WM_MBUTTONDBLCLK :: 0x0209
WM_MOUSEWHEEL :: 0x020A
VK_BACK :: 0x08
VK_TAB :: 0x09
/*
* 0x0A - 0x0B : reserved
*/
VK_CLEAR :: 0x0C
VK_RETURN :: 0x0D
/*
* 0x0E - 0x0F : unassigned
*/
VK_SHIFT :: 0x10
VK_CONTROL :: 0x11
VK_MENU :: 0x12
@@ -135,12 +138,10 @@ VK_KANJI :: 0x19
VK_IME_OFF :: 0x1A
VK_ESCAPE :: 0x1B
VK_CONVERT :: 0x1C
VK_NONCONVERT :: 0x1D
VK_ACCEPT :: 0x1E
VK_MODECHANGE :: 0x1F
VK_SPACE :: 0x20
VK_PRIOR :: 0x21
VK_NEXT :: 0x22
@@ -167,13 +168,7 @@ VK_HELP :: 0x2F
VK_LWIN :: 0x5B
VK_RWIN :: 0x5C
VK_APPS :: 0x5D
/*
* 0x5E : reserved
*/
VK_SLEEP :: 0x5F
VK_NUMPAD0 :: 0x60
VK_NUMPAD1 :: 0x61
VK_NUMPAD2 :: 0x62

View File

@@ -132,9 +132,11 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
Mu.os.window_dc = GetDC(Mu.os.window)
Mu.os.bitmap = W32.CreateBitmap(Mu.os.window_dc, size)
Mu.scrn = Mu.os.bitmap.data
Mu.x = size.x
Mu.y = size.y
Mu.screen = Mu.os.bitmap.data
Mu.window.x = size.x
Mu.window.y = size.y
Mu.window.sizef.x = Mu.window.x->F32
Mu.window.sizef.y = Mu.window.y->F32
UpdateMultimedia :: (): Bool
DrawBitmapInCompatibleDC(&Mu.os.bitmap)
@@ -145,12 +147,16 @@ UpdateMultimedia :: (): Bool
DispatchMessageW(&msg)
size := GetWindowSize(Mu.os.window)
if size.x != Mu.x || size.y != Mu.y
if size.x != Mu.window.x || size.y != Mu.window.y
DestroyBitmap(&Mu.os.bitmap)
CreateBitmap(Mu.os.window_dc, size)
Mu.x = size.x
Mu.y = size.y
Mu.screen = Mu.os.bitmap.data
Mu.window.x = size.x
Mu.window.y = size.y
Mu.window.sizef.x = Mu.window.x->F32
Mu.window.sizef.y = Mu.window.y->F32
Mu.frame_count += 1
frame_time := Time() - Mu.time.frame_start
@@ -177,10 +183,29 @@ WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
return 0
elif msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN
key := MapVKToKey(wparam)
Mu.key[key].is_down = true
Mu.key[key].down = true
elif msg == WM_KEYUP || msg == WM_SYSKEYUP
key := MapVKToKey(wparam)
Mu.key[key].is_down = false
Mu.key[key].down = false
elif msg == WM_LBUTTONDOWN ;; Mu.mouse.left.down = true
elif msg == WM_LBUTTONUP ;; Mu.mouse.left.down = false
elif msg == WM_RBUTTONDOWN ;; Mu.mouse.right.down = true
elif msg == WM_RBUTTONUP ;; Mu.mouse.right.down = false
elif msg == WM_MBUTTONDOWN ;; Mu.mouse.middle.down = true
elif msg == WM_MBUTTONUP ;; Mu.mouse.middle.down = false
elif msg == WM_MOUSEWHEEL
if wparam->int > 0
Mu.mouse.wheel = 1
else
Mu.mouse.wheel = -1
// Case(WM_CHAR){
// Utf32Result utf32 = Utf16ToUtf32((u16 *)&wparam, 1);
// if(!utf32.error){
// int index = OS->input_count;
// OS->input_count = ClampTop(OS->input_count + 1, (int)(ArrayCount(OS->input) - 1));
// OS->input[index] = utf32.out_str;
// }
// }Break;
else;; result = DefWindowProcW(hwnd, msg, wparam, lparam)