mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
Compare commits
5 Commits
905a5a25fa
...
6a90d6306d
Author | SHA1 | Date | |
---|---|---|---|
|
6a90d6306d | ||
|
e9e02a2473 | ||
|
eb6037ee27 | ||
|
8288f647c1 | ||
|
cb250d162f |
@ -1,6 +1,13 @@
|
|||||||
#include "hologram.h"
|
#include "hologram.h"
|
||||||
|
|
||||||
void nn_hologram_clear() {
|
// safety:
|
||||||
|
// For valid indexes to be valid,
|
||||||
|
// stuff must be from 0 to limit - 1
|
||||||
|
nn_size_t nn_positionToIndex(nn_hologram *h, unsigned x, unsigned y, unsigned z) {
|
||||||
|
return x + y * h->width_x + z * h->width_x * h->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nn_hologram_clear(nn_hologram *h) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,8 +338,8 @@ nn_component *nn_addScreen(nn_computer *computer, nn_address address, int slot,
|
|||||||
return nn_newComponent(computer, address, slot, screenTable, screen);
|
return nn_newComponent(computer, address, slot, screenTable, screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int nni_mcBlack = 0x1D1D21;
|
static const int nni_mcBlack = 0x000000;
|
||||||
static const int nni_mcWhite = 0xFFF9FE;
|
static const int nni_mcWhite = 0xFFFFFF;
|
||||||
|
|
||||||
void nn_getStd4BitPalette(int color[16]) {
|
void nn_getStd4BitPalette(int color[16]) {
|
||||||
color[0] = nni_mcWhite; // white
|
color[0] = nni_mcWhite; // white
|
||||||
@ -360,6 +360,27 @@ void nn_getStd4BitPalette(int color[16]) {
|
|||||||
color[15] = nni_mcBlack; // black
|
color[15] = nni_mcBlack; // black
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nn_getLegacy4BitPalette(int color[16]) {
|
||||||
|
// taken from https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/src/main/scala/li/cil/oc/util/PackedColor.scala
|
||||||
|
|
||||||
|
color[0] = 0xFFFFFF;
|
||||||
|
color[1] = 0xFFCC33;
|
||||||
|
color[2] = 0xCC66CC;
|
||||||
|
color[3] = 0x6699FF;
|
||||||
|
color[4] = 0xFFFF33;
|
||||||
|
color[5] = 0x33CC33;
|
||||||
|
color[6] = 0xFF6699;
|
||||||
|
color[7] = 0x333333;
|
||||||
|
color[8] = 0xCCCCCC;
|
||||||
|
color[9] = 0x336699;
|
||||||
|
color[10] = 0x9933CC;
|
||||||
|
color[11] = 0x333399;
|
||||||
|
color[12] = 0x663300;
|
||||||
|
color[13] = 0x336600;
|
||||||
|
color[14] = 0xFF3333;
|
||||||
|
color[15] = 0x000000;
|
||||||
|
}
|
||||||
|
|
||||||
void nn_getStd8BitPalette(int color[256]) {
|
void nn_getStd8BitPalette(int color[256]) {
|
||||||
// source: https://ocdoc.cil.li/component:gpu
|
// source: https://ocdoc.cil.li/component:gpu
|
||||||
int reds[6] = {0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF};
|
int reds[6] = {0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF};
|
||||||
@ -399,17 +420,28 @@ static nn_bool_t nni_4bit_did = false;
|
|||||||
static int nni_8bit_colors[256];
|
static int nni_8bit_colors[256];
|
||||||
static nn_bool_t nni_8bit_did = false;
|
static nn_bool_t nni_8bit_did = false;
|
||||||
|
|
||||||
int nn_mapDepth(int color, int depth) {
|
static int nni_4bitl_colors[16];
|
||||||
|
static nn_bool_t nni_4bitl_did = false;
|
||||||
|
|
||||||
|
int nn_mapDepth(int color, int depth, nn_bool_t legacy) {
|
||||||
if(depth == 1) {
|
if(depth == 1) {
|
||||||
if(color == 0) return nni_mcBlack;
|
if(color == 0) return nni_mcBlack;
|
||||||
return nni_mcWhite;
|
return nni_mcWhite;
|
||||||
}
|
}
|
||||||
if(depth == 4) {
|
if(depth == 4) {
|
||||||
if(!nni_4bit_did) {
|
if(legacy) {
|
||||||
nni_4bit_did = true;
|
if(!nni_4bitl_did) {
|
||||||
nn_getStd4BitPalette(nni_4bit_colors);
|
nni_4bitl_did = true;
|
||||||
}
|
nn_getLegacy4BitPalette(nni_4bitl_colors);
|
||||||
return nn_mapColor(color, nni_4bit_colors, 16);
|
}
|
||||||
|
return nn_mapColor(color, nni_4bitl_colors, 16);
|
||||||
|
} else {
|
||||||
|
if(!nni_4bit_did) {
|
||||||
|
nni_4bit_did = true;
|
||||||
|
nn_getStd4BitPalette(nni_4bit_colors);
|
||||||
|
}
|
||||||
|
return nn_mapColor(color, nni_4bit_colors, 16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(depth == 8) {
|
if(depth == 8) {
|
||||||
if(!nni_8bit_did) {
|
if(!nni_8bit_did) {
|
||||||
|
@ -9,7 +9,7 @@ typedef struct nn_signal {
|
|||||||
} nn_signal;
|
} nn_signal;
|
||||||
|
|
||||||
typedef struct nn_resource_t {
|
typedef struct nn_resource_t {
|
||||||
size_t id;
|
nn_size_t id;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
nn_resourceTable_t *table;
|
nn_resourceTable_t *table;
|
||||||
} nn_resource_t;
|
} nn_resource_t;
|
||||||
|
@ -557,8 +557,11 @@ typedef struct ne_premappedPixel {
|
|||||||
int mappedFgRes;
|
int mappedFgRes;
|
||||||
int mappedBgFor;
|
int mappedBgFor;
|
||||||
int mappedBgRes;
|
int mappedBgRes;
|
||||||
|
nn_bool_t legacyColors;
|
||||||
} ne_premappedPixel;
|
} ne_premappedPixel;
|
||||||
|
|
||||||
|
bool ne_legacyColors = false;
|
||||||
|
|
||||||
ne_premappedPixel ne_getPremap(ne_premappedPixel *pixels, nn_screen *screen, int x, int y) {
|
ne_premappedPixel ne_getPremap(ne_premappedPixel *pixels, nn_screen *screen, int x, int y) {
|
||||||
int maxW, maxH;
|
int maxW, maxH;
|
||||||
nn_maxResolution(screen, &maxW, &maxH);
|
nn_maxResolution(screen, &maxW, &maxH);
|
||||||
@ -571,6 +574,11 @@ ne_premappedPixel ne_getPremap(ne_premappedPixel *pixels, nn_screen *screen, int
|
|||||||
int fg = pixel.fg;
|
int fg = pixel.fg;
|
||||||
int bg = pixel.bg;
|
int bg = pixel.bg;
|
||||||
|
|
||||||
|
if(premapped.legacyColors != ne_legacyColors) {
|
||||||
|
premapped.legacyColors = ne_legacyColors;
|
||||||
|
premapped.mappedDepth = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(premapped.mappedDepth != depth) {
|
if(premapped.mappedDepth != depth) {
|
||||||
premapped.mappedDepth = depth;
|
premapped.mappedDepth = depth;
|
||||||
premapped.mappedFgFor = -1;
|
premapped.mappedFgFor = -1;
|
||||||
@ -578,14 +586,15 @@ ne_premappedPixel ne_getPremap(ne_premappedPixel *pixels, nn_screen *screen, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool miss = false;
|
bool miss = false;
|
||||||
|
|
||||||
if(premapped.mappedFgFor != fg) {
|
if(premapped.mappedFgFor != fg) {
|
||||||
premapped.mappedFgFor = fg;
|
premapped.mappedFgFor = fg;
|
||||||
premapped.mappedFgRes = nn_mapDepth(fg, depth);
|
premapped.mappedFgRes = nn_mapDepth(fg, depth, ne_legacyColors);
|
||||||
miss = true;
|
miss = true;
|
||||||
}
|
}
|
||||||
if(premapped.mappedBgFor != bg) {
|
if(premapped.mappedBgFor != bg) {
|
||||||
premapped.mappedBgFor = bg;
|
premapped.mappedBgFor = bg;
|
||||||
premapped.mappedBgRes = nn_mapDepth(bg, depth);
|
premapped.mappedBgRes = nn_mapDepth(bg, depth, ne_legacyColors);
|
||||||
miss = true;
|
miss = true;
|
||||||
}
|
}
|
||||||
premapped.codepoint = pixel.codepoint;
|
premapped.codepoint = pixel.codepoint;
|
||||||
@ -618,7 +627,7 @@ void ne_log(void *_, void *__, nn_component *component, nn_computer *computer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char **argv) {
|
||||||
printf("Setting up universe\n");
|
printf("Setting up universe\n");
|
||||||
nn_Context ctx = nn_libcContext();
|
nn_Context ctx = nn_libcContext();
|
||||||
nn_Alloc alloc = ctx.allocator;
|
nn_Alloc alloc = ctx.allocator;
|
||||||
@ -665,7 +674,7 @@ int main() {
|
|||||||
|
|
||||||
nn_addEEPROM(computer, NULL, 0, genericEEPROM);
|
nn_addEEPROM(computer, NULL, 0, genericEEPROM);
|
||||||
|
|
||||||
nn_address fsFolder = "OpenOS";
|
nn_address fsFolder = argc > 1 ? argv[1] : "OpenOS";
|
||||||
nn_filesystemTable genericFSTable = {
|
nn_filesystemTable genericFSTable = {
|
||||||
.userdata = fsFolder,
|
.userdata = fsFolder,
|
||||||
.deinit = NULL,
|
.deinit = NULL,
|
||||||
@ -739,7 +748,7 @@ int main() {
|
|||||||
int maxWidth = 80, maxHeight = 32;
|
int maxWidth = 80, maxHeight = 32;
|
||||||
|
|
||||||
nn_screen *s = nn_newScreen(&ctx, maxWidth, maxHeight, 24, 16, 256);
|
nn_screen *s = nn_newScreen(&ctx, maxWidth, maxHeight, 24, 16, 256);
|
||||||
nn_setDepth(s, 4); // looks cool
|
nn_setDepth(s, 8); // looks cool
|
||||||
nn_addKeyboard(s, "shitty keyboard");
|
nn_addKeyboard(s, "shitty keyboard");
|
||||||
nn_mountKeyboard(computer, "shitty keyboard", 2);
|
nn_mountKeyboard(computer, "shitty keyboard", 2);
|
||||||
nn_addScreen(computer, NULL, 2, s);
|
nn_addScreen(computer, NULL, 2, s);
|
||||||
@ -914,6 +923,19 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render:
|
render:
|
||||||
|
if(IsKeyPressed(KEY_F1)) {
|
||||||
|
nn_setDepth(s, 1);
|
||||||
|
}
|
||||||
|
if(IsKeyPressed(KEY_F2)) {
|
||||||
|
nn_setDepth(s, 4);
|
||||||
|
}
|
||||||
|
if(IsKeyPressed(KEY_F3)) {
|
||||||
|
nn_setDepth(s, 8);
|
||||||
|
}
|
||||||
|
if(IsKeyPressed(KEY_F4)) {
|
||||||
|
ne_legacyColors = !ne_legacyColors;
|
||||||
|
}
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
@ -894,10 +894,14 @@ const char *nn_depthName(int depth);
|
|||||||
double nn_colorDistance(int colorA, int colorB);
|
double nn_colorDistance(int colorA, int colorB);
|
||||||
int nn_mapColor(int color, int *palette, int paletteSize);
|
int nn_mapColor(int color, int *palette, int paletteSize);
|
||||||
|
|
||||||
int nn_mapDepth(int color, int depth);
|
int nn_mapDepth(int color, int depth, nn_bool_t legacy);
|
||||||
void nn_getStd4BitPalette(int color[16]);
|
void nn_getStd4BitPalette(int color[16]);
|
||||||
void nn_getStd8BitPalette(int color[256]);
|
void nn_getStd8BitPalette(int color[256]);
|
||||||
|
|
||||||
|
// Std4bit uses actual MC dye colors, except for white and black
|
||||||
|
// Legacy uses OC's versions that were brightened
|
||||||
|
void nn_getLegacy4BitPalette(int color[16]);
|
||||||
|
|
||||||
void nn_setPixel(nn_screen *screen, int x, int y, nn_scrchr_t pixel);
|
void nn_setPixel(nn_screen *screen, int x, int y, nn_scrchr_t pixel);
|
||||||
nn_scrchr_t nn_getPixel(nn_screen *screen, int x, int y);
|
nn_scrchr_t nn_getPixel(nn_screen *screen, int x, int y);
|
||||||
|
|
||||||
@ -1056,8 +1060,6 @@ nn_bool_t nn_destroyHologram(nn_hologram *hologram);
|
|||||||
|
|
||||||
nn_component *nn_addHologram(nn_computer *computer, nn_address address, int slot, nn_hologram *hologram);
|
nn_component *nn_addHologram(nn_computer *computer, nn_address address, int slot, nn_hologram *hologram);
|
||||||
|
|
||||||
int nn_XYZtoIndex(int x, int y, int z);
|
|
||||||
|
|
||||||
void nn_hologram_clear(nn_hologram *hologram);
|
void nn_hologram_clear(nn_hologram *hologram);
|
||||||
int nn_hologram_get(nn_hologram *hologram, int x, int y, int z);
|
int nn_hologram_get(nn_hologram *hologram, int x, int y, int z);
|
||||||
void nn_hologram_set(nn_hologram *hologram, int x, int y, int z, int value);
|
void nn_hologram_set(nn_hologram *hologram, int x, int y, int z, int value);
|
||||||
|
@ -218,7 +218,7 @@ double nn_colorDistance(int colorA, int colorB) {
|
|||||||
delta.g = a.g - b.g;
|
delta.g = a.g - b.g;
|
||||||
delta.b = a.b - b.b;
|
delta.b = a.b - b.b;
|
||||||
|
|
||||||
return delta.r*delta.r + delta.g*delta.g + delta.b*delta.b;
|
return 0.2126 * delta.r*delta.r + 0.7152 * delta.g*delta.g + 0.0722 * delta.b*delta.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nn_mapColor(int color, int *palette, int paletteSize) {
|
int nn_mapColor(int color, int *palette, int paletteSize) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user