Fixed PSP compiling
This commit is contained in:
@@ -10,7 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||
set(DUSK_TARGET_SYSTEM "linux")
|
||||
# set(DUSK_TARGET_SYSTEM "linux")
|
||||
set(DUSK_TARGET_SYSTEM "psp")
|
||||
endif()
|
||||
|
||||
# Prep cache
|
||||
@@ -60,6 +61,18 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
OpenGL::GL
|
||||
GL
|
||||
)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
# pspsdk
|
||||
${SDL2_LIBRARIES}
|
||||
)
|
||||
target_include_directories(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add code
|
||||
|
@@ -21,4 +21,13 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=960
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=720
|
||||
)
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
DUSK_DISPLAY_SDL2=1
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=480
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=272
|
||||
DISPLAY_WIDTH=480
|
||||
DISPLAY_HEIGHT=272
|
||||
)
|
||||
endif()
|
@@ -75,7 +75,7 @@ errorret_t displayUpdate(void) {
|
||||
|
||||
// Set viewport size.
|
||||
int32_t windowWidth, windowHeight;
|
||||
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
|
||||
// SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
|
||||
glViewport(0, 0, windowWidth, windowHeight);
|
||||
#endif
|
||||
|
||||
|
@@ -19,9 +19,11 @@ typedef enum {
|
||||
#define MESH_VERTEX_POS_SIZE 3
|
||||
|
||||
typedef struct {
|
||||
GLubyte color[MESH_VERTEX_COLOR_SIZE];
|
||||
GLfloat uv[MESH_VERTEX_UV_SIZE];
|
||||
GLfloat pos[MESH_VERTEX_POS_SIZE];
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
GLubyte color[MESH_VERTEX_COLOR_SIZE];
|
||||
GLfloat uv[MESH_VERTEX_UV_SIZE];
|
||||
GLfloat pos[MESH_VERTEX_POS_SIZE];
|
||||
#endif
|
||||
} meshvertex_t;
|
||||
|
||||
typedef struct {
|
||||
|
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "meshrenderer.h"
|
||||
#include "scene/node.h"
|
||||
|
||||
meshrenderer_t MESH_RENDERER_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
|
||||
ecscomponent_t MESH_RENDERER_COMPONENT = ecsComponentInit(
|
||||
@@ -22,5 +23,9 @@ void meshRendererDraw(const ecsid_t id) {
|
||||
|
||||
meshrenderer_t *renderer = &MESH_RENDERER_DATA[id];
|
||||
if(!renderer->mesh) return;
|
||||
|
||||
node_t *node = nodeGet(id);
|
||||
nodeMatrixUpdate(id);
|
||||
|
||||
meshDraw(renderer->mesh, 0, -1);
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "renderer.h"
|
||||
#include "display/mesh/meshrenderer.h"
|
||||
#include "scene/node.h"
|
||||
|
||||
void rendererRender(const ecsid_t camera) {
|
||||
if(camera == -1) return;
|
||||
@@ -14,11 +15,14 @@ void rendererRender(const ecsid_t camera) {
|
||||
// Get the meshes.
|
||||
uint32_t meshCount;
|
||||
ecsid_t meshes[ECS_ENTITY_COUNT_MAX];
|
||||
ecsid_t id;
|
||||
meshCount = meshRendererGetAll(meshes);
|
||||
|
||||
cameraPush(camera);
|
||||
for(uint32_t i = 0; i < meshCount; i++) {
|
||||
meshRendererDraw(meshes[i]);
|
||||
id = meshes[i];
|
||||
nodeMatrixPush(id);
|
||||
meshRendererDraw(id);
|
||||
}
|
||||
cameraPop();
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <float.h>
|
||||
#include <cglm/cglm.h>
|
||||
#include <cglm/types.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef int int_t;
|
||||
|
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/display.h"// Important to be included first.
|
||||
#include "error/error.h"
|
||||
|
||||
typedef struct {
|
||||
|
@@ -7,6 +7,9 @@
|
||||
|
||||
#include "engine/engine.h"
|
||||
|
||||
// PSP_MODULE_INFO("Dusk", 0, 1, 0);
|
||||
// PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | THREAD_ATTR_VFPU);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
errorret_t ret;
|
||||
ret = engineInit();
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "node.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/display.h"
|
||||
|
||||
node_t NODE_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
|
||||
ecscomponent_t NODE_COMPONENT = ecsComponentInit(
|
||||
@@ -50,4 +51,79 @@ void nodeMatrixSet(const ecsid_t id, mat4 in) {
|
||||
}
|
||||
|
||||
glm_mat4_copy(in, node->transform);
|
||||
|
||||
// Extract position, scale, rotation from the matrix.
|
||||
node->position[0] = in[3][0];
|
||||
node->position[1] = in[3][1];
|
||||
node->position[2] = in[3][2];
|
||||
|
||||
node->scale[0] = glm_vec3_norm((vec3){ in[0][0], in[0][1], in[0][2] });
|
||||
node->scale[1] = glm_vec3_norm((vec3){ in[1][0], in[1][1], in[1][2] });
|
||||
node->scale[2] = glm_vec3_norm((vec3){ in[2][0], in[2][1], in[2][2] });
|
||||
|
||||
// Remove scale from the matrix to extract rotation.
|
||||
if(node->scale[0] != 0.0f) {
|
||||
in[0][0] /= node->scale[0];
|
||||
in[0][1] /= node->scale[0];
|
||||
in[0][2] /= node->scale[0];
|
||||
glm_vec3_copy(in[0], node->rotation);
|
||||
glm_vec3_copy(in[1], node->rotation);
|
||||
glm_vec3_copy(in[2], node->rotation);
|
||||
node->rotation[1] = asinf(-in[0][2]);
|
||||
if (cosf(node->rotation[1]) != 0.0f) {
|
||||
node->rotation[0] = atan2f(in[1][2], in[2][2]);
|
||||
node->rotation[2] = atan2f(in[0][1], in[0][0]);
|
||||
} else {
|
||||
node->rotation[0] = 0.0f;
|
||||
node->rotation[2] = atan2f(-in[1][0], in[1][1]);
|
||||
}
|
||||
} else {
|
||||
node->rotation[0] = 0.0f;
|
||||
node->rotation[1] = 0.0f;
|
||||
node->rotation[2] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void nodePositionGet(const ecsid_t id, vec3 out) {
|
||||
node_t *node;
|
||||
|
||||
if(nodeHas(id)) {
|
||||
node = &NODE_DATA[id];
|
||||
} else {
|
||||
node = nodeAdd(id);
|
||||
}
|
||||
|
||||
glm_vec3_copy(node->position, out);
|
||||
}
|
||||
|
||||
void nodeMatrixUpdate(const ecsid_t id) {
|
||||
node_t *node;
|
||||
|
||||
if(nodeHas(id)) {
|
||||
node = &NODE_DATA[id];
|
||||
} else {
|
||||
node = nodeAdd(id);
|
||||
}
|
||||
|
||||
glm_mat4_identity(node->transform);
|
||||
mat4 rot;
|
||||
glm_euler(node->rotation, rot);
|
||||
glm_mat4_mul(node->transform, rot, node->transform);
|
||||
// glm_scale(node->transform, node->scale);
|
||||
}
|
||||
|
||||
void nodeMatrixPush(const ecsid_t id) {
|
||||
assertTrue(nodeHas(id), "Not a node component");
|
||||
node_t *node = nodeGet(id);
|
||||
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPushMatrix();
|
||||
glMultMatrixf((const GLfloat*)node->transform);
|
||||
#endif
|
||||
}
|
||||
|
||||
void nodeMatrixPop(void) {
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
@@ -12,6 +12,10 @@
|
||||
|
||||
typedef struct {
|
||||
mat4 transform;
|
||||
|
||||
vec3 position;
|
||||
vec3 scale;
|
||||
vec3 rotation; // Euler angles in radians
|
||||
} node_t;
|
||||
|
||||
extern node_t NODE_DATA[ECS_ENTITY_COUNT_MAX];
|
||||
@@ -25,15 +29,12 @@ extern ecscomponent_t NODE_COMPONENT;
|
||||
#define nodeRemove(id) ecsComponentDataRemove(&NODE_COMPONENT, id)
|
||||
|
||||
/**
|
||||
* Initialize the scene tree.
|
||||
*
|
||||
* This will initialize the ECS system and prepare the scene tree for use.
|
||||
* Initialize the node component.
|
||||
*/
|
||||
void nodeInit(void);
|
||||
|
||||
/**
|
||||
* Callback for when an entity is added to the ECS.
|
||||
* This will initialize the scene tree data for the entity.
|
||||
*
|
||||
* @param id The ID of the entity being added.
|
||||
*/
|
||||
@@ -41,24 +42,42 @@ void nodeEntityAdded(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Callback for when an entity is removed from the ECS.
|
||||
* This will clean up any scene tree data associated with the entity.
|
||||
*
|
||||
* @param id The ID of the entity being removed.
|
||||
*/
|
||||
void nodeEntityRemoved(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Get the local transformation matrix of a scene item.
|
||||
* Get the local transformation matrix of a node.
|
||||
*
|
||||
* @param id The ID of the scene item.
|
||||
* @param id The ID of the node.
|
||||
* @param out Pointer to a mat4 where the local matrix will be stored.
|
||||
*/
|
||||
void nodeMatrixGet(const ecsid_t id, mat4 out);
|
||||
|
||||
/**
|
||||
* Set the local transformation matrix of a scene item.
|
||||
* Set the local transformation matrix of a node.
|
||||
*
|
||||
* @param id The ID of the scene item.
|
||||
* @param id The ID of the node.
|
||||
* @param in Pointer to a mat4 containing the new local matrix.
|
||||
*/
|
||||
void nodeMatrixSet(const ecsid_t id, mat4 in);
|
||||
void nodeMatrixSet(const ecsid_t id, mat4 in);
|
||||
|
||||
/**
|
||||
* Get the local position of a node.
|
||||
*
|
||||
* @param id The ID of the node.
|
||||
*/
|
||||
void nodeMatrixUpdate(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Push the node's transformation matrix onto the OpenGL matrix stack.
|
||||
*
|
||||
* @param id The ID of the node.
|
||||
*/
|
||||
void nodeMatrixPush(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Pop the last transformation matrix from the OpenGL matrix stack.
|
||||
*/
|
||||
void nodeMatrixPop(void);
|
@@ -16,4 +16,9 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
PRIVATE
|
||||
DUSK_THREAD_PTHREAD=1
|
||||
)
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
DUSK_THREAD_PTHREAD=1
|
||||
)
|
||||
endif()
|
Reference in New Issue
Block a user