Skip to content

Commit

Permalink
snake_case renderer_*() and fix a few warnings
Browse files Browse the repository at this point in the history
I left in some warnings while sketching out the API, this fixes some of
them.
  • Loading branch information
vkoskiv committed Nov 12, 2023
1 parent e3ef2a7 commit 7e409be
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
70 changes: 43 additions & 27 deletions src/api/c-ray.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ char *cr_get_file_path(char *full_path) {
struct cr_renderer;

struct cr_renderer *cr_new_renderer() {
struct renderer *r = newRenderer();
cr_set_asset_path(r);
return r;
struct renderer *r = renderer_new();
cr_set_asset_path((struct cr_renderer *)r);
return (struct cr_renderer *)r;
}

enum cr_renderer_param {
Expand All @@ -92,37 +92,48 @@ bool cr_renderer_set_num_pref(struct cr_renderer *ext, enum cr_renderer_param p,
if (!ext) return false;
struct renderer *r = (struct renderer *)ext;
switch (p) {
case cr_renderer_threads: {
r->prefs.threads = num;
return true;
}
case cr_renderer_samples: {
r->prefs.sampleCount = num;
return true;
}
case cr_renderer_bounces: {
if (num > 512) return false;
r->prefs.bounces = num;
return true;
}
case cr_renderer_tile_width: {

}
case cr_renderer_threads: {
r->prefs.threads = num;
return true;
}
case cr_renderer_samples: {
r->prefs.sampleCount = num;
return true;
}
case cr_renderer_bounces: {
if (num > 512) return false;
r->prefs.bounces = num;
return true;
}
case cr_renderer_tile_width: {
r->prefs.tileWidth = num;
return true;
}
case cr_renderer_tile_height: {
r->prefs.tileHeight = num;
return true;
}
}
return false;
}

uint64_t cr_renderer_get_num_pref(struct cr_renderer *r, enum cr_renderer_param p) {
//TODO
(void)r;
(void)p;
uint64_t cr_renderer_get_num_pref(struct cr_renderer *ext, enum cr_renderer_param p) {
if (!ext) return 0;
struct renderer *r = (struct renderer *)ext;
switch (p) {
case cr_renderer_threads: return r->prefs.threads;
case cr_renderer_samples: return r->prefs.sampleCount;
case cr_renderer_bounces: return r->prefs.bounces;
case cr_renderer_tile_width: return r->prefs.tileWidth;
case cr_renderer_tile_height: return r->prefs.tileHeight;
}
return 0;
}

void cr_destroy_renderer(struct cr_renderer *ext) {
struct renderer *r = (struct renderer *)ext;
ASSERT(r);
destroyRenderer(r);
renderer_destroy(r);
}

// -- Scene --
Expand All @@ -134,6 +145,11 @@ struct cr_scene *cr_scene_create(struct cr_renderer *r) {
return NULL;
}

void cr_scene_destroy(struct cr_scene *s) {
//TODO
(void)s;
}

struct cr_object;

struct cr_object *cr_object_new(struct cr_scene *s) {
Expand Down Expand Up @@ -249,12 +265,12 @@ void cr_write_image(struct cr_renderer *ext) {
if (r->state.saveImage) {
struct imageFile *file = newImageFile(currentImage, r->prefs.imgFilePath, r->prefs.imgFileName, r->prefs.imgCount, r->prefs.imgType);
file->info = (struct renderInfo){
.bounces = cr_get_bounces(r),
.samples = cr_get_sample_count(r),
.bounces = cr_get_bounces(ext),
.samples = cr_get_sample_count(ext),
.crayVersion = cr_get_version(),
.gitHash = cr_get_git_hash(),
.renderTime = timer_get_ms(r->state.timer),
.threadCount = cr_get_thread_count(r)
.threadCount = cr_get_thread_count(ext)
};
writeImage(file);
destroyImageFile(file);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void *renderThread(void *arg) {
return 0;
}

static struct prefs defaultPrefs() {
static struct prefs defaults() {
return (struct prefs){
.tileOrder = renderOrderFromMiddle,
.threads = getSysCores() + 2,
Expand All @@ -378,9 +378,9 @@ static struct prefs defaultPrefs() {
};
}

struct renderer *newRenderer() {
struct renderer *renderer_new() {
struct renderer *r = calloc(1, sizeof(*r));
r->prefs = defaultPrefs();
r->prefs = defaults();
r->state.finishedPasses = 1;

r->state.tileMutex = mutex_create();
Expand All @@ -392,7 +392,7 @@ struct renderer *newRenderer() {
return r;
}

void destroyRenderer(struct renderer *r) {
void renderer_destroy(struct renderer *r) {
if (r) {
destroyScene(r->scene);
if (r->state.renderBuffer) destroyTexture(r->state.renderBuffer);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ struct renderer {
};

//Initialize a new renderer
struct renderer *newRenderer(void);
struct renderer *renderer_new(void);

//Start main render loop
struct texture *renderFrame(struct renderer *r);

//Free renderer allocations
void destroyRenderer(struct renderer *r);
void renderer_destroy(struct renderer *r);
4 changes: 2 additions & 2 deletions src/utils/protocol/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static cJSON *receiveScene(const cJSON *json) {
cJSON *scene = cJSON_GetObjectItem(json, "data");
char *sceneText = cJSON_PrintUnformatted(scene);
logr(info, "Received scene description\n");
g_worker_renderer = newRenderer();
g_worker_renderer = renderer_new();
g_worker_renderer->state.file_cache = cache;
g_worker_socket_mutex = mutex_create();
cJSON *assetPathJson = cJSON_GetObjectItem(json, "assetPath");
Expand Down Expand Up @@ -317,7 +317,7 @@ static cJSON *processCommand(int connectionSocket, const cJSON *json) {
}

static void workerCleanup() {
destroyRenderer(g_worker_renderer);
renderer_destroy(g_worker_renderer);
g_worker_renderer = NULL;
}

Expand Down

0 comments on commit 7e409be

Please sign in to comment.