This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file exists only to name the gist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example how screen updates can be done even when DefaultWindowProc is | |
// resizing or moving the window. We catch WM_ENTERMENULOOP and WM_ENTERSIZEMOVE | |
// to start a timer to notify us every so often. This way we regain some of the | |
// control that DefaultWindowProc takes from us in these modal loops. | |
// | |
// When resizing or moving the window, you should see a glimmering red | |
// background that turns from dark to bright and back again in 180 screen | |
// updates. That cycle should take a few seconds - it's hard to say how long | |
// exactly since we're not explicitly synchronizing with the monitor and I'm not | |
// sure how often we can receive WM_PAINT. The 4ms from the SetTimer() call are |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* win32_proc_wait.cpp - Get notified when a Windows process terminates */ | |
#include <Windows.h> | |
typedef void Proc_Terminated_Callback(void *data); | |
/* Proc_Wait - Waiting for a process to finish on Win32. | |
Zero out a Proc_Wait structure before use. | |
Call proc_wait_open() to register an asynchronous wait operation for a process handle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple reference for what I think is a sane approach to structuring GUIs. | |
// Platform code is cleanly separated from the GUI code. | |
// Win32 backend (the OpenGL code is unused) | |
// Easy to port to other platforms - X11, SDL, OpenGL... | |
#include <Windows.h> | |
#include <windowsx.h> // GET_X_LPARAM(), GET_Y_LPARAM() | |
#include <mshtmcid.h> // IDM_CUT, IDM_COPY etc | |
#include <GL/gl.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <inttypes.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#ifdef _MSC_VER | |
#define NORETURN __declspec(noreturn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdarg.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <inttypes.h> | |
#define NORETURN __attribute__((noreturn)) | |
#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Baseline code (compiles on Linux) for sending UDP packets at a relatively | |
// high rate. With some modifications, this will be suited as a starting point | |
// to experiment with UDP-based transfer protocols. | |
// | |
// Achieves ~350 MiB/s (350K packets/s) on my laptop from 2011 (Lenovo x220, | |
// Sandy Bridge i5-2520M). | |
// | |
// Compile this as a binary "test" and run two instances in parallel (in two | |
// terminals). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Experiment: Intrusively linked list, implemented using C++ templates | |
// 2019, Jens Stimpfle | |
#include <assert.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
struct ListLink { | |
ListLink *next; | |
ListLink *prev; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Intrusively doubly linked lists boilerplate. Similar to Linux list.h | |
// 2020, Jens Stimpfle | |
typedef struct _ListNode ListNode; | |
typedef struct _List List; | |
struct _ListNode { | |
ListNode *next; | |
ListNode *prev; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Ringbuffers are surprisingly hard to code because wraparound | |
can split the readable / writeable region in two. This is the | |
cutest implementation that I've come up with so far. | |
NOT ACTUALLY TESTED | |
- jstimpfle, 2020-09 | |
*/ |
NewerOlder