dev-blog

Let’s break down how to construct a data model for system elements in a procedural programming style. I’ll focus on principles, steps, and concrete rules you can follow, keeping everything aligned with the procedural mindset.


1️⃣ Identify the Core Entities (Structs)

In procedural programming, data lives in simple containers (structs in C, records in Pascal, etc.).

Rules:

Example: Game Element

typedef struct {
    int id;
    float x, y;
    float width, height;
    int health;
} GameObject;

2️⃣ Define Separate Functions to Operate on Data

Example: Movement Function

GameObject MoveObject(GameObject obj, float dx, float dy){
    obj.x += dx;
    obj.y += dy;
    return obj;
}

Example: Damage Function

GameObject ApplyDamage(GameObject obj, int dmg){
    obj.health -= dmg;
    if(obj.health < 0) obj.health = 0;
    return obj;
}

3️⃣ Use IDs for References Instead of Pointers (Optional)

If entities need to reference each other:

typedef struct {
    int id;
    int targetId; // points to another GameObject
} Missile;

4️⃣ Keep Data Normalized

Example: Position and Velocity as Separate Structs

typedef struct { float x, y; } v2;
typedef struct { v2 pos; v2 vel; float mass; } Physics;
typedef struct { int id; Physics physics; int health; } Entity;

5️⃣ Design for Explicit Updates

for(int i = 0; i < entityCount; i++){
    entities[i] = SimulateEntity(entities[i], dt);
}

6️⃣ Keep Data Simple, Functions Composable


Procedural Data Modeling Checklist

  1. Structs contain only data.
  2. Functions take structs as input, return modified structs or explicitly mutate.
  3. Use IDs or indices for references, not hidden pointers.
  4. Keep data normalized; avoid duplication.
  5. Systems operate over arrays/lists of structs.
  6. Functions are small, testable, deterministic.
  7. Avoid hidden state; all dependencies are explicit.

If you want, I can make a ready-to-use template for a procedural-style system element with multiple components (physics, graphics, AI) that follows all these rules. It would be like a “starter kit” for your procedural engine.

Do you want me to do that?