#include <assimp/postprocess.h>
#include "asset.h"
+#include "assimp_types.h"
#include "logger.h"
#include "tga.h"
const unsigned int numMeshes = scene->mNumMeshes;
const unsigned int numMaterials = scene->mNumMaterials;
+
+ // TODO Consider assets with some arrays empty, and prevent zero mallocs
Asset3D* asset = malloc(sizeof(Asset3D));
asset->numMeshes = numMeshes;
const unsigned int numIndices = aiFace.mNumIndices;
Face face = { .numIndices = numIndices,
- .indices = malloc(numIndices
- * sizeof(unsigned int)) };
+ .indices = malloc(numIndices * sizeof(size_t)) };
for (unsigned int i = 0; i < numIndices; ++i) {
face.indices[i] = aiFace.mIndices[i];
0,
&originalTexturePath,
NULL, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) {
- const char* textureFile = replaceFileExtension(originalTexturePath, ".tga");
- const size_t textureFileLength = strlen(textureFile);
- char* texturePath = malloc(strlen("assets/") + textureFileLength + 1);
+ const char* textureFilename = replaceFileExtension(originalTexturePath, ".tga");
+ const size_t textureFilenameLength = strlen(textureFilename);
+ char* texturePath = malloc(strlen("assets/") + textureFilenameLength + 1);
strcpy(texturePath, "assets/");
- strncat(texturePath, textureFile, textureFileLength);
+ strncat(texturePath, textureFilename, textureFilenameLength);
TgaImage* textureImage = readTga(texturePath);
if (textureImage == NULL) {
if (scene == NULL) {
logError("Failed to import asset from %s", path);
}
- else if ((scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
+ else if (scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) {
logError("Incomplete scene imported from %s", path);
aiReleaseImport(scene);
scene = NULL;
.z = vect.z };
}
-/** BUGS
+/**
+ * BUGS
* The following function will not work properly with texture
* file names (excluding directory part) beginning with '.'
*/
#ifndef ASSET_H_
#define ASSET_H_
-#include <GL/gl.h>
+#include <stddef.h>
-#include "assimp_types.h"
+#include <GL/gl.h>
#include "geometry.h"
typedef struct Material Material;
struct Asset3D {
- unsigned int numMeshes;
+ size_t numMeshes;
Mesh* meshes;
- unsigned int numMaterials;
+ size_t numMaterials;
Material* materials;
};
struct Mesh {
- unsigned int numVertices;
+ size_t numVertices;
Vector3D* vertices;
Vector3D* normals;
Vector3D* textureCoords;
- unsigned int numFaces;
+ size_t numFaces;
Face* faces;
- unsigned int materialIndex;
+ size_t materialIndex;
};
struct Face {
- unsigned int numIndices;
- unsigned int* indices;
+ size_t numIndices;
+ size_t* indices;
};
struct Material {
static void renderBlockGrid(const BlockGrid grid) {
glMatrixMode(GL_MODELVIEW);
- for (int z = 0; z < grid.depth; ++z) {
+ for (size_t z = 0; z < grid.depth; ++z) {
glLoadIdentity();
glTranslatef(0.0f, 0.0f, z * BLOCKGRID_CELL_SIZE);
- for (int x = 0; x < grid.width; ++x) {
+ for (size_t x = 0; x < grid.width; ++x) {
drawAsset3D(getBlockFromGrid(grid, x, z)->asset3D);
glTranslatef(BLOCKGRID_CELL_SIZE, 0.0f, 0.0f);
}
glBegin(faceMode);
for (size_t i = 0; i < face.numIndices; ++i) {
- unsigned int vertIndex = face.indices[i];
+ size_t vertIndex = face.indices[i];
if (hasNormals) {
if (hasTextureCoords) {
Vector3D coords = mesh.textureCoords[vertIndex];
* sizeof(Block*)) };
playerSpawnPos = (Vector3D) DEFAULT_PLAYER_SPAWN_POS;
- for (int row = 0; row < newGrid.depth; ++row) {
- for (int x = 0; x < newGrid.width; ++x) {
+ 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
- int z = newGrid.depth - row - 1;
+ size_t z = newGrid.depth - row - 1;
uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(row * newGrid.width) + x];
Block* block;
} Block;
typedef struct {
- int width;
- int depth;
+ size_t width;
+ size_t depth;
Block** blocks;
} BlockGrid;
void initLevel();
void buildLevelFromImage(TgaImage* image);
-static inline Block* getBlockFromGrid(BlockGrid grid, int x, int z) {
+static inline Block* getBlockFromGrid(BlockGrid grid, size_t x, size_t z) {
return grid.blocks[(z * grid.width) + x];
}
-static inline void setBlockInGrid(BlockGrid grid, int x, int z, Block* block) {
+static inline void setBlockInGrid(BlockGrid grid, size_t x, size_t z, Block* block) {
grid.blocks[(z * grid.width) + x] = block;
}