# Prefix all object file names with the compilation directory
objects ::= $(addprefix out/, \
- main.o level.o logger.o \
- performance.o render.o tga.o ui.o)
+ main.o asset.o level.o logger.o \
+ performance.o player.o render.o tga.o ui.o)
# Set executable extension for the platform
ifeq ($(OS),Windows_NT)
--- /dev/null
+#include <assimp/cimport.h>
+#include <assimp/postprocess.h>
+
+#include "assimp_types.h"
+
+#include "logger.h"
+
+const AiScene* importScene(const char* path) {
+ const AiScene* scene = aiImportFile(path, aiProcess_PreTransformVertices);
+ if (scene == NULL) {
+ logError("Failed to import asset from %s", path);
+ }
+ else if ((scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
+ logError("Incomplete scene imported from %s", path);
+ aiReleaseImport(scene);
+ scene = NULL;
+ }
+ return scene;
+ // TODO aiReleaseImport(scene);
+}
--- /dev/null
+#ifndef ASSET_H_
+#define ASSET_H_
+
+#include "assimp_types.h"
+
+const AiScene* importScene(const char* path);
+
+#endif
#include <assimp/scene.h>
+#ifdef ASSIMP_DOUBLE_PRECISION
+ #error "ASSIMP_DOUBLE_PRECISION is defined"
+ #error "shadowclad relies on ai_real defined as a single precision float"
+#endif
+
typedef struct aiScene AiScene;
typedef struct aiNode AiNode;
typedef struct aiMesh AiMesh;
#include <GL/gl.h>
-#include <assimp/cimport.h>
-#include <assimp/postprocess.h>
#include <stdlib.h>
+#include "asset.h"
#include "level.h"
#include "logger.h"
+#include "player.h"
static Block blockEmpty = { .type = BLOCKTYPE_SPACE,
.sceneData = NULL,
.depth = 3,
.blocks = testBlocks };
-//static TgaImage* levelImage = NULL;
+#define DEFAULT_PLAYER_SPAWN_POS { -BLOCKGRID_CELL_SIZE, 0.0f, -BLOCKGRID_CELL_SIZE }
+AiVector3D playerSpawnPos = DEFAULT_PLAYER_SPAWN_POS;
static const char* replaceFileExtension(const AiString path, const char* ext);
+
+
void initLevel() {
const AiScene* sceneData = importScene("out/assets/wall01.3ds");
blockWall01.sceneData = sceneData;
.blocks = malloc(image->header.imageWidth
* image->header.imageHeight
* sizeof(Block*)) };
+ playerSpawnPos = (AiVector3D) DEFAULT_PLAYER_SPAWN_POS;
for (int z = 0; z < newGrid.depth; ++z) {
for (int x = 0; x < newGrid.width; ++x) {
case 0xFFFF0000:
block = &blockWall01;
break;
+ case 0xFF00FFFF:
+ block = &blockEmpty;
+ playerSpawnPos = (AiVector3D) { x * BLOCKGRID_CELL_SIZE, 0.0f, z * BLOCKGRID_CELL_SIZE };
+ break;
default:
block = &blockEmpty;
break;
}
levelGrid = newGrid;
-}
-
-const AiScene* importScene(const char* path) {
- const AiScene* scene = aiImportFile(path, aiProcess_PreTransformVertices);
- if (scene == NULL) {
- logError("Failed to import asset from %s", path);
- }
- else if ((scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
- logError("Incomplete scene imported from %s", path);
- aiReleaseImport(scene);
- scene = NULL;
- }
- return scene;
- // TODO aiReleaseImport(scene);
+ spawnPlayer();
}
/** BUGS
#define BLOCKGRID_CELL_SIZE 2.5f
BlockGrid levelGrid;
+AiVector3D playerSpawnPos;
void initLevel();
void buildLevelFromImage(TgaImage* image);
-const AiScene* importScene(const char* path);
static inline Block* getBlockFromGrid(BlockGrid grid, int x, int z) {
return grid.blocks[(z * grid.width) + x];
LogLevel logLevel = LOGLEVEL_DEBUG;
+
+
void logMessage(LogLevel msgLevel, const char* file, int line, const char* message, ...) {
if (msgLevel > logLevel) {
return;
#include <GL/glxew.h>
#include <GL/glut.h>
-//#include "debugutil.h"
#include "level.h"
#include "logger.h"
#include "performance.h"
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow(NULL);
- // glutSetWindowTitle(getGlInfoString());
glutSetWindowTitle("shadowclad");
logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
static int frames = 0;
static bool meteringEnabled = false;
+
+
void initPerformanceMetering() {
if (clock_gettime(CLOCK_MONOTONIC, &lastDisplayTime) != 0) {
logWarning("Clock read failed, performance metering unavailable");
--- /dev/null
+#include "asset.h"
+#include "level.h"
+#include "logger.h"
+#include "player.h"
+
+PlayerCharacter playerCharacter = { .sceneData = NULL,
+ .textureIds = NULL };
+
+static AiVector3D playerPos;
+
+
+
+void initPlayer() {
+ playerCharacter.sceneData = importScene("out/assets/playercharacter.3ds");
+ // TODO import textures
+}
+
+void spawnPlayer() {
+ playerPos = playerSpawnPos;
+}
--- /dev/null
+#ifndef PLAYER_H_
+#define PLAYER_H_
+
+#include <GL/gl.h>
+
+#include "assimp_types.h"
+
+typedef struct {
+ const AiScene* sceneData;
+ GLuint* textureIds;
+} PlayerCharacter;
+
+void spawnPlayer();
+
+#endif
static void renderBlockGrid(const BlockGrid grid);
static void drawBlock(const Block* block);
+
+
void initRender() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);