summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-11-14 14:46:23 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-11-14 14:46:23 -0500
commitb2548ba4ce295fcd94a50123fb543fac2ef2bc33 (patch)
tree444a32abb4a094c4fa2f7bc9a95aa86963ad4110 /src/game.cpp
parentb1d926361b9d613ad712ad161f9a8b7ccab4551d (diff)
add pk.h and major pkmem refactor
Completely replaces the memory module with pkmem pkmem is a newer implementation of the same bucket memory structure. Also includes replacing pkstr.h with pk.h's pkstr
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/game.cpp b/src/game.cpp
index bca8bb2..8fb24e4 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -12,7 +12,6 @@
#include "imgui.h"
#include "level-types.hpp"
#include "level.hpp"
-#include "macros.hpp"
#include "math-helpers.hpp"
#include "physics.hpp"
#include "player-input.hpp"
@@ -21,6 +20,7 @@
#include "thread_pool.hpp"
#include "vendor/glm_include.hpp"
#include "window.hpp"
+#include "vendor/pk.h"
#include <BulletCollision/CollisionShapes/btConvexHullShape.h>
#include <BulletCollision/NarrowPhaseCollision/btRaycastCallback.h>
@@ -74,7 +74,7 @@ const char *PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE = "Cam::TargetInstanceHandle:
const char *PKE_FILE_CAMERA_IS_PRIMARY = "Cam::IsPrimary: ";
void SerializeCamera(std::ostringstream &stream, const PkeCamera &cam) {
- NULL_CHAR_ARR(handleStr, 19);
+ NULL_CHAR_ARR(handleStr, 22);
PkeCamera c{};
if (cam.type != c.type) {
stream << PKE_FILE_CAMERA_TYPE << int(static_cast<PkeCameraType_T>(cam.type)) << std::endl;
@@ -83,11 +83,11 @@ void SerializeCamera(std::ostringstream &stream, const PkeCamera &cam) {
stream << PKE_FILE_CAMERA_ORIENTATION << int(static_cast<PkeCameraView_T>(cam.view)) << std::endl;
}
if (cam.phys.inst != c.phys.inst && cam.phys.inst != CAFE_BABE(CompInstance)) {
- snprintf(handleStr, 19, "0x%016lX", cam.phys.inst->instanceHandle.hash);
+ snprintf(handleStr, 21, "0x%08X 0x%08X", cam.phys.inst->instanceHandle.bucketIndex, cam.phys.inst->instanceHandle.itemIndex);
stream << PKE_FILE_CAMERA_INSTANCE_HANDLE << handleStr << std::endl;
}
if (cam.phys.targetInst != c.phys.targetInst && cam.phys.targetInst != CAFE_BABE(CompInstance)) {
- snprintf(handleStr, 19, "0x%016lX", cam.phys.targetInst->instanceHandle.hash);
+ snprintf(handleStr, 21, "0x%08X 0x%08X", cam.phys.targetInst->instanceHandle.bucketIndex, cam.phys.targetInst->instanceHandle.itemIndex);
stream << PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE << handleStr << std::endl;
}
if (cam.isPrimary != c.isPrimary) {
@@ -96,7 +96,7 @@ void SerializeCamera(std::ostringstream &stream, const PkeCamera &cam) {
}
void SerializeInstance(std::ostringstream &stream, const CompInstance &comp) {
- NULL_CHAR_ARR(handleStr, 19);
+ NULL_CHAR_ARR(handleStr, 22);
EntityType *et = nullptr;
if (comp.grBindsHandle != GrBindsHandle_MAX) {
et = EntityType_FindByEntityHandle(ECS_GetGrBinds(comp.grBindsHandle)->entHandle);
@@ -108,15 +108,15 @@ void SerializeInstance(std::ostringstream &stream, const CompInstance &comp) {
baseInst.scale = btVector3(1, 1, 1);
baseInst.mass = 1;
if (comp.entHandle != c.entHandle) {
- snprintf(handleStr, 19, "0x%016lX", comp.entHandle.hash);
+ snprintf(handleStr, 21, "0x%08X 0x%08X", comp.entHandle.bucketIndex, comp.entHandle.itemIndex);
stream << PKE_FILE_INSTANCE_ENTITY_HANDLE << handleStr << std::endl;
}
if (comp.entHandle != c.entHandle) {
- snprintf(handleStr, 19, "0x%016lX", comp.instanceHandle.hash);
+ snprintf(handleStr, 21, "0x%08X 0x%08X", comp.instanceHandle.bucketIndex, comp.instanceHandle.itemIndex);
stream << PKE_FILE_INSTANCE_HANDLE << handleStr << std::endl;
}
if (et != nullptr) {
- stream << PKE_FILE_INSTANCE_ENTITY_TYPE_CODE << et->entityTypeCode << std::endl;
+ stream << PKE_FILE_INSTANCE_ENTITY_TYPE_CODE << et->entityTypeCode.val << std::endl;
} else if (PkeCamera_Get(comp.entHandle)) {
stream << PKE_FILE_INSTANCE_ENTITY_TYPE_CODE << PKE_FILE_INSTANCE_SPECIAL_ENTITY_TYPE_CODE_CAMERA << std::endl;
}
@@ -217,15 +217,21 @@ void ParseCamera(PkeLevel *level, std::ifstream &stream) {
}
if (strstr(readLine, PKE_FILE_CAMERA_INSTANCE_HANDLE)) {
uint64_t prefixLen = strlen(PKE_FILE_CAMERA_INSTANCE_HANDLE);
- STR2NUM_ERROR result = str2num(instanceHandle.hash, readLine + prefixLen);
- assert(result == STR2NUM_ERROR::SUCCESS);
+ readLine[prefixLen + 10] = '\0';
+ STR2NUM_ERROR result1 = str2num(instanceHandle.bucketIndex, readLine + prefixLen);
+ STR2NUM_ERROR result2 = str2num(instanceHandle.itemIndex, readLine + prefixLen + 11);
+ assert(result1 == STR2NUM_ERROR::SUCCESS);
+ assert(result2 == STR2NUM_ERROR::SUCCESS);
// TODO add to global list
continue;
}
if (strstr(readLine, PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE)) {
uint64_t prefixLen = strlen(PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE);
- STR2NUM_ERROR result = str2num(targetInstanceHandle.hash, readLine + prefixLen);
- assert(result == STR2NUM_ERROR::SUCCESS);
+ readLine[prefixLen + 10] = '\0';
+ STR2NUM_ERROR result1 = str2num(targetInstanceHandle.bucketIndex, readLine + prefixLen);
+ STR2NUM_ERROR result2 = str2num(targetInstanceHandle.itemIndex, readLine + prefixLen + 11);
+ assert(result1 == STR2NUM_ERROR::SUCCESS);
+ assert(result2 == STR2NUM_ERROR::SUCCESS);
// TODO find and set
continue;
}
@@ -293,14 +299,20 @@ void ParseInstance(Entity_Base *parentEntity, std::ifstream &stream) {
}
if (strstr(readLine, PKE_FILE_INSTANCE_ENTITY_HANDLE)) {
uint64_t prefixLen = strlen(PKE_FILE_INSTANCE_ENTITY_HANDLE);
- STR2NUM_ERROR result = str2num(comp.entHandle.hash, readLine + prefixLen);
- assert(result == STR2NUM_ERROR::SUCCESS);
+ readLine[prefixLen + 10] = '\0';
+ STR2NUM_ERROR result1 = str2num(comp.entHandle.bucketIndex, readLine + prefixLen);
+ STR2NUM_ERROR result2 = str2num(comp.entHandle.itemIndex, readLine + prefixLen + 11);
+ assert(result1 == STR2NUM_ERROR::SUCCESS);
+ assert(result2 == STR2NUM_ERROR::SUCCESS);
continue;
}
if (strstr(readLine, PKE_FILE_INSTANCE_HANDLE)) {
uint64_t prefixLen = strlen(PKE_FILE_INSTANCE_HANDLE);
- STR2NUM_ERROR result = str2num(mapping.origHandle.hash, readLine + prefixLen);
- assert(result == STR2NUM_ERROR::SUCCESS);
+ readLine[prefixLen + 10] = '\0';
+ STR2NUM_ERROR result1 = str2num(mapping.origHandle.bucketIndex, readLine + prefixLen);
+ STR2NUM_ERROR result2 = str2num(mapping.origHandle.itemIndex, readLine + prefixLen + 11);
+ assert(result1 == STR2NUM_ERROR::SUCCESS);
+ assert(result2 == STR2NUM_ERROR::SUCCESS);
continue;
}
if (strstr(readLine, PKE_FILE_INSTANCE_ENTITY_TYPE_CODE)) {
@@ -519,7 +531,7 @@ void Game_RecordImGui() {
}
void Game_Tick(double delta) {
- Pke_ResetBucket(pkeSettings.mem.bkt);
+ pk_bucket_reset(pkeSettings.mem.bkt);
// TODO this should be removed in favor of storing the scene details inside a level definition
if (pkeSettings.rt.shouldLoadScene && pkeSettings.rt.sceneName) {
@@ -673,7 +685,7 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
}
fprintf(stdout, "Game_Main SHUTDOWN INITIATED\n");
#ifndef NDEBUG
- Pke_DebugPrint();
+ pk_memory_debug_print();
#endif
const auto pluginCount = LoadedPkePlugins.Count();
for (long i = 0; i < pluginCount; ++i) {
@@ -692,12 +704,12 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
AM_DebugPrint();
AM_Teardown();
PkeThreads_Teardown();
- Pke_DebugPrint();
+ pk_memory_debug_print();
fprintf(stdout, "Game_Main Exiting\n");
}
void Game_Init() {
- pkeSettings.mem.bkt = Pke_BeginTransientBucket(1UL << 26);
+ pkeSettings.mem.bkt = pk_bucket_create("game", 1UL << 26, true);
for (long i = 0; i < consoleBufferCount; ++i) {
memset(consoleBuffer[i], '\0', consoleLineLength);