Prog
This commit is contained in:
@@ -14,20 +14,18 @@ errorret_t assetMapLoad(void *data, void *output) {
|
||||
assertNotNull(output, "Output cannot be NULL");
|
||||
|
||||
assetmap_t *mapData = (assetmap_t *)data;
|
||||
assetmapmodel_t *mesh = (assetmapmodel_t *)output;
|
||||
assetmap_t *out = (assetmap_t *)output;
|
||||
|
||||
memoryCopy(
|
||||
mesh,
|
||||
&mapData->models[0],
|
||||
sizeof(assetmapmodel_t)
|
||||
);
|
||||
memoryCopy(out, mapData, sizeof(assetmap_t));
|
||||
|
||||
meshInit(
|
||||
&mesh->mesh,
|
||||
&out->models[0].mesh,
|
||||
MESH_PRIMITIVE_TRIANGLES,
|
||||
mesh->vertexCount,
|
||||
mesh->vertices
|
||||
out->models[0].vertexCount,
|
||||
out->models[0].vertices
|
||||
);
|
||||
|
||||
printf("Load asset\n");
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint32_t vertexCount;
|
||||
meshvertex_t vertices[36];
|
||||
meshvertex_t vertices[6 * CHUNK_TILE_COUNT];
|
||||
mesh_t mesh;
|
||||
} assetmapmodel_t;
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ void meshDraw(
|
||||
const GLsizei stride = sizeof(meshvertex_t);
|
||||
|
||||
glColorPointer(
|
||||
MESH_VERTEX_COLOR_SIZE,
|
||||
sizeof(color4b_t),
|
||||
GL_UNSIGNED_BYTE,
|
||||
stride,
|
||||
(const GLvoid*)&mesh->vertices[offset].color[0]
|
||||
(const GLvoid*)&mesh->vertices[offset].color
|
||||
);
|
||||
glTexCoordPointer(
|
||||
MESH_VERTEX_UV_SIZE,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "display/display.h"
|
||||
#include "display/color.h"
|
||||
|
||||
typedef enum {
|
||||
#if DISPLAY_SDL2
|
||||
@@ -14,13 +15,12 @@ typedef enum {
|
||||
#endif
|
||||
} meshprimitivetype_t;
|
||||
|
||||
#define MESH_VERTEX_COLOR_SIZE 4
|
||||
#define MESH_VERTEX_UV_SIZE 2
|
||||
#define MESH_VERTEX_POS_SIZE 3
|
||||
|
||||
typedef struct {
|
||||
#if DISPLAY_SDL2
|
||||
GLubyte color[MESH_VERTEX_COLOR_SIZE];
|
||||
color4b_t color;
|
||||
GLfloat uv[MESH_VERTEX_UV_SIZE];
|
||||
GLfloat pos[MESH_VERTEX_POS_SIZE];
|
||||
#endif
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
mesh_t QUAD_MESH_SIMPLE;
|
||||
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||
{ COLOR_WHITE_4B, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||
{ COLOR_WHITE_4B, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
||||
{ COLOR_WHITE_4B, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }
|
||||
{ COLOR_WHITE_4B, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||
{ COLOR_WHITE_4B, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||
{ COLOR_WHITE_4B, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }
|
||||
};
|
||||
|
||||
void quadInit() {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "map.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "scene/scene/scenemap.h"
|
||||
|
||||
map_t MAP;
|
||||
|
||||
@@ -111,6 +112,7 @@ void mapPositionSet(const chunkpos_t newPos) {
|
||||
void mapUpdate() {
|
||||
|
||||
}
|
||||
|
||||
void mapChunkUnload(chunk_t* chunk) {
|
||||
printf("Unloading chunk at (%d, %d, %d)\n",
|
||||
chunk->position.x,
|
||||
@@ -120,33 +122,20 @@ void mapChunkUnload(chunk_t* chunk) {
|
||||
}
|
||||
|
||||
void mapChunkLoad(chunk_t* chunk) {
|
||||
printf("Loading chunk at (%d, %d, %d)\n",
|
||||
chunk->position.x,
|
||||
chunk->position.y,
|
||||
chunk->position.z
|
||||
);
|
||||
// printf("Loading chunk at (%d, %d, %d)\n",
|
||||
// chunk->position.x,
|
||||
// chunk->position.y,
|
||||
// chunk->position.z
|
||||
// );
|
||||
|
||||
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
|
||||
|
||||
// 3x3 test walkable area
|
||||
chunktileindex_t x, y, z;
|
||||
|
||||
z = 0;
|
||||
for(y = 0; y <= 3; y++) {
|
||||
for(x = 0; x <= 3; x++) {
|
||||
chunktileindex_t tileIndex = (y * CHUNK_WIDTH) + x;
|
||||
chunk->tiles[tileIndex] = TILE_WALKABLE;
|
||||
if(chunk->position.x == 0 && chunk->position.y == 0 && chunk->position.z == 0) {
|
||||
if(TEST_MAP_READY) {
|
||||
|
||||
}
|
||||
printf("LOAD CHUNK\n");
|
||||
}
|
||||
|
||||
x = 3, y = 3;
|
||||
chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_STAIRS_UP;
|
||||
|
||||
// x = 3, y = 2, z = 1;
|
||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
||||
// x = 2, y = 2, z = 1;
|
||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
||||
// x = 4, y = 2, z = 1;
|
||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
||||
}
|
||||
|
||||
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
#include "rpg/rpgcamera.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
#define TILE_SIZE 16
|
||||
assetmapmodel_t mesh;
|
||||
#define TILE_WIDTH 16.0f
|
||||
#define TILE_HEIGHT 16.0f
|
||||
#define TILE_DEPTH 11.36f
|
||||
assetmap_t TEST_MAP;
|
||||
bool_t TEST_MAP_READY = false;
|
||||
|
||||
errorret_t sceneMapInit(scenedata_t *data) {
|
||||
// Init the camera.
|
||||
@@ -37,7 +40,8 @@ errorret_t sceneMapInit(scenedata_t *data) {
|
||||
data->sceneMap.camera.lookatPixelPerfect.pixelsPerUnit = 1.0f;
|
||||
|
||||
|
||||
errorChain(assetLoad("map/map.dmf", &mesh));
|
||||
errorChain(assetLoad("map/map.dmf", &TEST_MAP));
|
||||
TEST_MAP_READY = true;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -48,9 +52,9 @@ void sceneMapUpdate(scenedata_t *data) {
|
||||
void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
|
||||
assertNotNull(outPosition, "Output position cannot be NULL");
|
||||
|
||||
outPosition[0] = pos.x * TILE_SIZE;
|
||||
outPosition[1] = pos.y * TILE_SIZE;
|
||||
outPosition[2] = pos.z * TILE_SIZE;
|
||||
outPosition[0] = pos.x * TILE_WIDTH;
|
||||
outPosition[1] = pos.y * TILE_HEIGHT;
|
||||
outPosition[2] = pos.z * TILE_DEPTH;
|
||||
}
|
||||
|
||||
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
||||
@@ -70,13 +74,13 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
||||
vec3 offset = {
|
||||
(
|
||||
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
||||
) * TILE_SIZE * -animPercentage,
|
||||
) * TILE_WIDTH * -animPercentage,
|
||||
(
|
||||
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
||||
) * TILE_SIZE * -animPercentage,
|
||||
) * TILE_HEIGHT * -animPercentage,
|
||||
(
|
||||
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
||||
) * TILE_SIZE * -animPercentage
|
||||
) * TILE_DEPTH * -animPercentage
|
||||
};
|
||||
glm_vec3_add(outPosition, offset, outPosition);
|
||||
break;
|
||||
@@ -117,7 +121,7 @@ void sceneMapRender(scenedata_t *data) {
|
||||
// sceneMapRenderMap();
|
||||
|
||||
textureBind(NULL);
|
||||
meshDraw(&mesh.mesh, -1, -1);
|
||||
meshDraw(&TEST_MAP.models[0].mesh, -1, -1);
|
||||
|
||||
// Render ents
|
||||
entity_t *ent = ENTITIES;
|
||||
@@ -136,7 +140,7 @@ void sceneMapRenderEntity(entity_t *entity) {
|
||||
if(entity->type == ENTITY_TYPE_NULL) return;
|
||||
|
||||
vec3 posMin, posMax;
|
||||
vec3 size = { TILE_SIZE, TILE_SIZE, TILE_SIZE };
|
||||
vec3 size = { TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH };
|
||||
sceneMapEntityGetPosition(entity, posMin);
|
||||
glm_vec3_add(posMin, size, posMax);
|
||||
|
||||
@@ -172,12 +176,12 @@ void sceneMapRenderMap() {
|
||||
chunk_t *chunk = MAP.chunkOrder[i];
|
||||
|
||||
vec3 min, max;
|
||||
min[0] = chunk->position.x * CHUNK_WIDTH * TILE_SIZE;
|
||||
min[1] = chunk->position.y * CHUNK_HEIGHT * TILE_SIZE;
|
||||
min[2] = chunk->position.z * CHUNK_DEPTH * TILE_SIZE;
|
||||
min[0] = chunk->position.x * CHUNK_WIDTH * TILE_WIDTH;
|
||||
min[1] = chunk->position.y * CHUNK_HEIGHT * TILE_HEIGHT;
|
||||
min[2] = chunk->position.z * CHUNK_DEPTH * TILE_DEPTH;
|
||||
|
||||
max[0] = min[0] + (CHUNK_WIDTH * TILE_SIZE);
|
||||
max[1] = min[1] + (CHUNK_HEIGHT * TILE_SIZE);
|
||||
max[0] = min[0] + (CHUNK_WIDTH * TILE_WIDTH);
|
||||
max[1] = min[1] + (CHUNK_HEIGHT * TILE_HEIGHT);
|
||||
max[2] = min[2];
|
||||
|
||||
color_t color = COLOR_WHITE;
|
||||
@@ -199,5 +203,5 @@ void sceneMapRenderMap() {
|
||||
}
|
||||
|
||||
void sceneMapDispose(scenedata_t *data) {
|
||||
meshDispose(&mesh.mesh);
|
||||
meshDispose(&TEST_MAP.models[0].mesh);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,15 @@
|
||||
#include "scene/scene.h"
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "display/camera.h"
|
||||
#include "asset/asset.h"
|
||||
|
||||
typedef struct {
|
||||
camera_t camera;
|
||||
} scenemap_t;
|
||||
|
||||
extern assetmap_t TEST_MAP;
|
||||
extern bool_t TEST_MAP_READY;
|
||||
|
||||
errorret_t sceneMapInit(scenedata_t *data);
|
||||
void sceneMapUpdate(scenedata_t *data);
|
||||
void sceneMapRender(scenedata_t *data);
|
||||
|
||||
@@ -29,9 +29,10 @@ void uiDebugRender(const tileset_t *tileset, texture_t *texture) {
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%.2f/%.2f/%d",
|
||||
"%.2f/%.2f/%d/%d",
|
||||
TIME.dynamicDelta * 1000.0f,
|
||||
TIME.delta * 1000.0f,
|
||||
TIME.dynamicUpdate,
|
||||
(int32_t)fpsDynamic
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user