aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene_memory.h
blob: d175cba69cc563ace3fc058b485a62aeebdf1e36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// Memory management of scene objects.
#pragma once

#include "types.h"

/// Initialize scene memory.
///
/// The scene memory guarantees that every object maps to an index different
/// than 0. This way, 0 can be used as a special index to denote "no value".
void scene_mem_init();

/// Destroy the scene memory and all allocated objects.
void scene_mem_destroy();

#define NAMED_INDEX(name) name##_idx

#define DECL_MEMORY(name, type)                \
  typedef struct type type;                    \
  /* xyz* mem_alloc_xyz() */                   \
  type* mem_alloc_##name();                    \
  /* mem_free_xyz(xyz**) */                    \
  void mem_free_##name(type**);                \
  /* xyz* mem_get_xyz(xyz_idx); */             \
  type* mem_get_##name(NAMED_INDEX(name));     \
  /* xyz_idx mem_get_xyz_index(const xyz*); */ \
  NAMED_INDEX(name) mem_get_##name##_index(const type*);

DECL_MEMORY(anima, Anima)
DECL_MEMORY(animation, Animation)
DECL_MEMORY(camera, SceneCamera)
DECL_MEMORY(light, Light)
DECL_MEMORY(material, Material)
DECL_MEMORY(mesh, Mesh)
DECL_MEMORY(mesh_link, MeshLink)
DECL_MEMORY(model, Model)
DECL_MEMORY(node, SceneNode)
DECL_MEMORY(object, SceneObject)
DECL_MEMORY(scene, Scene)
DECL_MEMORY(skeleton, Skeleton)