Subastra
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1#ifndef __H__SETUP_CLIENT__
2#define __H__SETUP_CLIENT__
3
4#include "../engine/world.h"
5
6#include "../engine/input.h"
7#include "../memory.h"
8#include "../misc.h"
9#include "../rendering/context.h"
10#include "../rendering/image.h"
11#include "../rendering/quads.h"
12#include "../rendering/shader.h"
13#include "../systems/camera.h"
14#include "../systems/construct.h"
15#include "../systems/input.h"
16#include "../systems/physics.h"
17#include "../systems/require.h"
18#include "../systems/scheduler.h"
19
24
34
36 sz file_size;
37 void *file_buffer =
38 read_binary_file(data->alloc, "./assets/tileset.png", &file_size);
39
40 image_init(&data->assets.tileset_image, data->alloc, file_buffer, file_size);
41 allocator_free(data->alloc, file_buffer);
43
44 char *vertex_source = read_text_file(data->alloc, "./assets/tileset.vert");
45 char *fragment_source = read_text_file(data->alloc, "./assets/tileset.frag");
46
47 shader_init(&data->assets.tileset_shader, vertex_source, fragment_source);
48}
49
50static void client_data_init(client_data_t *data, allocator_t alloc) {
51 names_init();
52
53 data->alloc = alloc;
54
55 world_init(&data->world);
56
60
61 input_init(&data->input);
62
64
66}
67
69 scheduler_declare_system(&data->scheduler, ENTITY_KIND_CONSTRUCT,
70 ENTITY_KIND_CONSTRUCT, integrate_velocity,
72 {
73 .phase = SYSTEM_PHASE_POST_UPDATE,
74 .world = (world_t *)1,
75 });
76
77 scheduler_declare_system(&data->scheduler, ENTITY_KIND_CONSTRUCT,
78 ENTITY_KIND_CONSTRUCT, tick_thrusters,
80 {
81 .phase = SYSTEM_PHASE_PRE_RENDER,
82 .world = (world_t *)1,
83 });
84}
85
87 scheduler_declare_system(&data->scheduler, ENTITY_KIND_CAMERA,
88 ENTITY_KIND_MASK_EMPTY, camera_move,
90 {
91 .phase = SYSTEM_PHASE_PRE_RENDER,
92 .world = (world_t *)1,
93 .input = (input_t *)1,
94 });
95
96 name_t deps_proj[] = {system_camera_move_name};
97 scheduler_declare_system(
99 camera_set_projection, deps_proj, 1,
100 {
101 .phase = SYSTEM_PHASE_PRE_RENDER,
102 .system_specific_data = &data->assets.tileset_shader,
103 .world = (world_t *)1,
104 .input = (input_t *)1,
105 .rendering_ctx = (rendering_ctx_t *)1,
106 });
107
108 render_constructs_data_t *render_constructs_data = allocator_alloc_ty(
110
111 render_constructs_data->image = &data->assets.tileset_image;
112 render_constructs_data->program = data->assets.tileset_shader.gl_program;
113 render_constructs_data->vao = _gl_quad_vao;
114
115 name_t deps_render_constructs[] = {system_camera_move_name};
116 scheduler_declare_system(&data->scheduler, ENTITY_KIND_CONSTRUCT,
117 ENTITY_KIND_MASK_EMPTY, render_constructs,
118 deps_render_constructs, 1,
119 {
120 .phase = SYSTEM_PHASE_RENDER,
121 .system_specific_data = render_constructs_data,
122 .world = (world_t *)1,
123 .input = (input_t *)1,
124 .rendering_ctx = (rendering_ctx_t *)1,
125 });
126
127 scheduler_declare_system(&data->scheduler, ENTITY_KIND_MASK_EMPTY,
128 ENTITY_KIND_MASK_EMPTY, process_input,
130 {
131 .phase = SYSTEM_PHASE_PRE_UPDATE,
132 .input = (input_t *)1,
133 .rendering_ctx = (rendering_ctx_t *)1,
134 });
135}
136
139 reqs.input = &data->input;
140 reqs.rendering_ctx = &data->rendering_ctx;
141 reqs.world = &data->world;
143
146
147 FILE *f = fopen("./schedule.tmp.graphviz", "w+");
150 fclose(f);
151}
152
153#endif
static void client_schedule_systems(client_data_t *data)
Definition client.h:137
static void client_data__load_assets(client_data_t *data)
Definition client.h:35
static void client__schedule_physics(client_data_t *data)
Definition client.h:68
static void client_data_init(client_data_t *data, allocator_t alloc)
Definition client.h:50
static void client__schedule_rendering(client_data_t *data)
Definition client.h:86
static void rendering_ctx_show_window(rendering_ctx_t *ctx)
Definition context.h:51
static void rendering_ctx_init(rendering_ctx_t *ctx)
Definition context.h:30
size_t sz
Definition defs.h:51
static void input_init(input_t *input)
Definition input.h:14
@ ENTITY_KIND_CONSTRUCT
Definition entity.h:37
@ ENTITY_KIND_MASK_EMPTY
Definition entity.h:35
@ ENTITY_KIND_CAMERA
Definition entity.h:38
static void image_bind(image_t *image)
Definition image.h:51
static void * read_binary_file(allocator_t allocator, const char *filename, sz *size)
Read a binary file file of into memory.
Definition misc.h:9
static char * read_text_file(allocator_t allocator, const char *filename)
Definition misc.h:28
static void names_init()
Definition names.h:21
u64 name_t
Definition names.h:14
static GLuint _gl_quad_vao
Definition quads.h:6
static void gl_quad_init()
Definition quads.h:8
static system_req_t system_req_new()
Definition require.h:71
#define SYSTEM_REQ_NO_DEPS
Definition require.h:49
static void scheduler_dump_dependency_graph(scheduler_t *scheduler, FILE *out)
Definition scheduler.h:96
@ SCHEDULER_STRATEGY_RANDOM
Definition scheduler.h:14
static void scheduler_set_requirements(scheduler_t *scheduler, system_req_t reqs)
Definition scheduler.h:191
static scheduler_t scheduler_new(scheduler_strategy_t strategy, allocator_t persistent_allocator, allocator_t temporary_allocator)
Definition scheduler.h:36
static void scheduler_plan(scheduler_t *scheduler)
Definition scheduler.h:184
A generic allocator type passed by value. Contains a fallback allocator and a set of function pointer...
Definition memory.h:30
Definition client.h:25
world_t world
Definition client.h:27
scheduler_t scheduler
Definition client.h:30
input_t input
Definition client.h:29
allocator_t alloc
Definition client.h:26
rendering_ctx_t rendering_ctx
Definition client.h:28
global_assets_t assets
Definition client.h:32
Definition client.h:20
image_t tileset_image
Definition client.h:22
shader_t tileset_shader
Definition client.h:21
The raw data of an image.
Definition image.h:10
Definition input.h:10
Definition construct.h:11
GLuint program
Definition construct.h:12
GLuint vao
Definition construct.h:13
image_t * image
Definition construct.h:14
Definition context.h:11
Definition scheduler.h:22
allocator_t persistent_allocator
Definition scheduler.h:23
Small container and wrapper over OpenGL for shader-related things. In actually it is closer to what O...
Definition shader.h:15
GLuint gl_program
Definition shader.h:16
Definition require.h:51
input_t * input
Definition require.h:62
rendering_ctx_t * rendering_ctx
Definition require.h:63
world_t * world
Definition require.h:61
Definition world.h:12
static void world_init(world_t *world)
Definition world.h:18