Added camera

Moved some math types
Added some more vector types
Did the camera matrix calulations
Updated shaders to take push constants
This commit is contained in:
2025-10-05 02:40:59 +01:00
parent 2c67896cf2
commit 3b8c50a361
15 changed files with 355 additions and 70 deletions

View File

@@ -21,11 +21,10 @@ struct navSearchState{
navSearchState initState(U32 start, U32 meshSize) {
navSearchState state = {};
for(U32 i = 0; i < meshSize; i++) {
state.nodeStates[i].visited = false;
state.nodeStates[i].visited = false;
state.nodeStates[i].addedToUnvisited = false;
// underflow to the max :)
state.nodeStates[i].distance = U64_MAX;
state.nodeStates[i].shortest = 0;
state.nodeStates[i].distance = U64_MAX;
state.nodeStates[i].shortest = 0;
}
state.nodeStates[start].distance = 0;
return state;
@@ -53,8 +52,8 @@ U32 getLowestState(U32 unfinishedIndexes[128], U32 unfinishedCount, navSearchSta
}
// Generate a path to follow between the start and end node.
NavPath Nav_Path(NavMesh mesh, U32 start, U32 end) {
navSearchState state = initState(start, mesh.nodeCount);
NavPath Nav_Path(NavMesh *mesh, U32 start, U32 end) {
navSearchState state = initState(start, mesh->nodeCount);
U32 unfinishedCount = 1;
U32 unfinishedIndexes[NAV_MAX_NODES] = {start};
// I don't want to spend time removing items from
@@ -65,19 +64,19 @@ NavPath Nav_Path(NavMesh mesh, U32 start, U32 end) {
U32 lowestNodeIndex = start;
bool found = false;
while(!found) {
for(int connectionI = 0 ; connectionI < mesh.nodes[lowestNodeIndex].connectionCount; connectionI++) {
NavConnection connection = mesh.nodes[lowestNodeIndex].connections[connectionI];
navSearchNodeState *testNode = &state.nodeStates[connection.NodeIndex];
for(int connectionI = 0 ; connectionI < mesh->nodes[lowestNodeIndex].connectionCount; connectionI++) {
NavConnection *connection = &mesh->nodes[lowestNodeIndex].connections[connectionI];
navSearchNodeState *testNode = &state.nodeStates[connection->NodeIndex];
if(testNode->visited) {continue;}
U32 distance = cast(U32) (state.nodeStates[lowestNodeIndex].distance + connection.Cost);
distance += cast(U32) (mesh.nodes[end].pos.x - mesh.nodes[connection.NodeIndex].pos.x);
distance += cast(U32) (mesh.nodes[end].pos.y - mesh.nodes[connection.NodeIndex].pos.y);
U32 distance = cast(U32) (state.nodeStates[lowestNodeIndex].distance + connection->Cost);
distance += cast(U32) (mesh->nodes[end].pos.x - mesh->nodes[connection->NodeIndex].pos.x);
distance += cast(U32) (mesh->nodes[end].pos.y - mesh->nodes[connection->NodeIndex].pos.y);
if(testNode->distance > distance) {
testNode->distance = distance;
testNode->shortest = lowestNodeIndex;
}
if(!testNode->addedToUnvisited) {
unfinishedIndexes[unfinishedCount] = connection.NodeIndex;
unfinishedIndexes[unfinishedCount] = connection->NodeIndex;
unfinishedCount++;
testNode->addedToUnvisited = true;
}

View File

@@ -1,6 +1,7 @@
#include "../npc.h"
#include "../world.h"
#include "../../core/types.h"
#include "game/npc.h"
#include "game/world.h"
#include "core/types.h"
#include <stdio.h>
void updateNPC(F32 delta, NPC *npc, World *world) {
@@ -33,15 +34,15 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
npc->pathIndex+=1;
npc->currentNavNode = npc->path.indexes[npc->pathIndex];
}
NavNode cNav = world->navMesh.nodes[npc->currentNavNode];
NavNode tNav = world->navMesh.nodes[npc->pathIndex];
NavNode cNav = world->navMesh->nodes[npc->currentNavNode];
NavNode tNav = world->navMesh->nodes[npc->pathIndex];
npc->collision.pos.x = cNav.pos.x * (1 - npc->walkTimer/NPC_SPEED) + tNav.pos.x * npc->walkTimer/NPC_SPEED;
npc->collision.pos.y = cNav.pos.y * (1 - npc->walkTimer/NPC_SPEED) + tNav.pos.y * npc->walkTimer/NPC_SPEED;
break;
}
}
void UpdateNPCs(F32 delta, World *world) {
void updateNPCs(F32 delta, World *world) {
for(U32 i = 0; i < world->npcCount; i++) {
updateNPC(delta, &world->npcs[i], world);
}