Skip to content
Snippets Groups Projects
Commit 1a5fe6e2 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Some optimizations and clearing realloc()ed data.

parent f5a3570f
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2088 passed
...@@ -8067,6 +8067,11 @@ pixel2color(uint32_t pix) ...@@ -8067,6 +8067,11 @@ pixel2color(uint32_t pix)
break; break;
} }
if (i == 16) { if (i == 16) {
for (i = 0; i < 256; i++) {
if (map_rip_color(i) == pix)
break;
}
if (i == 256)
printf("TODO: Unable to convert color %08" PRIx32 " to palette color\n", pix); printf("TODO: Unable to convert color %08" PRIx32 " to palette color\n", pix);
return 0; return 0;
} }
...@@ -9418,7 +9423,9 @@ reinit_screen(uint8_t *font, int fx, int fy) ...@@ -9418,7 +9423,9 @@ reinit_screen(uint8_t *font, int fx, int fy)
term.width = cols; term.width = cols;
term.height = rows; term.height = rows;
// Now, make the vmem array large enough for the new bits... // Now, make the vmem array large enough for the new bits...
// TODO: Handle failures!
nvmem = realloc(vstat.vmem->vmem, vstat.cols * vstat.rows * sizeof(vstat.vmem->vmem[0])); nvmem = realloc(vstat.vmem->vmem, vstat.cols * vstat.rows * sizeof(vstat.vmem->vmem[0]));
memset(nvmem, 0, vstat.cols * vstat.rows * sizeof(vstat.vmem->vmem[0]));
// And use it. // And use it.
vstat.vmem->vmem = nvmem; vstat.vmem->vmem = nvmem;
} }
...@@ -10385,11 +10392,18 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10385,11 +10392,18 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
arg1 = parse_mega(&args[16], 2); arg1 = parse_mega(&args[16], 2);
x2 = xp[0]; x2 = xp[0];
y2 = yp[0]; y2 = yp[0];
// TODO: We should be able to parallelize this...
for (arg2 = 1; arg2 < arg1; arg2++) { for (arg2 = 1; arg2 < arg1; arg2++) {
double tf = ((double)arg2) / arg1; double tf = ((double)arg2) / arg1;
double tr = ((double)(arg1 - arg2)) / arg1; double tr = ((double)(arg1 - arg2)) / arg1;
x1 = pow(tr, 3) * xp[0] + 3 * tf * pow(tr, 2) * xp[1] + 3 * pow(tf, 2) * tr * xp[2] + pow(tf, 3) * xp[3]; double tfs = pow(tf, 2);
y1 = pow(tr, 3) * yp[0] + 3 * tf * pow(tr, 2) * yp[1] + 3 * pow(tf, 2) * tr * yp[2] + pow(tf, 3) * yp[3]; double tfstr = tfs * tr;
double tfc = pow(tf, 3);
double trs = pow(tr, 2);
double tftrs = tf * trs;
double trc = pow(tr, 3);
x1 = trc * xp[0] + 3 * tftrs * xp[1] + 3 * tfstr * xp[2] + tfc * xp[3];
y1 = trc * yp[0] + 3 * tftrs * yp[1] + 3 * tfstr * yp[2] + tfc * yp[3];
//x1 = tr * tr * tr * xp[0] + 3 * tf * tr * tr * xp[1] + 3 * tf * tf * tr * xp[2] + tf * tf * tf * xp[3]; //x1 = tr * tr * tr * xp[0] + 3 * tf * tr * tr * xp[1] + 3 * tf * tf * tr * xp[2] + tf * tf * tf * xp[3];
//y1 = tr * tr * tr * yp[0] + 3 * tf * tr * tr * yp[1] + 3 * tf * tf * tr * yp[2] + tf * tf * tf * yp[3]; //y1 = tr * tr * tr * yp[0] + 3 * tf * tr * tr * yp[1] + 3 * tf * tf * tr * yp[2] + tf * tf * tf * yp[3];
draw_line(x2, y2, x1, y1); draw_line(x2, y2, x1, y1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment