summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-06 18:40:57 +1000
committerquou <quou@disroot.org>2024-07-06 18:40:57 +1000
commit2693d0e46cf55c613e560d2eed8a2f762fe76bb5 (patch)
treeeda3c4571c16e24602e5adc3d59b2b99aef3e3cf
parente6f8a3356a91e0304e9965c7b8bfc2f06a2b79cc (diff)
Allocate a max viewport so that re-creating images isn't needed.
-rw-r--r--3de.c2
-rw-r--r--config.h6
-rw-r--r--plat.c39
3 files changed, 24 insertions, 23 deletions
diff --git a/3de.c b/3de.c
index 8af3d18..fdfd7aa 100644
--- a/3de.c
+++ b/3de.c
@@ -68,7 +68,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
app = new_app(&h, 640, 480, "3D Engine");
if (!app) return app->err;
init_fps(&f, 20);
- depth = heap_alloc(&h, 3000 * 3000 * sizeof *depth);
+ depth = heap_alloc(&h, max_vp_w * max_vp_h * sizeof *depth);
if (!depth) {
print_err("Out of memory.\n");
return error_out_of_memory;
diff --git a/config.h b/config.h
index 31e98f4..59554ee 100644
--- a/config.h
+++ b/config.h
@@ -4,4 +4,10 @@
#define memory_size (1024 * 1024 * 128)
#define app_memory_size (1024 * 1024 * 64)
+#define max_vp_w 2000
+#define max_vp_h 2000
+
+#define max_pc_window_w 5000
+#define max_pc_window_h 3000
+
#endif
diff --git a/plat.c b/plat.c
index e0d72be..f0d60ba 100644
--- a/plat.c
+++ b/plat.c
@@ -1,5 +1,6 @@
#include "config.h"
#include "error.h"
+#include "maths.h"
#include "memory.h"
#include "plat.h"
@@ -184,16 +185,10 @@ void init_rendering(
XWindowAttributes* wa
) {
Colour* p, * fb;
- int w = i->w = wa->width;
- int h = i->h = wa->height;
- int tw = (w + a->s) / a->s;
- int th = (h + a->s) / a->s;
- a->w = tw;
- a->h = th;
- if (i->bb) {
- heap_free(a->heap, a->fb);
- XDestroyImage(i->bb);
- }
+ int w = max_pc_window_w;
+ int h = max_pc_window_h;
+ int tw = max_vp_w;
+ int th = max_vp_h;
p = malloc(sizeof *p * w * h);
fb = heap_alloc(a->heap, sizeof *p * tw * th);
if (!p || !fb) {
@@ -275,6 +270,10 @@ void init_window(App* a, App_Internal* i, const char* n) {
print_war("Detected BGR. Colours will look fucked.\n");
}
init_rendering(a, i, &wa);
+ a->w = (wa.width + a->s) / a->s;
+ a->h = (wa.height + a->s) / a->s;
+ i->w = wa.width;
+ i->h = wa.height;
}
App* new_app(Heap* mem, int w, int h, const char* n) {
@@ -315,7 +314,6 @@ void app_begin(App* a) {
while (XPending(d)) {
XEvent e;
XWindowAttributes wa;
- int nw, nh;
XNextEvent(d, &e);
switch (e.type) {
case ClientMessage:
@@ -328,15 +326,12 @@ void app_begin(App* a) {
break;
case Expose:
XGetWindowAttributes(d, w, &wa);
- nw = wa.width;
- nh = wa.height;
- if (
- !i->bb ||
- nw != i->w ||
- nh != i->h
- ) {
- init_rendering(a, i, &wa);
- }
+ a->w = (wa.width + a->s) / a->s;
+ a->h = (wa.height + a->s) / a->s;
+ a->w = mini(a->w, max_vp_w);
+ a->h = mini(a->h, max_vp_w);
+ i->w = mini(wa.width, max_pc_window_w);
+ i->h = mini(wa.height, max_pc_window_h);
break;
case MotionNotify:
a->mx = e.xmotion.x / a->s;
@@ -362,7 +357,7 @@ void app_rencpy(
int ix, iy, sw, sh, dw, dh;
int dsx, dsy;
int dex, dey;
- int pidx, fbits = 9;
+ int pidx;
Colour* dst;
const Colour* src;
unsigned char t;
@@ -385,7 +380,7 @@ void app_rencpy(
for (ix = dsx; ix < dex; ix++) {
sx = (rat_x * (ix << fbits)) >> (fbits * 2);
pidx = sx + sy * sw;
- dst = &i->bbp[ix + iy * dw];
+ dst = &i->bbp[ix + iy * max_pc_window_w];
*dst = src[pidx];
t = dst->r;
dst->r = dst->b;