Skip to content

Commit

Permalink
Enable -Wextra and fix a bunch of warnings supplied by it.
Browse files Browse the repository at this point in the history
Hash out some more of the API
Clean up ui.c a bit.
  • Loading branch information
vkoskiv committed Jan 18, 2020
1 parent 7ecf578 commit b2ece87
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 40 deletions.
16 changes: 14 additions & 2 deletions C-Ray.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
WARNING_CFLAGS = (
"-Wall",
"-Wextra",
);
};
name = Debug;
};
Expand Down Expand Up @@ -767,6 +771,10 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
WARNING_CFLAGS = (
"-Wall",
"-Wextra",
);
};
name = Release;
};
Expand All @@ -789,13 +797,14 @@
);
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
GCC_USE_STANDARD_INCLUDE_SEARCHING = NO;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_PEDANTIC = NO;
GCC_WARN_SHADOW = NO;
GCC_WARN_UNUSED_PARAMETER = NO;
GCC_WARN_UNUSED_PARAMETER = YES;
HEADER_SEARCH_PATHS = "";
LIBRARY_SEARCH_PATHS = "";
OTHER_CFLAGS = (
Expand All @@ -810,6 +819,7 @@
);
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = NO;
WARNING_CFLAGS = "";
};
name = Debug;
};
Expand All @@ -829,13 +839,14 @@
GCC_PREPROCESSOR_DEFINITIONS = UI_ENABLED;
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
GCC_USE_STANDARD_INCLUDE_SEARCHING = NO;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_PEDANTIC = NO;
GCC_WARN_SHADOW = NO;
GCC_WARN_UNUSED_PARAMETER = NO;
GCC_WARN_UNUSED_PARAMETER = YES;
HEADER_SEARCH_PATHS = "";
LIBRARY_SEARCH_PATHS = "";
OTHER_CFLAGS = (
Expand All @@ -850,6 +861,7 @@
);
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = NO;
WARNING_CFLAGS = "";
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
else()
# set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wconversion -std=gnu99")
set(CMAKE_C_FLAGS "-Wall -std=gnu99")
set(CMAKE_C_FLAGS "-Wall -Wextra -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O3 -ftree-vectorize")
if (ASAN)
unset(UBSAN CACHE)
Expand Down
34 changes: 29 additions & 5 deletions src/c-ray.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ void crGetRenderOrder(void) {
}

void crSetThreadCount(int threadCount, bool fromSystem) {
ASSERT_NOT_REACHED();
grenderer->prefs.threadCount = threadCount;
grenderer->prefs.fromSystem = fromSystem;
crRestartInteractive();
}

int crGetThreadCount(void) {
return grenderer->prefs.threadCount;
}

void crSetSampleCount(int sampleCount) {
(void)sampleCount;
ASSERT_NOT_REACHED();
}

Expand All @@ -137,6 +140,7 @@ int crGetSampleCount(void) {
}

void crSetBounces(int bounces) {
(void)bounces;
ASSERT_NOT_REACHED();
}

Expand All @@ -145,6 +149,7 @@ int crGetBounces(void) {
}

void crSetTileWidth(int width) {
(void)width;
ASSERT_NOT_REACHED();
}

Expand All @@ -153,6 +158,7 @@ int crGetTileWidth(void) {
}

void crSetTileHeight(int height) {
(void)height;
ASSERT_NOT_REACHED();
}

Expand All @@ -161,14 +167,16 @@ int crGetTileHeight(void) {
}

void crSetImageWidth(int width) {
ASSERT_NOT_REACHED();
grenderer->prefs.imageWidth = width;
crRestartInteractive();
}

int crGetImageWidth(void) {
return grenderer->prefs.imageWidth;
}

void crSetImageHeight(int height) {
(void)height;
ASSERT_NOT_REACHED();
}

Expand All @@ -177,6 +185,7 @@ int crGetImageHeight() {
}

void crSetFilePath(char *filePath) {
(void)filePath;
ASSERT_NOT_REACHED();
}

Expand All @@ -185,6 +194,7 @@ char *crGetFilePath() {
}

void crSetFileName(char *fileName) {
(void)fileName;
ASSERT_NOT_REACHED();
}

Expand All @@ -207,9 +217,23 @@ void crRenderSingleFrame() {
}

//Interactive mode
void crStartInteractive(void);
void crPauseInteractive(void); //Toggle paused state
void crGetCurrentImage(void); //Just get the current buffer
void crStartInteractive(void) {
ASSERT_NOT_REACHED();
}

//Toggle paused state
void crPauseInteractive(void) {
ASSERT_NOT_REACHED();
}

//Just get the current buffer
void crGetCurrentImage(void) {
ASSERT_NOT_REACHED();
}
void crRestartInteractive() {
//if (grenderer->prefs.interactive) { do the thing }
ASSERT_NOT_REACHED();
}

void crTransformMesh(void); //Transform, recompute kd-tree, restart

Expand Down
1 change: 1 addition & 0 deletions src/c-ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void crRenderSingleFrame(void);
void crStartInteractive(void);
void crPauseInteractive(void); //Toggle paused state
void crGetCurrentImage(void); //Just get the current buffer
void crRestartInteractive(void);

void crTransformMesh(void); //Transform, recompute kd-tree, restart

Expand Down
14 changes: 13 additions & 1 deletion src/datatypes/material.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,20 @@ struct vector randomOnUnitSphere(pcg32_random_t *rng) {
}

bool emissiveBSDF(struct hitRecord *isect, struct lightRay *ray, struct color *attenuation, struct lightRay *scattered, pcg32_random_t *rng) {
(void)isect;
(void)ray;
(void)attenuation;
(void)scattered;
(void)rng;
return false;
}

bool weightedBSDF(struct hitRecord *isect, struct lightRay *ray, struct color *attenuation, struct lightRay *scattered, pcg32_random_t *rng) {

(void)isect;
(void)ray;
(void)attenuation;
(void)scattered;
(void)rng;
/*
This will be the internal shader weighting solver that runs a random distribution and chooses from the available
discrete shaders.
Expand All @@ -240,6 +249,7 @@ struct color diffuseColor(struct hitRecord *isect) {
}

bool lambertianBSDF(struct hitRecord *isect, struct lightRay *ray, struct color *attenuation, struct lightRay *scattered, pcg32_random_t *rng) {
(void)ray;
struct vector temp = vecAdd(isect->hitPoint, isect->surfaceNormal);
struct vector rand = randomInUnitSphere(rng);
struct vector scatterDir = vecSub(vecAdd(temp, rand), isect->hitPoint); //Randomized scatter direction
Expand All @@ -249,6 +259,7 @@ bool lambertianBSDF(struct hitRecord *isect, struct lightRay *ray, struct color
}

bool metallicBSDF(struct hitRecord *isect, struct lightRay *ray, struct color *attenuation, struct lightRay *scattered, pcg32_random_t *rng) {
(void)ray;
struct vector normalizedDir = vecNormalize(isect->incident.direction);
struct vector reflected = reflectVec(&normalizedDir, &isect->surfaceNormal);
//Roughness
Expand Down Expand Up @@ -286,6 +297,7 @@ float shlick(float cosine, float IOR) {

// Only works on spheres for now. Reflections work but refractions don't
bool dialectricBSDF(struct hitRecord *isect, struct lightRay *ray, struct color *attenuation, struct lightRay *scattered, pcg32_random_t *rng) {
(void)ray;
struct vector outwardNormal;
struct vector reflected = reflectVec(&isect->incident.direction, &isect->surfaceNormal);
float niOverNt;
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct renderTile getTile(struct renderer *r) {
@param scene scene object
*/
int quantizeImage(struct renderTile **renderTiles, int width, int height, unsigned tileWidth, unsigned tileHeight) {
int quantizeImage(struct renderTile **renderTiles, unsigned width, unsigned height, unsigned tileWidth, unsigned tileHeight) {

logr(info, "Quantizing render plane\n");

Expand Down
3 changes: 1 addition & 2 deletions src/datatypes/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ struct renderTile {
};

struct texture;
enum renderOrder;

int quantizeImage(struct renderTile **renderTiles, int width, int height, unsigned tileWidth, unsigned tileHeight);
int quantizeImage(struct renderTile **renderTiles, unsigned width, unsigned height, unsigned tileWidth, unsigned tileHeight);

void reorderTiles(struct renderTile **tiles, int tileCount, enum renderOrder tileOrder);

Expand Down
8 changes: 8 additions & 0 deletions src/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ enum fileType {
hdr,
buffer
};

enum renderOrder {
renderOrderTopToBottom = 0,
renderOrderFromMiddle,
renderOrderToMiddle,
renderOrderNormal,
renderOrderRandom
};
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ int main(int argc, char *argv[]) {
char *input = argc == 2 ? crLoadFile(argv[1], &bytes) : crReadStdin(&bytes);
logr(info, "%zi bytes of input JSON loaded from %s, parsing.\n", bytes, argc == 2 ? "file" : "stdin");
if (!input) return -1;

if (crLoadSceneFromBuf(input)) {
crDestroyRenderer();
return -1;
Expand Down
1 change: 0 additions & 1 deletion src/renderer/pathtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ struct hitRecord {
/// @param depth Current depth for recursive calls
/// @param maxDepth Maximum depth of recursion
/// @param rng A random number generator. One per execution thread.
/// @param hasHitObject set to true if an object was hit in this pass
struct color pathTrace(struct lightRay *incidentRay, struct world *scene, int depth, int maxDepth, pcg32_random_t *rng);
12 changes: 2 additions & 10 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ struct threadState {
struct texture *output;
};

enum renderOrder {
renderOrderTopToBottom = 0,
renderOrderFromMiddle,
renderOrderToMiddle,
renderOrderNormal,
renderOrderRandom
};

/// Renderer state data
struct state {
struct renderTile *renderTiles; //Array of renderTiles to render
Expand Down Expand Up @@ -77,8 +69,8 @@ struct prefs {
int tileHeight;

//Output prefs
int imageWidth;
int imageHeight;
unsigned imageWidth;
unsigned imageHeight;
char *imgFilePath;
char *imgFileName;
int imgCount;
Expand Down
2 changes: 0 additions & 2 deletions src/utils/filehandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ void encodePNGFromArray(const char *filename, unsigned char *imgData, int width,
lodepng_add_text(&info, "C-ray SysInfo", sysinfo);
#endif

//TODO: Maybe platform info? arch, uname, etc.

LodePNGState state;
lodepng_state_init(&state);
state.info_raw.bitdepth = 8;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void freeTable(struct hashtable *table) {
}

void printTableUsage(struct hashtable *t) {
for (int i = 0; i < t->size; ++i) {
for (uint64_t i = 0; i < t->size; ++i) {
printf("[%s]", t->data[i].used ? "x" : " ");
}
printf("\n");
Expand Down Expand Up @@ -138,8 +138,8 @@ void testTable() {
*/
logr(debug, "Testing overfill\n");
char buf[5];
for (int i = 0; i < defaultTableSize; i++) {
sprintf(buf, "%i", i);
for (uint64_t i = 0; i < defaultTableSize; i++) {
sprintf(buf, "%llu", i);
setFloat(table, buf, (float)i);
printTableUsage(table);
}
Expand Down
12 changes: 1 addition & 11 deletions src/utils/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ void getKeyboardInput(struct renderer *r) {
r->state.renderAborted = true;
}
if (event.key.keysym.sym == SDLK_p) {

/*if (r->state.threadStates[0].paused) {
printf("\n");
logr(info, "Resuming render.\n");
} else {
printf("\n");
logr(info, "Pausing render.\n");
}*/

for (int i = 0; i < r->prefs.threadCount; i++) {
if (r->state.threadStates[i].paused) {
r->state.threadStates[i].paused = false;
Expand Down Expand Up @@ -200,12 +191,11 @@ void drawProgressBars(struct renderer *r) {
@param tile Given renderTile
*/
void drawFrame(struct renderer *r, struct renderTile tile) {
int length = 8;
int length = tile.width < 16 ? 4 : 8;
struct color c = clearColor;
if (tile.isRendering) {
c = frameColor;
}
if (tile.width < 16) length = 4;
for (int i = 1; i < length; i++) {
//top left
blit(r->state.uiBuffer, c, tile.begin.x+i, tile.begin.y+1);
Expand Down

0 comments on commit b2ece87

Please sign in to comment.