summaryrefslogtreecommitdiff
path: root/src/resources/include/engine/resources.h
blob: e151d7e61fb321e9e06393a0dc64f13c8017d87c (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef ENGINE_RESOURCES_H
#define ENGINE_RESOURCES_H

#include <engine/core/types.h>
#include <engine/rendering/rendering.h>

// TODO
/* We need some "global resources", available to all states.
 * These are resources such as common fonts, GUI frames, button background
 * images.
 *
 * We need to define state-specific resources as well.
 * - Can both be defined alike?
 *   If we lazy-load all resources we can get away with a lot.
 *   Maybe use fall-back resources? like the missing source texture, and an ugly
 *   font?
 * - Then declare to the engine, in the main function for the game, that these
 *   resources are to be made available throughout?
 * - Make all resource specifications A UNION?! 🤯
 * */

enum Asset {
  Asset_error,
  Asset_font,
  Asset_texture,
  Asset_audio,
};

typedef struct {
  enum Asset type;
  const char* font_path;
  i32 ptsize;
} Asset_FontSpec;

typedef struct {
  enum Asset type;
  const char* path;
  i32 width;
  i32 height;
} Asset_TextureSpec;

typedef struct {
  enum Asset type;
  const char* path;
} Asset_AudioSpec;

typedef union {
  enum Asset type;
  Asset_FontSpec font;
  Asset_TextureSpec texture;
  Asset_AudioSpec audio;
} asset_t;

// The resource spec
typedef struct {
  // Was:
//  usize textures_len;
//  usize textures_size;
//  usize fonts_len;
//
//  usize texturepaths_len;
//  usize fontpaths_len;
//
//  /* Paths for our sources, kept in case the user wants to reload them */
//  Asset_TextureSpec** texture_paths;
//  Asset_FontSpec** font_paths;
//
//  /* Our actual sources */
//  Texture** textures;
//  //TTF_Font** fonts;

  // But with the new way:
  // usize assets_len;
  // asset_t assets*;
  Shader* shaders;
  usize shaders_len;
} Resources;

#define Resource_FontDefinition(_path, _fontsize)                              \
  (const Asset_FontSpec) {                                                     \
    .type = Asset_font, .font_path = _path, .ptsize = _fontsize                \
  }

#define Resource_TextureAtlasDefinition(_path, _subtexture_width,              \
                                        _subtexture_height)                    \
  (const Asset_TextureSpec) {                                                  \
    .type = Asset_texture, .width = _subtexture_width,                         \
    .height = _subtexture_height, .path = _path                                \
  }

#define TextureDefinition(_path, ...) unimplemented

#define Resource_AudioDefinition(_path, ...) unimplemented

/* Each of resource_load_font, resource_load_texture, and resource_load_audio
 * loads a given resource into the engines memory and returns an identifier.
 */
isize resource_load_font(Asset_FontSpec font_def);
isize resource_load_texture(Asset_TextureSpec texture_def);
isize resource_load_audio(Asset_AudioSpec audio_def);

/* Makes a resource globally available. This must be called **BEFORE** any call
 * to `engine_run` */
isize resource_make_global(isize resource_id);

#include <engine/resources/texture.h>

#endif