Remove indents on empty lines

master
outfrost 2020-07-15 00:05:20 +02:00
parent d259a0da9a
commit c3acebb2cb
6 changed files with 59 additions and 59 deletions

View File

@ -86,30 +86,30 @@ const Solid* importSolid(const char* path) {
logError("Failed to import solid from %s", path);
return NULL;
}
#if IMPORT_DEBUG_
const struct aiMetadata* meta = scene->mMetaData;
logDebug("Metadata from %s: %p", path, meta);
printMetadata(meta);
printAiNodeMetadata(scene->mRootNode);
#endif // IMPORT_DEBUG_
const unsigned int numMeshes = scene->mNumMeshes;
const unsigned int numMaterials = scene->mNumMaterials;
// TODO Consider assets with some arrays empty, and prevent zero mallocs
Solid* solid = malloc(sizeof(Solid));
solid->numMeshes = numMeshes;
solid->meshes = malloc(numMeshes * sizeof(Mesh));
solid->numMaterials = numMaterials;
solid->materials = malloc(numMaterials * sizeof(Material));
for (unsigned int meshIndex = 0; meshIndex < numMeshes; ++meshIndex) {
const struct aiMesh* aiMesh = scene->mMeshes[meshIndex];
const unsigned int numVertices = aiMesh->mNumVertices;
const unsigned int numFaces = aiMesh->mNumFaces;
Mesh mesh = { .numVertices = numVertices,
.vertices = malloc(numVertices * sizeof(Vector)),
.normals = NULL,
@ -117,12 +117,12 @@ const Solid* importSolid(const char* path) {
.numFaces = numFaces,
.faces = malloc(numFaces * sizeof(Face)),
.materialIndex = aiMesh->mMaterialIndex };
for (unsigned int vertIndex = 0; vertIndex < numVertices; ++vertIndex) {
mesh.vertices[vertIndex] = convertAiVector3D(
aiMesh->mVertices[vertIndex]);
}
if (aiMesh->mNormals != NULL) {
mesh.normals = malloc(numVertices * sizeof(Vector));
for (unsigned int normIndex = 0; normIndex < numVertices; ++normIndex) {
@ -130,25 +130,25 @@ const Solid* importSolid(const char* path) {
aiMesh->mNormals[normIndex]);
}
}
mesh.textureCoords = malloc(numVertices * sizeof(Vector));
for (unsigned int texcIndex = 0; texcIndex < numVertices; ++texcIndex) {
mesh.textureCoords[texcIndex] = convertAiVector3D(
aiMesh->mTextureCoords[0][texcIndex]);
}
for (unsigned int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
const struct aiFace aiFace = aiMesh->mFaces[faceIndex];
const unsigned int numIndices = aiFace.mNumIndices;
Face face = { .numIndices = numIndices,
.indices = malloc(numIndices * sizeof(size_t)),
.normals = malloc(numIndices * sizeof(Vector)) };
for (unsigned int i = 0; i < numIndices; ++i) {
face.indices[i] = aiFace.mIndices[i];
}
if (numIndices == 3) {
Vector normal = triangleNormal(mesh.vertices[face.indices[0]],
mesh.vertices[face.indices[1]],
@ -168,7 +168,7 @@ const Solid* importSolid(const char* path) {
face.normals = NULL;
}
}
mesh.faces[faceIndex] = face;
}
@ -207,13 +207,13 @@ const Solid* importSolid(const char* path) {
// TODO Actually clean up the stuff inside
free(mesh.faces);
mesh.faces = smoothedFaces;
solid->meshes[meshIndex] = mesh;
}
GLuint* textureIds = malloc(numMaterials * sizeof(GLuint));
glGenTextures(numMaterials, textureIds);
for (unsigned int matIndex = 0; matIndex < numMaterials; ++matIndex) {
Material material = { .textureId = textureIds[matIndex] };
@ -232,10 +232,10 @@ const Solid* importSolid(const char* path) {
dropString(key);
#endif // IMPORT_DEBUG_
glBindTexture(GL_TEXTURE_2D, material.textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
struct aiString originalTexturePath;
if (aiGetMaterialTexture(scene->mMaterials[matIndex],
aiTextureType_DIFFUSE,
@ -247,7 +247,7 @@ const Solid* importSolid(const char* path) {
char* texturePath = malloc(strlen("assets/") + textureFilenameLength + 1);
strcpy(texturePath, "assets/");
strncat(texturePath, textureFilename, textureFilenameLength);
TgaImage* textureImage = readTga(texturePath);
if (textureImage == NULL) {
logError("Importing solid from %s: Cannot read texture file %s", path, texturePath);
@ -266,11 +266,11 @@ const Solid* importSolid(const char* path) {
free(textureImage);
}
}
solid->materials[matIndex] = material;
}
glBindTexture(GL_TEXTURE_2D, 0);
aiReleaseImport(scene);
return solid;
}
@ -304,18 +304,18 @@ static Vector convertAiVector3D(struct aiVector3D vect) {
*/
static const char* replaceFileExtension(const struct aiString path, const char* ext) {
size_t lengthToCopy = path.length;
char* lastDotSubstr = strrchr(path.data, '.');
if (lastDotSubstr != NULL) {
if (strpbrk(lastDotSubstr, "\\/") == NULL) {
lengthToCopy = lastDotSubstr - path.data;
}
}
size_t extLength = strlen(ext) + 1;
char* newPath = malloc(lengthToCopy + extLength);
strncpy(newPath, path.data, lengthToCopy);
strncpy(newPath + lengthToCopy, ext, extLength);
return newPath;
}

View File

@ -11,7 +11,7 @@ void logMessage(LogLevel msgLevel, const char* func, const char* message, ...) {
if (msgLevel > logLevel) {
return;
}
const char* msgLevelString;
switch (msgLevel) {
case LOGLEVEL_ERROR:
@ -30,13 +30,13 @@ void logMessage(LogLevel msgLevel, const char* func, const char* message, ...) {
msgLevelString = "(invalid message level) ";
break;
}
va_list args;
va_start(args, message);
fprintf(stderr, "%s %s:: ", func, msgLevelString);
vfprintf(stderr, message, args);
fputc('\n', stderr);
va_end(args);
}

View File

@ -31,16 +31,16 @@ void frameRendered() {
if (meteringEnabled) {
++frames;
Timepoint now;
if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {
logWarning("Clock read failed, stopping performance metering");
meteringEnabled = false;
return;
}
time_t fullSeconds = now.tv_sec - lastDisplayTime.tv_sec;
if (now.tv_nsec < lastDisplayTime.tv_nsec) --fullSeconds;
if (fullSeconds > 0) {
float seconds = (now.tv_nsec - lastDisplayTime.tv_nsec) / 1000000000.0f;
seconds += (float) (now.tv_sec - lastDisplayTime.tv_sec);

View File

@ -20,21 +20,21 @@ static void drawSolid(const Solid* solid);
void initRender() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLfloat light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
GLfloat light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat light0_specular[] = {0.96f, 0.98f, 1.0f, 1.0f};
GLfloat light0_position[] = {5.0f, 10.0f, 5.0f, 0.0f}; // (w == 0.0f) == directional
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05f);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.005f);
//glShadeModel(GL_FLAT);
}
@ -135,18 +135,18 @@ static void drawSolid(const Solid* solid) {
if (solid == NULL) {
return;
}
glMatrixMode(GL_MODELVIEW);
glColor3f(0.5f, 1.0f, 0.0f);
for (size_t meshIndex = 0; meshIndex < solid->numMeshes; ++meshIndex) {
const Mesh mesh = solid->meshes[meshIndex];
glBindTexture(GL_TEXTURE_2D,
solid->materials[mesh.materialIndex].textureId);
for (size_t faceIndex = 0; faceIndex < mesh.numFaces; ++faceIndex) {
const Face face = mesh.faces[faceIndex];
if (debugRender && face.normals) {
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
@ -163,7 +163,7 @@ static void drawSolid(const Solid* solid) {
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
}
GLenum faceMode;
switch (face.numIndices) {
case 1: faceMode = GL_POINTS; break;
@ -171,9 +171,9 @@ static void drawSolid(const Solid* solid) {
case 3: faceMode = GL_TRIANGLES; break;
default: faceMode = GL_POLYGON; break;
}
glBegin(faceMode);
for (size_t i = 0; i < face.numIndices; ++i) {
size_t vertIndex = face.indices[i];
if (face.normals) {
@ -188,7 +188,7 @@ static void drawSolid(const Solid* solid) {
Vector vertex = mesh.vertices[vertIndex];
glVertex3f(vertex.x, vertex.y, vertex.z);
}
glEnd();
}
}

View File

@ -8,17 +8,17 @@ TgaImage* readTga(const char* path) {
if (tgaFile == NULL) {
return NULL;
}
TgaHeader header;
if (fread(&header, sizeof(TgaHeader), 1, tgaFile) != 1) {
fclose(tgaFile);
return NULL;
}
GLenum imageFormat;
GLint imageComponents;
switch (header.imageBpp) {
case 32:
imageFormat = GL_BGRA;
@ -36,32 +36,32 @@ TgaImage* readTga(const char* path) {
fclose(tgaFile);
return NULL;
}
unsigned long imageSize = header.imageWidth * header.imageHeight * (header.imageBpp >> 3);
GLbyte* bytes = malloc(imageSize * sizeof(GLbyte));
if (bytes == NULL) {
fclose(tgaFile);
return NULL;
}
if (fread(bytes, imageSize, 1, tgaFile) != 1) {
free(bytes);
fclose(tgaFile);
return NULL;
}
fclose(tgaFile);
TgaImage* image = malloc(sizeof(TgaImage));
if (image == NULL) {
return NULL;
}
(*image).header = header;
(*image).imageFormat = imageFormat;
(*image).imageComponents = imageComponents;
(*image).bytes = bytes;
return image;
}

View File

@ -61,23 +61,23 @@ static void buildLevelFromImage(const TgaImage* image) {
logError("Null image received, cannot build level");
return;
}
if (image->header.imageBpp != 32) {
logError("Invalid level image format (%d bpp)", image->header.imageBpp);
return;
}
BlockGrid newGrid = { .width = image->header.imageWidth,
.depth = image->header.imageHeight,
.blocks = malloc(image->header.imageWidth
* image->header.imageHeight
* sizeof(Block*)) };
for (size_t row = 0; row < newGrid.depth; ++row) {
for (size_t x = 0; x < newGrid.width; ++x) {
// Flip the image vertically due to (0, 0) being bottom left
size_t z = newGrid.depth - row - 1;
uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(row * newGrid.width) + x];
Block* block;
switch (pixelColorARGB) {
@ -98,7 +98,7 @@ static void buildLevelFromImage(const TgaImage* image) {
setBlockInGrid(newGrid, x, z, block);
}
}
levelGrid = newGrid;
}