From 73b1fd787554e7a3cdd778393d846e662022e7d7 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 4 Aug 2024 05:46:18 +0200 Subject: Add p_render_frame proc; Fix delete window atom --- examples/landscape.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/landscape.c b/examples/landscape.c index cb0fefc..624183e 100755 --- a/examples/landscape.c +++ b/examples/landscape.c @@ -86,7 +86,7 @@ enum { IPv4 = 1, IPv6 = 2, - + BUTTON_LEFT = 256, BUTTON_MIDDLE, BUTTON_RIGHT, @@ -147,6 +147,7 @@ typedef i64 (*Thread_Proc)(void *user_data); void p_init(void); void p_cleanup(void); i32 p_handle_events(void); +void p_render_frame(void); // Sound void p_handle_audio(i64 time_elapsed); @@ -474,7 +475,7 @@ u32 u32_from_rgb(f32 red, f32 green, f32 blue) { i32 main(i32 argc, c8 **argv) { (void) argc; (void) argv; - + u32 background = u32_from_rgb(.03f, .08f, .01f); platform = (Platform) { @@ -542,6 +543,8 @@ i32 main(i32 argc, c8 **argv) { for (i32 k = 0; k < world.num_entities; ++k) e_render(k); + + p_render_frame(); } p_cleanup(); @@ -576,6 +579,7 @@ i64 p_recv(u16 slot, IP_Address address, i64 size, u8 *data, IP_Address *remote_ (void) address; (void) size; (void) data; + (void) remote_address; assert(0); return 0; } @@ -749,7 +753,7 @@ void p_init(void) { XInitImage(&_image); - _wm_delete_window = XInternAtom(_display, "WM_DELETE__WINDOW", False); + _wm_delete_window = XInternAtom(_display, "WM_DELETE_WINDOW", False); XSetWMProtocols(_display, _window, &_wm_delete_window, 1); @@ -763,16 +767,6 @@ void p_cleanup(void) { } i32 p_handle_events(void) { - XEvent ev; - XWindowAttributes attrs; - - XGetWindowAttributes(_display, _window, &attrs); - - if (attrs.width == platform.frame_width && attrs.height == platform.frame_height) - XPutImage(_display, _window, _gc, &_image, 0, 0, 0, 0, attrs.width, attrs.height); - - XFlush(_display); - i32 num_events = XEventsQueued(_display, QueuedAlready); memset(platform.key_pressed, 0, sizeof platform.key_pressed); @@ -781,6 +775,8 @@ i32 p_handle_events(void) { platform.cursor_dy = 0; platform.wheel_dy = 0; + XEvent ev; + for (i32 i = 0; i < num_events; ++i) { XNextEvent(_display, &ev); @@ -857,6 +853,9 @@ i32 p_handle_events(void) { } } + XWindowAttributes attrs; + XGetWindowAttributes(_display, _window, &attrs); + if ((platform.frame_width != attrs.width || platform.frame_height != attrs.height) && attrs.width * attrs.height * 4 <= (i32) sizeof _buffer) { if (attrs.width > 0 && attrs.height > 0) { _image.width = attrs.width; @@ -871,6 +870,14 @@ i32 p_handle_events(void) { return num_events; } +void p_render_frame(void) { + if (platform.done) + return; + + XPutImage(_display, _window, _gc, &_image, 0, 0, 0, 0, platform.frame_width, platform.frame_height); + XFlush(_display); +} + #endif // ================================================================ -- cgit v1.2.3