This commit is contained in:
IonutParau 2025-07-30 21:49:34 +02:00
parent be89f6a960
commit d1ad9d0be3
5 changed files with 22 additions and 4 deletions

View File

@ -2,6 +2,7 @@
nn_screen *nn_newScreen(nn_Context *context, int maxWidth, int maxHeight, int maxDepth, int editableColors, int paletteColors) {
nn_Alloc *alloc = &context->allocator;
// TODO: handle OOMs
nn_screen *screen = nn_alloc(alloc, sizeof(nn_screen));
screen->ctx = *context;
screen->buffer = nn_alloc(alloc, sizeof(nn_scrchr_t) * maxWidth * maxHeight);
@ -65,6 +66,20 @@ void nn_setResolution(nn_screen *screen, int width, int height) {
screen->height = height;
}
nn_bool_t nn_unsafeReallocateScreenBuffer(nn_screen *screen, int maxWidth, int maxHeight) {
nn_Alloc *alloc = &screen->ctx.allocator;
nn_scrchr_t *newBuffer = nn_alloc(alloc, sizeof(nn_scrchr_t) * maxWidth * maxHeight);
if(newBuffer == NULL) {
return false;
}
screen->buffer = newBuffer;
screen->maxWidth = maxWidth;
screen->maxHeight = maxHeight;
return true;
}
void nn_getViewport(nn_screen *screen, int *width, int *height) {
*width = screen->viewportWidth;
*height = screen->viewportHeight;

View File

@ -111,7 +111,7 @@ nn_size_t nn_vf_spaceUsedByNode(nn_vfnode *node) {
if(node->isDirectory) {
nn_size_t sum = 0;
for(nn_size_t i = 0; i < node->len; i++) {
sum = nn_vf_spaceUsedByNode(node->entries[i]);
sum += nn_vf_spaceUsedByNode(node->entries[i]);
}
return sum;
} else {

View File

@ -914,6 +914,9 @@ void nn_unlockScreen(nn_screen *screen);
void nn_getResolution(nn_screen *screen, int *width, int *height);
void nn_maxResolution(nn_screen *screen, int *width, int *height);
void nn_setResolution(nn_screen *screen, int width, int height);
// changes the maximum resolution
// DOES NOT USE THE LOCK AND THUS MAY CAUSE RACE CONDITIONS AND SEGFAULTS!!!!!
nn_bool_t nn_unsafeReallocateScreenBuffer(nn_screen *screen, int maxWidth, int maxHeight);
void nn_getViewport(nn_screen *screen, int *width, int *height);
void nn_setViewport(nn_screen *screen, int width, int height);

View File

@ -228,6 +228,7 @@ local libcomputer = {
local deadline = computer.uptime() + (type(timeout) == "number" and timeout or math.huge)
repeat
print("waiting for signal", computer.uptime())
yield() -- give executor a chance to give us stuff
local s = table.pack(computer.popSignal())
if s.n > 0 then
@ -437,7 +438,6 @@ local lastGC = computer.uptime()
while true do
timeout = nextDeadline()
bubbleYield = false
collectgarbage()
if computer.uptime() - lastGC >= gcInterval then
collectgarbage("collect")

View File

@ -69,7 +69,7 @@ void *testLuaArch_alloc(testLuaArch *arch, void *ptr, size_t osize, size_t nsize
nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(arch->computer));
if(nsize == 0) {
arch->memoryUsed -= osize;
free(ptr);
nn_dealloc(alloc, ptr, osize);
return NULL;
} else {
size_t actualOldSize = osize;
@ -79,7 +79,7 @@ void *testLuaArch_alloc(testLuaArch *arch, void *ptr, size_t osize, size_t nsize
}
arch->memoryUsed -= actualOldSize;
arch->memoryUsed += nsize;
return realloc(ptr, nsize);
return nn_resize(alloc, ptr, actualOldSize, nsize);
}
}