Game no longer crashes on Dolphin

This commit is contained in:
2026-03-09 08:05:26 -05:00
parent 23eaffa3a7
commit c5f5b025a6
39 changed files with 1227 additions and 160 deletions
@@ -0,0 +1,11 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
meshdolphin.c
)
@@ -0,0 +1,73 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "display/mesh/mesh.h"
#include "display/texture/texture.h"
#include "assert/assert.h"
errorret_t meshInitDolphin(
meshdolphin_t *mesh,
const meshprimitivetypedolphin_t primitiveType,
const int32_t vertexCount,
const meshvertex_t *vertices
) {
assertNotNull(mesh, "Mesh cannot be null.");
assertNotNull(vertices, "Vertices cannot be null.");
assertTrue(vertexCount > 0, "Vertex count must be greater than 0.");
mesh->primitiveType = primitiveType;
mesh->vertexCount = vertexCount;
mesh->vertices = vertices;
errorOk();
}
errorret_t meshDrawDolphin(
const meshdolphin_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
) {
assertNotNull(mesh, "Mesh cannot be NULL.");
assertTrue(vertexOffset >= 0, "Vertex offset must be >= 0");
assertTrue(vertexCount > 0, "Vertex count must be > 0");
assertTrue(
vertexOffset + vertexCount <= mesh->vertexCount,
"Requested vertex range is invalid"
);
// Prepare Vertex descriptor
DCFlushRange(
(void*)&mesh->vertices[vertexOffset],
sizeof(meshvertex_t) * vertexCount
);
const u8 stride = (u8)sizeof(meshvertex_t);
GX_SetArray(GX_VA_POS, (void*)&mesh->vertices[vertexOffset].pos[0], stride);
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color, stride);
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
textureDolphinUploadTEV();
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
for(u16 i = 0; i < (u16)vertexCount; ++i) {
GX_Position1x16(i);
GX_Color1x16(i);
GX_TexCoord1x16(i);
}
GX_End();
errorOk();
}
int32_t meshGetVertexCountDolphin(const meshdolphin_t *mesh) {
assertNotNull(mesh, "Mesh cannot be NULL.");
return mesh->vertexCount;
}
errorret_t meshDisposeDolphin(meshdolphin_t *mesh) {
errorOk();
}
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "display/mesh/meshvertex.h"
#include "error/error.h"
typedef enum {
MESH_PRIMITIVE_TYPE_TRIANGLES = GX_TRIANGLES,
MESH_PRIMITIVE_TYPE_LINES = GX_LINES,
MESH_PRIMITIVE_TYPE_POINTS = GX_POINTS,
} meshprimitivetypedolphin_t;
typedef struct {
const meshvertex_t *vertices;
int32_t vertexCount;
meshprimitivetypedolphin_t primitiveType;
} meshdolphin_t;
/**
* Initializes a mesh.
*
* @param mesh The mesh to initialize.
* @param primitiveType The Dolphin primitive type (e.g., GX_TRIANGLES).
* @param vertexCount The number of vertices in the mesh.
* @param vertices The vertex data for the mesh.
* @return An error indicating success or failure.
*/
errorret_t meshInitDolphin(
meshdolphin_t *mesh,
const meshprimitivetypedolphin_t primitiveType,
const int32_t vertexCount,
const meshvertex_t *vertices
);
/**
* Draws a mesh.
*
* @param mesh The mesh to draw.
* @param vertexOffset The offset in the vertex array to start drawing from.
* @param vertexCount The number of vertices to draw. If -1, draws all vertices.
* @return An error indicating success or failure.
*/
errorret_t meshDrawDolphin(
const meshdolphin_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
);
/**
* Gets the vertex count of a mesh.
*
* @param mesh The mesh to get the vertex count from.
* @return The vertex count of the mesh.
*/
int32_t meshGetVertexCountDolphin(const meshdolphin_t *mesh);
/**
* Disposes of a mesh, freeing any associated resources.
*
* @param mesh The mesh to dispose of.
* @return An error indicating success or failure.
*/
errorret_t meshDisposeDolphin(meshdolphin_t *mesh);
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "meshdolphin.h"
#define meshInitPlatform meshInitDolphin
#define meshDrawPlatform meshDrawDolphin
#define meshGetVertexCountPlatform meshGetVertexCountDolphin
#define meshDisposePlatform meshDisposeDolphin
typedef meshprimitivetypedolphin_t meshprimitivetypeplatform_t;
typedef meshdolphin_t meshplatform_t;