Global illumination aus und monitoring/loading bar implementiert
This commit is contained in:
+26
@@ -1,6 +1,14 @@
|
||||
//
|
||||
// Created by ary on 29.07.2026.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define SLEEP_SECONDS(s) Sleep((s) * 1000)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define SLEEP_SECONDS(s) sleep(s)
|
||||
#endif
|
||||
|
||||
#include "interface.h"
|
||||
#include "examples.h"
|
||||
@@ -61,6 +69,21 @@ void *workerLoop(void *arg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* monitorProgress(void *arg) {
|
||||
MonitorArgs *args = (MonitorArgs*)arg;
|
||||
|
||||
while (1){
|
||||
pthread_mutex_lock(args->mutexKey);
|
||||
int pixelId = *args->nextPixelId;
|
||||
pthread_mutex_unlock(args->mutexKey);
|
||||
if (pixelId >= args->pixelCount) break;
|
||||
double progress = 100.0 * pixelId / args->pixelCount;
|
||||
printf("progress: %lf%%\n", progress);
|
||||
SLEEP_SECONDS(1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void displaySzene(object objectList[], int objectCount, camera cam1, int width, int height, int channels, unsigned char **image) {
|
||||
const vec3 worldUp = (vec3){0, 1, 0};
|
||||
vec3 screenX = vec3Cross(worldUp, cam1.direction);
|
||||
@@ -87,6 +110,8 @@ void displaySzene(object objectList[], int objectCount, camera cam1, int width,
|
||||
for (int i = 0; i < WORKTHREADSIZE; i++) {
|
||||
pthread_create(&(threadIdList[i]), NULL, workerLoop, args);
|
||||
}
|
||||
pthread_t monitorThread;
|
||||
pthread_create(&monitorThread, NULL, monitorProgress, (void*)(&(MonitorArgs){&args->nextPixelId, args->pixelCount, &args->mutexKey}));
|
||||
|
||||
|
||||
//renderPixel(i, objectList, objectCount, width, channels, &screenTopLeft, &vecPixelStepX, &vecPixelStepY, &cam1, image);
|
||||
@@ -94,6 +119,7 @@ void displaySzene(object objectList[], int objectCount, camera cam1, int width,
|
||||
for (int i = 0; i < WORKTHREADSIZE; i++) {
|
||||
pthread_join(threadIdList[i], NULL);
|
||||
}
|
||||
pthread_join(monitorThread, NULL);
|
||||
pthread_mutex_destroy(&args->mutexKey);
|
||||
free(threadIdList);
|
||||
free(args);
|
||||
|
||||
Reference in New Issue
Block a user