Probably should have given more info on that number before throwing it out there 😅. I’ll have a look and show what my struct looks like and how many entities were active (hopefully today or tomorrow). This 3gb was in a worst case scenario where I shot a lot of arrows, each one with a physics body which had a lot of data aswell because of static arrays.
Nirion on handmade.network I believe uses the flat struct approach.
EDIT:
Looking at it now, it's probably a memory bug in something else, it seems like too much memory is being allocated :( from something else.
This is my sizes
sizeof(Entity) = 512
sizeof(EasyRigidBody) = 100
sizeof(EasyCollider) = 88
This is what my Entity struct looks like
struct Entity {
EntityType type;
u64 flags;
EntityDirection direction;
//NOTE: This is for the redo undo system, and to save entities that shouldn't be deleted like the sword and shield
bool isDeleted;
//NOTE: If the entity is flipped on the x-Axis
bool isFlipped;
bool isDead;
bool isSwimming;
bool isFalling; //For player falling through the floor
float animationRate;
EntityEnemyType enemyType;
//FOr empty triggers that do stuff
EntityTriggerType triggerType;
char *levelToLoad; //for triggers that load levels
//Location Sound type to retrieve string
EntityLocationSoundType locationSoundType;
///NOTE: CHest information
bool chestIsOpen;
ChestType chestType;
/////
//NOTE: For things that are have a switch that gets turns on and stay on. Using for a door when you exit it it closes.
bool isActivated;
//For entity creator
float rateOfCreation;
float timeSinceLastCreation;
EntityType typeToCreate;
/////////////////////////////
int subEntityType;
//NOTE: If no animation, use this sprite
Texture *sprite;
V4 colorTint;
EasyTransform T;
EasyAnimation_Controller animationController;
//For the ai stuff
EasyAiController *aiController;
V3 lastSetPos; //the position the A* path find is travelling to
V3 beginSetPos;
float travelTimer; //timer to lerp between A* positions
V3 lastGoalPos;
///
//NOTE: For loading to other scenes through a door
int partnerId;
V2 moveDirection;
//////////////////////
EasyRigidBody *rb;
EasyCollider *collider;
//Four colliders for the rock
EasyCollider *collider1;
EasyCollider *collider2;
EasyCollider *collider3;
EasyCollider *collider4;
bool shieldInUse;
bool staminaMaxedOut;
float flashHurtTimer;
int animationIndexOn; //for ai state machines
float layer; //NOTE: zero for infront, +ve for more behind
//////////////// Different entity sub types ////////////////
float lifeSpanLeft;
float maxLifeSpan;
bool isDying;
int health;
int maxHealth;
bool wearingGloves;
/////
int footstepAt;
float footStepTimer;
//////////////////
float lightIntensity;
V3 lightColor;
float innerRadius;
float outerRadius;
bool renderFirstPass; //Render before entities like terrain so the doesn't affect the depth buffer ordering
PlayingSound *currentSound;
//NOTE: For the button that needs to know things are on top of it
int refCount;
//Player stamina
float stamina;
float maxStamina;
float staminaTimer;
//For NPCs and signs
DialogInfoType dialogType;
//For key prompts
float tBob;
EasyModel *model;
float rotation;
float healthBarTimer;
//For the audio checklist
char *audioFile;
//For the push block
float moveTimer;
V3 startMovePos;
V3 endMovePos;
////////////////////
int particleSystemIndexToEndOnDelete;
float enemyMoveSpeed;
} ;
This is the rigid body
struct EasyRigidBody {
int arrayIndex;
V3 dP;
V3 accumForce; //perFrame
V3 accumForceOnce; //Gets cleared after one phsyics click
V3 accumTorque;
V3 accumTorqueOnce;
union {
struct { //2d
float inverse_I;
};
struct { //3d
V3 dA;
// Matrix4 inverse_I;
};
};
float inverseWeight;
float reboundFactor;
float dragFactor;
float gravityFactor;
bool updated;
bool hasRigidCollider;
u32 isGrounded; //flag where grounded is 1 << 0 & done this frame is 1 << 1
};
This is the collider
struct EasyCollider {
int arrayIndex;
EasyTransform *T;
EasyRigidBody *rb;
EasyColliderType type;
V3 offset;
bool isActive;
bool isTrigger;
EasyCollisionLayer layer;
InfiniteAlloc collisions;
bool canCollide; //this is since rigid bodies have to have a collider to update their position
union {
struct {
float radius;
};
struct {
float capsuleRadius;
float capsuleLength;
};
struct {
V3 dim3f;
};
struct {
V2 dim2f;
};
};
};