mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
small tweaks
This commit is contained in:
parent
df5eeeda7c
commit
fa870c111e
1
TODO.md
1
TODO.md
@ -3,6 +3,7 @@
|
|||||||
- rework literally all the costs to just be heat and amount per tick
|
- rework literally all the costs to just be heat and amount per tick
|
||||||
- change more methods to be direct but with buffered indirects
|
- change more methods to be direct but with buffered indirects
|
||||||
- complete the GPU implementation (screen buffers and missing methods)
|
- complete the GPU implementation (screen buffers and missing methods)
|
||||||
|
- complete the screen implementation (bunch of missing methods)
|
||||||
- `computer` component
|
- `computer` component
|
||||||
- `modem` component
|
- `modem` component
|
||||||
- `tunnel` component
|
- `tunnel` component
|
||||||
|
@ -162,7 +162,10 @@ void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component,
|
|||||||
nn_setCError(computer, "out of memory");
|
nn_setCError(computer, "out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t len = eeprom->getData(component, eeprom->userdata, buf);
|
int len = eeprom->getData(component, eeprom->userdata, buf);
|
||||||
|
if(len < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for(size_t i = 0; i < len; i++) {
|
for(size_t i = 0; i < len; i++) {
|
||||||
sum += buf[i];
|
sum += buf[i];
|
||||||
|
@ -408,24 +408,24 @@ void nn_loadFilesystemTable(nn_universe *universe) {
|
|||||||
nn_componentTable *fsTable = nn_newComponentTable(nn_getAllocator(universe), "filesystem", NULL, NULL, (void *)nn_fs_destroy);
|
nn_componentTable *fsTable = nn_newComponentTable(nn_getAllocator(universe), "filesystem", NULL, NULL, (void *)nn_fs_destroy);
|
||||||
nn_storeUserdata(universe, "NN:FILESYSTEM", fsTable);
|
nn_storeUserdata(universe, "NN:FILESYSTEM", fsTable);
|
||||||
|
|
||||||
nn_defineMethod(fsTable, "getLabel", false, (void *)nn_fs_getLabel, NULL, "getLabel(): string - Returns the label of the filesystem.");
|
nn_defineMethod(fsTable, "getLabel", true, (void *)nn_fs_getLabel, NULL, "getLabel(): string - Returns the label of the filesystem.");
|
||||||
nn_defineMethod(fsTable, "setLabel", false, (void *)nn_fs_setLabel, NULL, "setLabel(label: string): string - Sets a new label for the filesystem and returns the new label of the filesystem, which may have been truncated.");
|
nn_defineMethod(fsTable, "setLabel", true, (void *)nn_fs_setLabel, NULL, "setLabel(label: string): string - Sets a new label for the filesystem and returns the new label of the filesystem, which may have been truncated.");
|
||||||
nn_defineMethod(fsTable, "spaceUsed", false, (void *)nn_fs_spaceUsed, NULL, "spaceUsed(): integer - Returns the amounts of bytes used.");
|
nn_defineMethod(fsTable, "spaceUsed", true, (void *)nn_fs_spaceUsed, NULL, "spaceUsed(): integer - Returns the amounts of bytes used.");
|
||||||
nn_defineMethod(fsTable, "spaceTotal", true, (void *)nn_fs_spaceTotal, NULL, "spaceTotal(): integer - Returns the capacity of the filesystem.");
|
nn_defineMethod(fsTable, "spaceTotal", true, (void *)nn_fs_spaceTotal, NULL, "spaceTotal(): integer - Returns the capacity of the filesystem.");
|
||||||
nn_defineMethod(fsTable, "isReadOnly", true, (void *)nn_fs_isReadOnly, NULL, "isReadOnly(): boolean - Returns whether the filesystem is in read-only mode.");
|
nn_defineMethod(fsTable, "isReadOnly", true, (void *)nn_fs_isReadOnly, NULL, "isReadOnly(): boolean - Returns whether the filesystem is in read-only mode.");
|
||||||
nn_defineMethod(fsTable, "size", false, (void *)nn_fs_size, NULL, "size(path: string): integer - Gets the size, in bytes, of a file.");
|
nn_defineMethod(fsTable, "size", true, (void *)nn_fs_size, NULL, "size(path: string): integer - Gets the size, in bytes, of a file.");
|
||||||
nn_defineMethod(fsTable, "remove", false, (void *)nn_fs_remove, NULL, "remove(path: string): boolean - Removes a file. Returns whether the operation succeeded.");
|
nn_defineMethod(fsTable, "remove", true, (void *)nn_fs_remove, NULL, "remove(path: string): boolean - Removes a file. Returns whether the operation succeeded.");
|
||||||
nn_defineMethod(fsTable, "lastModified", false, (void *)nn_fs_lastModified, NULL, "remove(path: string): boolean - Removes a file. Returns whether the operation succeeded.");
|
nn_defineMethod(fsTable, "lastModified", true, (void *)nn_fs_lastModified, NULL, "remove(path: string): boolean - Removes a file. Returns whether the operation succeeded.");
|
||||||
nn_defineMethod(fsTable, "rename", false, (void *)nn_fs_rename, NULL, "rename(from: string, to: string): boolean - Moves files from one path to another.");
|
nn_defineMethod(fsTable, "rename", true, (void *)nn_fs_rename, NULL, "rename(from: string, to: string): boolean - Moves files from one path to another.");
|
||||||
nn_defineMethod(fsTable, "exists", false, (void *)nn_fs_exists, NULL, "exists(path: string): boolean - Checks whether a file exists.");
|
nn_defineMethod(fsTable, "exists", true, (void *)nn_fs_exists, NULL, "exists(path: string): boolean - Checks whether a file exists.");
|
||||||
nn_defineMethod(fsTable, "isDirectory", false, (void *)nn_fs_isDirectory, NULL, "isDirectory(path: string): boolean - Returns whether a file is actually a directory.");
|
nn_defineMethod(fsTable, "isDirectory", true, (void *)nn_fs_isDirectory, NULL, "isDirectory(path: string): boolean - Returns whether a file is actually a directory.");
|
||||||
nn_defineMethod(fsTable, "makeDirectory", false, (void *)nn_fs_makeDirectory, NULL, "makeDirectory(path: string): boolean - Creates a new directory at the given path. Returns whether it succeeded.");
|
nn_defineMethod(fsTable, "makeDirectory", true, (void *)nn_fs_makeDirectory, NULL, "makeDirectory(path: string): boolean - Creates a new directory at the given path. Returns whether it succeeded.");
|
||||||
nn_defineMethod(fsTable, "list", false, (void *)nn_fs_list, NULL, "list(path: string): string[] - Returns a list of file paths. Directories will have a / after them");
|
nn_defineMethod(fsTable, "list", true, (void *)nn_fs_list, NULL, "list(path: string): string[] - Returns a list of file paths. Directories will have a / after them");
|
||||||
nn_defineMethod(fsTable, "open", false, (void *)nn_fs_open, NULL, "open(path: string[, mode: string = \"r\"]): integer - Opens a file, may create it.");
|
nn_defineMethod(fsTable, "open", true, (void *)nn_fs_open, NULL, "open(path: string[, mode: string = \"r\"]): integer - Opens a file, may create it.");
|
||||||
nn_defineMethod(fsTable, "close", false, (void *)nn_fs_close, NULL, "close(fd: integer): boolean - Closes a file.");
|
nn_defineMethod(fsTable, "close", true, (void *)nn_fs_close, NULL, "close(fd: integer): boolean - Closes a file.");
|
||||||
nn_defineMethod(fsTable, "write", false, (void *)nn_fs_write, NULL, "write(fd: integer, data: string): boolean - Writes data to a file.");
|
nn_defineMethod(fsTable, "write", true, (void *)nn_fs_write, NULL, "write(fd: integer, data: string): boolean - Writes data to a file.");
|
||||||
nn_defineMethod(fsTable, "read", false, (void *)nn_fs_read, NULL, "read(fd: integer, len: number): string - Reads bytes from a file. Infinity is a valid length, in which case it reads as much as possible.");
|
nn_defineMethod(fsTable, "read", true, (void *)nn_fs_read, NULL, "read(fd: integer, len: number): string - Reads bytes from a file. Infinity is a valid length, in which case it reads as much as possible.");
|
||||||
nn_defineMethod(fsTable, "seek", false, (void *)nn_fs_seek, NULL, "seek(fd: integer, whence: string, offset: integer): integer - Seeks a file. Returns the new position. Valid whences are set, cur and end.");
|
nn_defineMethod(fsTable, "seek", true, (void *)nn_fs_seek, NULL, "seek(fd: integer, whence: string, offset: integer): integer - Seeks a file. Returns the new position. Valid whences are set, cur and end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
nn_component *nn_addFileSystem(nn_computer *computer, nn_address address, int slot, nn_filesystem *filesystem) {
|
nn_component *nn_addFileSystem(nn_computer *computer, nn_address address, int slot, nn_filesystem *filesystem) {
|
||||||
|
@ -459,6 +459,7 @@ void nn_loadGraphicsCardTable(nn_universe *universe) {
|
|||||||
nn_defineMethod(gpuTable, "getForeground", true, (void *)nni_gpu_getForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable.");
|
nn_defineMethod(gpuTable, "getForeground", true, (void *)nni_gpu_getForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable.");
|
||||||
nn_defineMethod(gpuTable, "getDepth", true, (void *)nni_gpu_getDepth, NULL, "getDepth(): number - The currently set color depth of the screen, in bits. Can be 1, 4 or 8.");
|
nn_defineMethod(gpuTable, "getDepth", true, (void *)nni_gpu_getDepth, NULL, "getDepth(): number - The currently set color depth of the screen, in bits. Can be 1, 4 or 8.");
|
||||||
nn_defineMethod(gpuTable, "setDepth", true, (void *)nni_gpu_setDepth, NULL, "setDepth(depth: integer): string - Changes the screen depth. Valid values can be 1, 4, 8, 16 or 24, however check maxDepth for the maximum supported value of the screen. Using a depth higher than what is supported by the screen will error. Returns the name of the new depth.");
|
nn_defineMethod(gpuTable, "setDepth", true, (void *)nni_gpu_setDepth, NULL, "setDepth(depth: integer): string - Changes the screen depth. Valid values can be 1, 4, 8, 16 or 24, however check maxDepth for the maximum supported value of the screen. Using a depth higher than what is supported by the screen will error. Returns the name of the new depth.");
|
||||||
|
nn_defineMethod(gpuTable, "maxDepth", true, (void *)nni_gpu_maxDepth, NULL, "maxDepth(): number - The maximum supported depth of the screen.");
|
||||||
nn_defineMethod(gpuTable, "fill", true, (void *)nni_gpu_fill, NULL, "fill(x: integer, y: integer, w: integer, h: integer, s: string)");
|
nn_defineMethod(gpuTable, "fill", true, (void *)nni_gpu_fill, NULL, "fill(x: integer, y: integer, w: integer, h: integer, s: string)");
|
||||||
nn_defineMethod(gpuTable, "copy", true, (void *)nni_gpu_copy, NULL, "copy(x: integer, y: integer, w: integer, h: integer, tx: integer, ty: integer) - Copies stuff");
|
nn_defineMethod(gpuTable, "copy", true, (void *)nni_gpu_copy, NULL, "copy(x: integer, y: integer, w: integer, h: integer, tx: integer, ty: integer) - Copies stuff");
|
||||||
nn_defineMethod(gpuTable, "getViewport", true, (void *)nni_gpu_getViewport, NULL, "getViewport(): integer, integer - Gets the current viewport resolution");
|
nn_defineMethod(gpuTable, "getViewport", true, (void *)nni_gpu_getViewport, NULL, "getViewport(): integer, integer - Gets the current viewport resolution");
|
||||||
|
@ -224,11 +224,24 @@ void nn_screenComp_getKeyboards(nn_screen *screen, void *_, nn_component *compon
|
|||||||
nn_return(computer, arr);
|
nn_return(computer, arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nn_screenComp_getAspectRatio(nn_screen *screen, void *_, nn_component *component, nn_computer *computer) {
|
||||||
|
nn_lockScreen(screen);
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
nn_getAspectRatio(screen, &w, &h);
|
||||||
|
|
||||||
|
nn_unlockScreen(screen);
|
||||||
|
|
||||||
|
nn_return_integer(computer, w);
|
||||||
|
nn_return_integer(computer, h);
|
||||||
|
}
|
||||||
|
|
||||||
void nn_loadScreenTable(nn_universe *universe) {
|
void nn_loadScreenTable(nn_universe *universe) {
|
||||||
nn_componentTable *screenTable = nn_newComponentTable(nn_getAllocator(universe), "screen", NULL, NULL, (void *)nn_screenComp_destroy);
|
nn_componentTable *screenTable = nn_newComponentTable(nn_getAllocator(universe), "screen", NULL, NULL, (void *)nn_screenComp_destroy);
|
||||||
nn_storeUserdata(universe, "NN:SCREEN", screenTable);
|
nn_storeUserdata(universe, "NN:SCREEN", screenTable);
|
||||||
|
|
||||||
nn_defineMethod(screenTable, "getKeyboards", false, (void *)nn_screenComp_getKeyboards, NULL, "getKeyboards(): string[] - Returns the keyboards registered to this screen.");
|
nn_defineMethod(screenTable, "getKeyboards", true, (void *)nn_screenComp_getKeyboards, NULL, "getKeyboards(): string[] - Returns the keyboards registered to this screen.");
|
||||||
|
nn_defineMethod(screenTable, "getAspectRatio", true, (void *)nn_screenComp_getAspectRatio, NULL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
nn_componentTable *nn_getScreenTable(nn_universe *universe) {
|
nn_componentTable *nn_getScreenTable(nn_universe *universe) {
|
||||||
|
@ -71,7 +71,7 @@ void ne_eeprom_set(nn_component *component, void *_, const char *buf, size_t len
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ne_eeprom_getData(nn_component *component, void *_, char *buf) {
|
int ne_eeprom_getData(nn_component *component, void *_, char *buf) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ne_eeprom_setData(nn_component *component, void *_, const char *buf, size_t len) {}
|
void ne_eeprom_setData(nn_component *component, void *_, const char *buf, size_t len) {}
|
||||||
@ -654,20 +654,20 @@ int main() {
|
|||||||
|
|
||||||
int maxWidth = 80, maxHeight = 32;
|
int maxWidth = 80, maxHeight = 32;
|
||||||
|
|
||||||
nn_screen *s = nn_newScreen(&alloc, maxWidth, maxHeight, 16, 16, 256);
|
nn_screen *s = nn_newScreen(&alloc, maxWidth, maxHeight, 24, 16, 256);
|
||||||
|
nn_setDepth(s, 4); // 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, "Main Screen", 2, s);
|
nn_addScreen(computer, "Main Screen", 2, s);
|
||||||
|
|
||||||
ne_premappedPixel *premap = ne_allocPremap(maxWidth, maxHeight);
|
ne_premappedPixel *premap = ne_allocPremap(maxWidth, maxHeight);
|
||||||
|
|
||||||
// somewhat matches tier 3 in OC in terms of perTick
|
|
||||||
nn_gpuControl gpuCtrl = {
|
nn_gpuControl gpuCtrl = {
|
||||||
.totalVRAM = 16*1024,
|
.totalVRAM = 16*1024,
|
||||||
.screenCopyPerTick = 4,
|
.screenCopyPerTick = 4,
|
||||||
.screenFillPerTick = 8,
|
.screenFillPerTick = 8,
|
||||||
.screenSetsPerTick = 16,
|
.screenSetsPerTick = 16,
|
||||||
.screenColorChangesPerTick = 8,
|
.screenColorChangesPerTick = 64,
|
||||||
|
|
||||||
.heatPerPixelChange = 0.0005,
|
.heatPerPixelChange = 0.0005,
|
||||||
.heatPerPixelReset = 0.0001,
|
.heatPerPixelReset = 0.0001,
|
||||||
@ -691,6 +691,8 @@ int main() {
|
|||||||
|
|
||||||
SetExitKey(KEY_NULL);
|
SetExitKey(KEY_NULL);
|
||||||
|
|
||||||
|
SetTargetFPS(20); // match MC TPS
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
if(WindowShouldClose()) break;
|
if(WindowShouldClose()) break;
|
||||||
nn_setEnergyInfo(computer, 5000, 5000);
|
nn_setEnergyInfo(computer, 5000, 5000);
|
||||||
@ -807,6 +809,9 @@ render:
|
|||||||
|
|
||||||
int depth = nn_getDepth(s);
|
int depth = nn_getDepth(s);
|
||||||
|
|
||||||
|
int offX = (GetScreenWidth() - scrW * pixelWidth) / 2;
|
||||||
|
int offY = (GetScreenHeight() - scrH * pixelHeight) / 2;
|
||||||
|
|
||||||
for(size_t x = 0; x < scrW; x++) {
|
for(size_t x = 0; x < scrW; x++) {
|
||||||
for(size_t y = 0; y < scrH; y++) {
|
for(size_t y = 0; y < scrH; y++) {
|
||||||
ne_premappedPixel p = ne_getPremap(premap, s, x, y);
|
ne_premappedPixel p = ne_getPremap(premap, s, x, y);
|
||||||
@ -814,8 +819,8 @@ render:
|
|||||||
// fuck palettes
|
// fuck palettes
|
||||||
Color fgColor = ne_processColor(p.mappedFgRes);
|
Color fgColor = ne_processColor(p.mappedFgRes);
|
||||||
Color bgColor = ne_processColor(p.mappedBgRes);
|
Color bgColor = ne_processColor(p.mappedBgRes);
|
||||||
DrawRectangle(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight, bgColor);
|
DrawRectangle(x * pixelWidth + offX, y * pixelHeight + offY, pixelWidth, pixelHeight, bgColor);
|
||||||
DrawTextCodepoint(unscii, p.codepoint, (Vector2) {x * pixelWidth, y * pixelHeight}, pixelHeight - 5, fgColor);
|
DrawTextCodepoint(unscii, p.codepoint, (Vector2) {x * pixelWidth + offX, y * pixelHeight + offY}, pixelHeight - 5, fgColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user