summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-04-24 00:18:20 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-04-24 00:18:20 -0400
commit0e1fc86d08147cfbe9e85e28b9d54f31e78bacd8 (patch)
treeb226c2135c4b25a9b3b96210654ac30153f5ec3c /src/screen.c
parentremove old debug x11 code (diff)
downloadraycaster-0e1fc86d08147cfbe9e85e28b9d54f31e78bacd8.tar.gz
raycaster-0e1fc86d08147cfbe9e85e28b9d54f31e78bacd8.tar.bz2
raycaster-0e1fc86d08147cfbe9e85e28b9d54f31e78bacd8.zip
optimize x11
Diffstat (limited to '')
-rw-r--r--src/screen.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/screen.c b/src/screen.c
index 064c794..6446357 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -44,6 +44,9 @@ static void init_x() {
key_count = dpy->max_keycode - dpy->min_keycode;
key_state = malloc(sizeof(bool) * key_count);
key_checked = malloc(sizeof(bool) * key_count);
+
+ memset(key_state, 0, sizeof(bool) * key_count);
+ memset(key_checked, 0, sizeof(bool) * key_count);
}
static Window create_window(int x, int y, int w, int h, int d) {
@@ -54,7 +57,7 @@ static Window create_window(int x, int y, int w, int h, int d) {
exit(EXIT_FAILURE);
}
- Visual* visual = vis_info.visual;;
+ Visual* visual = vis_info.visual;
XSetWindowAttributes xwa;
xwa.background_pixel = 0;
@@ -69,14 +72,14 @@ static Window create_window(int x, int y, int w, int h, int d) {
return window;
}
-static XImage* create_image(int width, int height) {
+static XImage* create_image(int width, int height, void* data) {
return XCreateImage(
dpy,
CopyFromParent,
bit_depth,
ZPixmap,
0,
- malloc(width * height * bit_depth / 8),
+ data,
width,
height,
bit_depth,
@@ -118,7 +121,7 @@ void init_screen(struct Screen* screen, uint16_t width, uint16_t height) {
state->height = xwa.height;
screen->internal = state;
- XImage* image = create_image(state->width, state->height);
+ XImage* image = create_image(state->width, state->height, screen->pixels);
state->image = image;
count++;
@@ -145,22 +148,6 @@ static void update_delta(struct Screen* screen) {
static void draw_screen(struct Screen* screen) {
WindowState* state = (WindowState*) screen->internal;
- uint32_t* src = screen->pixels;
- uint32_t* dst = (uint32_t*) state->image->data;
-
- float x_step = screen->width / (float) state->width;
- float y_step = screen->height / (float) state->height;
-
- for (int x = 0; x < state->width; x++) {
- int px = (int) (x * x_step);
-
- for (int y = 0; y < state->height; y++) {
- int py = (int) (y * y_step);
-
- dst[x + y * state->width] = src[px + py * screen->width];
- }
- }
-
XPutImage(
dpy,
state->window,
@@ -199,9 +186,6 @@ static void handle_event(WindowState* state) {
state->width = xce.width;
state->height = xce.height;
- XDestroyImage(state->image);
- state->image = create_image(state->width, state->height);
-
break;
}