bugfixes and improvements
credit to blendi for fixing the depth mapper
This commit is contained in:
1
TODO.md
1
TODO.md
@@ -1,6 +1,5 @@
|
|||||||
# For MVP functionality
|
# For MVP functionality
|
||||||
|
|
||||||
- fix coloring issue in UlOS 2 beta 5 (and in OpenOS `dmesg`, it appears color-mapper is wrong)
|
|
||||||
- make `computer` component use callbacks
|
- make `computer` component use callbacks
|
||||||
- make a lot of stuff which likely will need to be indirect actually be indirect (modem comms, computer funcs)
|
- make a lot of stuff which likely will need to be indirect actually be indirect (modem comms, computer funcs)
|
||||||
- make beeps, power, etc. be callbacks on one shared local state (computer environment)
|
- make beeps, power, etc. be callbacks on one shared local state (computer environment)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ local syncedMethodStats
|
|||||||
|
|
||||||
local function realInvoke(address, method, ...)
|
local function realInvoke(address, method, ...)
|
||||||
local t = {pcall(cinvoke, address, method, ...)}
|
local t = {pcall(cinvoke, address, method, ...)}
|
||||||
if not _SYNCED then
|
if not _SYNCED and not os.getenv("NN_FAST") then
|
||||||
if computer.energy() <= 0 then sysyield() end -- out of power
|
if computer.energy() <= 0 then sysyield() end -- out of power
|
||||||
if computer.isOverused() then sysyield() end -- overused
|
if computer.isOverused() then sysyield() end -- overused
|
||||||
if computer.isIdle() then sysyield() end -- machine idle
|
if computer.isIdle() then sysyield() end -- machine idle
|
||||||
|
|||||||
@@ -496,6 +496,7 @@ int main(int argc, char **argv) {
|
|||||||
nn_mountComponent(c, testFlash, 5, false);
|
nn_mountComponent(c, testFlash, 5, false);
|
||||||
int ltx = 0, lty = 0;
|
int ltx = 0, lty = 0;
|
||||||
double scrollBuf = 0;
|
double scrollBuf = 0;
|
||||||
|
SetTargetFPS(60);
|
||||||
while(true) {
|
while(true) {
|
||||||
if(WindowShouldClose()) break;
|
if(WindowShouldClose()) break;
|
||||||
|
|
||||||
|
|||||||
@@ -2909,9 +2909,9 @@ void nn_initPalettes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void nn_splitColor(int color, double *r, double *g, double *b) {
|
static void nn_splitColor(int color, double *r, double *g, double *b) {
|
||||||
int _r = (color >> 16) & 0xFF;
|
unsigned int _r = (color >> 16) & 0xFF;
|
||||||
int _g = (color >> 8) & 0xFF;
|
unsigned int _g = (color >> 8) & 0xFF;
|
||||||
int _b = (color >> 0) & 0xFF;
|
unsigned int _b = (color >> 0) & 0xFF;
|
||||||
|
|
||||||
*r = (double)_r / 255;
|
*r = (double)_r / 255;
|
||||||
*g = (double)_g / 255;
|
*g = (double)_g / 255;
|
||||||
@@ -2925,10 +2925,20 @@ double nn_colorLuminance(int color) {
|
|||||||
return r * 0.2126 + g * 0.7152 + b * 0.0722;
|
return r * 0.2126 + g * 0.7152 + b * 0.0722;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Credit to Blendi for writing this, the old algorithm based off luminance gave bad results
|
||||||
static double nn_colorDistance(int a, int b) {
|
static double nn_colorDistance(int a, int b) {
|
||||||
double n = nn_colorLuminance(a) - nn_colorLuminance(b);
|
// double n = nn_colorLuminance(a) - nn_colorLuminance(b);
|
||||||
if(n < 0) n = -n;
|
// if(n < 0) n = -n;
|
||||||
return n;
|
|
||||||
|
double ar,ag,ab;
|
||||||
|
double br,bg,bb;
|
||||||
|
|
||||||
|
nn_splitColor(a, &ar, &ag, &ab);
|
||||||
|
nn_splitColor(b, &br, &bg, &bb);
|
||||||
|
|
||||||
|
double dr = ar-br, dg = ag-bg, db = ab-bb;
|
||||||
|
|
||||||
|
return ((dr < 0) ? -dr : dr) + ((dg < 0) ? -dg : dg) + ((db < 0) ? -db : db);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nn_mapColor(int color, int *palette, size_t len) {
|
int nn_mapColor(int color, int *palette, size_t len) {
|
||||||
@@ -2938,7 +2948,7 @@ int nn_mapColor(int color, int *palette, size_t len) {
|
|||||||
for(size_t i = 0; i < len; i++) {
|
for(size_t i = 0; i < len; i++) {
|
||||||
int entry = palette[i];
|
int entry = palette[i];
|
||||||
double dist = nn_colorDistance(color, entry);
|
double dist = nn_colorDistance(color, entry);
|
||||||
if(dist < bestDist) {
|
if(dist <= bestDist) {
|
||||||
bestDist = dist;
|
bestDist = dist;
|
||||||
bestColor = entry;
|
bestColor = entry;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user