├── .gitignore
├── etc
├── city.wasm
├── img
│ └── flecs_logo.png
├── sokol
│ └── shaders
│ │ ├── constants.glsl
│ │ ├── fx_fog_header.glsl
│ │ ├── fx_ssao_blend.glsl
│ │ ├── fx_hdr.glsl
│ │ ├── fx_hdr_threshold.glsl
│ │ ├── scene_vert.glsl
│ │ ├── fx_ssao_main.glsl
│ │ ├── scene_atmos_sun.frag
│ │ ├── fx_fog_main.glsl
│ │ ├── fx_hdr_blur.glsl
│ │ ├── common.glsl
│ │ ├── atmosphere_frag.glsl
│ │ ├── fx_ssao_header.glsl
│ │ ├── atmosphere.glsl
│ │ └── scene_frag.glsl
├── assets
│ ├── scene.flecs
│ ├── app.flecs
│ └── city.flecs
└── index.html
├── .gitattributes
├── deps
├── flecs_systems_sokol.c
├── flecs_systems_sokol_objc.m
├── flecs_components_cglm.c
├── flecs_components_physics.c
├── flecs_components_gui.c
├── dependee.json
├── flecs_components_cglm.h
├── flecs_components_geometry.c
├── flecs_systems_transform.h
├── flecs_components_transform.c
├── flecs_systems_sokol.h
├── flecs_components_graphics.c
├── flecs_game.h
├── flecs_components_physics.h
├── flecs_components_geometry.h
├── flecs_components_gui.h
├── flecs_systems_transform.c
├── flecs_components_transform.h
├── flecs_systems_physics.h
├── flecs_components_graphics.h
├── flecs_components_input.c
├── flecs_components_input.h
├── flecs_systems_physics.c
└── flecs_game.c
├── project.json
├── include
├── city
│ ├── game.h
│ └── bake_config.h
└── city.h
├── README.md
├── LICENSE
└── src
├── main.c
└── module.c
/.gitignore:
--------------------------------------------------------------------------------
1 | .bake_cache
2 | .DS_Store
3 | .vscode
4 | gcov
5 | bin
6 |
--------------------------------------------------------------------------------
/etc/city.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flecs-hub/city/HEAD/etc/city.wasm
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/etc/img/flecs_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flecs-hub/city/HEAD/etc/img/flecs_logo.png
--------------------------------------------------------------------------------
/deps/flecs_systems_sokol.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flecs-hub/city/HEAD/deps/flecs_systems_sokol.c
--------------------------------------------------------------------------------
/deps/flecs_systems_sokol_objc.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flecs-hub/city/HEAD/deps/flecs_systems_sokol_objc.m
--------------------------------------------------------------------------------
/etc/sokol/shaders/constants.glsl:
--------------------------------------------------------------------------------
1 | #define PI 3.1415926535897932384626433832795
2 | #define PI2 (2.0 * PI)
3 | #define EPSILON 1e-6f
4 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_fog_header.glsl:
--------------------------------------------------------------------------------
1 | #include "etc/sokol/shaders/common.glsl"
2 | #include "etc/sokol/shaders/atmosphere.glsl"
3 |
4 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_ssao_blend.glsl:
--------------------------------------------------------------------------------
1 | float ambientOcclusion = rgba_to_float(texture(t_occlusion, uv));
2 | frag_color = (1.0 - ambientOcclusion) * texture(t_scene, uv);
3 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_hdr.glsl:
--------------------------------------------------------------------------------
1 |
2 | vec3 c = texture(hdr, uv).rgb;
3 | vec3 b = texture(bloom, uv).rgb;
4 | float b_clip = dot(vec3(0.333), b);
5 | b = b + pow(b_clip, 3.0);
6 | c = c + b;
7 | c = pow(c, vec3(1.0 / gamma));
8 | frag_color = vec4(c, 1.0);
9 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_hdr_threshold.glsl:
--------------------------------------------------------------------------------
1 |
2 | const vec3 channel_lum = vec3(0.299, 0.587, 0.114);
3 | const float lmax = 0.2 / dot(vec3(1.0, 1.0, 1.0), channel_lum);
4 |
5 | vec4 c = texture(hdr, uv, mipmap);
6 | float l = dot(c.rgb, channel_lum);
7 | l = l * lmax;
8 | frag_color = c * l;
9 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/scene_vert.glsl:
--------------------------------------------------------------------------------
1 | out vec4 position;
2 | out vec4 light_position;
3 | out vec3 normal;
4 | out vec4 color;
5 | out vec3 material;
6 |
7 | void main() {
8 | vec4 pos4 = vec4(v_position, 1.0);
9 | gl_Position = u_mat_vp * i_mat_m * pos4;
10 | light_position = u_light_vp * i_mat_m * pos4;
11 | position = (i_mat_m * pos4);
12 | normal = (i_mat_m * vec4(v_normal, 0.0)).xyz;
13 | color = vec4(i_color, 0.0);
14 | material = i_material;
15 | }
16 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_ssao_main.glsl:
--------------------------------------------------------------------------------
1 | // Depth (range = 0 .. u_far)
2 | float centerDepth = getDepth( uv );
3 |
4 | // Depth (range = 0 .. 1)
5 | float centerDepthNorm = centerDepth / u_far;
6 | float centerViewZ = getViewZ( centerDepth );
7 | vec3 viewPosition = getViewPosition( uv, centerDepthNorm, centerViewZ );
8 | float ambientOcclusion = getAmbientOcclusion( viewPosition, centerDepth );
9 |
10 | // Store value as rgba to increase precision
11 | float max_dist = 0.1;
12 | float mult = 1.0 / max_dist;
13 | frag_color = float_to_rgba(ambientOcclusion) * max(0.0, max_dist - centerDepthNorm) * mult;
14 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/scene_atmos_sun.frag:
--------------------------------------------------------------------------------
1 | uniform sampler2D atmos;
2 | uniform vec3 u_sun_screen_pos;
3 | uniform vec3 u_sun_color;
4 | uniform float u_aspect;
5 | uniform float u_sun_intensity;
6 |
7 | in vec2 uv;
8 | out vec4 frag_color;
9 |
10 | void main() {
11 | vec2 sun_dist = uv.xy - u_sun_screen_pos.xy;
12 | sun_dist.x *= u_aspect;
13 |
14 | float sun_dist_len = length(sun_dist);
15 | float intensity = u_sun_intensity * float(u_sun_screen_pos.z >= 0.0);
16 | vec3 sunDisc = intensity * u_sun_color * ((sun_dist_len < 0.025) ? 1.0 : 0.0);
17 |
18 | frag_color = texture(atmos, uv) + vec4(sunDisc, 1.0);
19 | }
20 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_fog_main.glsl:
--------------------------------------------------------------------------------
1 | #define LOG2 1.442695
2 |
3 | const float transition = 0.025;
4 | const float inv_transition = 1.0 / transition;
5 | const float sample_height = 0.01;
6 |
7 | vec4 c = texture(hdr, uv);
8 | float d = (rgba_to_depth(texture(depth, uv)) / u_far);
9 | vec4 fog_color = texture(atmos, vec2(uv.x, u_horizon + sample_height));
10 | float intensity;
11 | if (d > 1.0) {
12 | intensity = (max((u_horizon + transition) - uv.y, 0.0) * inv_transition);
13 | intensity = min(intensity, 1.0);
14 | } else {
15 | intensity = 1.0 - exp2(-(d * d) * u_density * u_density * LOG2);
16 | }
17 | frag_color = mix(c, fog_color, intensity);
18 |
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "city",
3 | "type": "application",
4 | "value": {
5 | "use": [
6 | "flecs",
7 | "flecs.components.transform",
8 | "flecs.components.graphics",
9 | "flecs.components.geometry",
10 | "flecs.components.physics",
11 | "flecs.components.gui",
12 | "flecs.systems.physics",
13 | "flecs.systems.transform",
14 | "flecs.systems.sokol",
15 | "flecs.game"
16 | ],
17 | "standalone": true
18 | },
19 | "lang.c": {
20 | "${target em}": {
21 | "ldflags": ["-sSTACK_SIZE=1000000", "-Wl,-u,ntohs"],
22 | "embed": ["etc/assets"]
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/include/city/game.h:
--------------------------------------------------------------------------------
1 | #ifndef FLECS_CITY_H
2 | #define FLECS_CITY_H
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | ECS_STRUCT(CityBlock, {
9 | float x;
10 | float y;
11 | ecs_entity_t city;
12 | int16_t size;
13 | int16_t building_size;
14 | int16_t building_height;
15 | float park_chance;
16 | float tree_chance;
17 | });
18 |
19 | ECS_STRUCT(City, {
20 | int16_t blocks_x;
21 | int16_t blocks_y;
22 | int16_t block_size;
23 | int16_t road_width;
24 | int16_t building_size;
25 | int16_t min_building_height;
26 | int16_t max_building_height;
27 | float park_chance;
28 | float tree_chance;
29 | });
30 |
31 | void FlecsCityImport(
32 | ecs_world_t *world);
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_hdr_blur.glsl:
--------------------------------------------------------------------------------
1 | const float gauss[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
2 |
3 | float offset = 0.0;
4 | vec4 result = gauss[0] * texture(tex, vec2(uv.x, uv.y));
5 | ivec2 ts = textureSize(tex, 0);
6 | float px = 1.0 / float(ts.x);
7 | float py = 1.0 / float(ts.y);
8 | if (horizontal == 0.0) {
9 | for (int i = 1; i < 5; i ++) {
10 | offset += px / u_aspect;
11 | result += gauss[i] * texture(tex, vec2(uv.x + offset, uv.y));
12 | result += gauss[i] * texture(tex, vec2(uv.x - offset, uv.y));
13 | }
14 | } else {
15 | for (int i = 1; i < 5; i ++) {
16 | offset += py;
17 | result += gauss[i] * texture(tex, vec2(uv.x, uv.y + offset));
18 | result += gauss[i] * texture(tex, vec2(uv.x, uv.y - offset));
19 | }
20 | }
21 |
22 | frag_color = result;
23 |
--------------------------------------------------------------------------------
/deps/flecs_components_cglm.c:
--------------------------------------------------------------------------------
1 | #include "flecs_components_cglm.h"
2 |
3 | ECS_COMPONENT_DECLARE(vec3);
4 | ECS_COMPONENT_DECLARE(vec4);
5 |
6 | void FlecsComponentsCglmImport(
7 | ecs_world_t *world)
8 | {
9 | ECS_MODULE(world, FlecsComponentsCglm);
10 |
11 | ecs_id(vec3) = ecs_array(world, {
12 | .entity = ecs_entity(world, {
13 | .name = "vec3",
14 | .symbol = "vec3",
15 | .id = ecs_id(vec3)
16 | }),
17 | .type = ecs_id(ecs_f32_t),
18 | .count = 3
19 | });
20 |
21 | ecs_id(vec4) = ecs_array(world, {
22 | .entity = ecs_entity(world, {
23 | .name = "vec4",
24 | .symbol = "vec4",
25 | .id = ecs_id(vec4)
26 | }),
27 | .type = ecs_id(ecs_f32_t),
28 | .count = 4
29 | });
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # city
2 | Simple procedural city generator. Standalone Flecs project with embedded graphics modules ([live webasm demo](https://flecs.dev/city))
3 |
4 |
5 |
6 | ## How to run
7 | Use the following commands to run the demo:
8 |
9 | Install bake on macOS/Linux:
10 | ```
11 | git clone https://github.com/SanderMertens/bake
12 | bake/setup.sh
13 | ```
14 |
15 | Install bake on Windows
16 | ```
17 | git clone https://github.com/SanderMertens/bake
18 | cd bake
19 | setup
20 | ```
21 |
22 | or if you already have a bake installation:
23 | ```
24 | bake upgrade
25 | ```
26 |
27 | Then run:
28 | ```
29 | bake run flecs-hub/city
30 | ```
31 |
32 | Have fun!
33 |
34 | ## How to use
35 | To customize the city generation parameters, change the settings in the etc/assets/scene.plecs file.
36 |
--------------------------------------------------------------------------------
/etc/assets/scene.flecs:
--------------------------------------------------------------------------------
1 | using flecs.components.*
2 | using flecs.city
3 | using flecs.game
4 |
5 | city {
6 | City: {
7 | blocks_x: 25
8 | blocks_y: 18
9 | block_width: 15
10 | block_height: 25
11 | road_width: 6
12 |
13 | buildings: {
14 | min_height: 3
15 | max_height: 160
16 | x_variation: 0.5
17 | y_variation: 2.0
18 | small_height: 50
19 |
20 | modern_chance: 0.3
21 | skyscraper_chance: 0.2
22 | backyard_chance: 1.0
23 | }
24 |
25 | parks: {
26 | chance: 0.3,
27 | tree_chance: 0.6
28 | plaza_chance: 0.1
29 | tree_count: 4
30 | }
31 |
32 | props: {
33 | chance: 0.7
34 | tree_chance: 0.5
35 | bin_chance: 0.09
36 | hydrant_chance: 0.03
37 | bench_chance: 0.08
38 | }
39 |
40 | traffic: {
41 | frequency: 5
42 | speed: 10
43 | chance: 0.02
44 | }
45 |
46 | lanterns: true
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/etc/assets/app.flecs:
--------------------------------------------------------------------------------
1 | using flecs.components.*
2 | using flecs.game
3 |
4 | light {
5 | Sun
6 | Rotation3:{y: 0.5}
7 | }
8 |
9 | $ {
10 | TimeOfDay: {
11 | t: 0.8
12 | speed: 0.0005
13 | }
14 | }
15 |
16 | camera {
17 | CameraController
18 | Position3: {-115, 10.0, -287}
19 | Rotation3: {-0.15}
20 | Camera: {
21 | fov: 20
22 | up: [0, 1, 0]
23 | near_: 2
24 | far_: 1000
25 | }
26 | }
27 |
28 | canvas {
29 | Atmosphere: {
30 | night_color: {0.0001, 0.002, 0.004}
31 | }
32 | Canvas: {
33 | title: "Flecs City"
34 | width: 1200
35 | height: 900
36 | background_color: {0.3, 0.6, 0.9}
37 | ambient_light: {0.03, 0.06, 0.09}
38 | ambient_light_ground: {0.007, 0.00625, 0.00312}
39 | ambient_light_ground_falloff: 4.0
40 | directional_light: light
41 | camera: camera
42 | fog_density: 1.8
43 | shadow_far: 300
44 | }
45 | }
46 |
47 | ground_plane {
48 | Position3: {0, -1.0, 0}
49 | Box: {5000, 1.0, 5000}
50 | Rgb: {0.11, 0.15, 0.1}
51 | }
52 |
--------------------------------------------------------------------------------
/etc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Flecs city
4 |
5 |
6 |
7 |
8 |
9 | [
12 | Source
13 | ]
14 | [
17 | Open in Explorer
18 | ]
19 | -
20 | Use WASD + QE to move camera, arrow keys to look around
21 |
22 |
23 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Flecs Hub
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char *argv[]) {
4 | ecs_world_t *world = ecs_init();
5 |
6 | ECS_IMPORT(world, FlecsStats);
7 |
8 | ECS_IMPORT(world, FlecsUnits);
9 | ECS_IMPORT(world, FlecsScript);
10 | ECS_IMPORT(world, FlecsComponentsTransform);
11 | ECS_IMPORT(world, FlecsComponentsGeometry);
12 | ECS_IMPORT(world, FlecsComponentsGui);
13 | ECS_IMPORT(world, FlecsComponentsGraphics);
14 |
15 | ECS_IMPORT(world, FlecsGame);
16 | ECS_IMPORT(world, FlecsCity);
17 |
18 | ecs_time_t t = {0}; ecs_time_measure(&t);
19 | ecs_script_run_file(world, "etc/assets/scene.flecs");
20 | printf("scene loaded in %fs\n", ecs_time_measure(&t));
21 |
22 | /* Prewarm simulation so there's cars everywhere */
23 | for (int i = 0; i < 5000; i ++) {
24 | ecs_progress(world, 0.16);
25 | }
26 |
27 | ECS_IMPORT(world, FlecsSystemsTransform);
28 | ECS_IMPORT(world, FlecsSystemsSokol);
29 | ecs_script_run_file(world, "etc/assets/app.flecs");
30 |
31 | return ecs_app_run(world, &(ecs_app_desc_t){
32 | .enable_rest = true,
33 | .enable_stats = true,
34 | .target_fps = 60
35 | });
36 | }
37 |
--------------------------------------------------------------------------------
/include/city/bake_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | )
3 | (.)
4 | .|.
5 | | |
6 | _.--| |--._
7 | .-'; ;`-'& ; `&.
8 | \ & ; & &_/
9 | |"""---...---"""|
10 | \ | | | | | | | /
11 | `---.|.|.|.---'
12 |
13 | * This file is generated by bake.lang.c for your convenience. Headers of
14 | * dependencies will automatically show up in this file. Include bake_config.h
15 | * in your main project file. Do not edit! */
16 |
17 | #ifndef CITY_BAKE_CONFIG_H
18 | #define CITY_BAKE_CONFIG_H
19 |
20 | /* Headers of public dependencies */
21 | #include "../../deps/flecs.h"
22 | #include "../../deps/flecs_components_transform.h"
23 | #include "../../deps/flecs_components_graphics.h"
24 | #include "../../deps/flecs_components_geometry.h"
25 | #include "../../deps/flecs_components_physics.h"
26 | #include "../../deps/flecs_components_gui.h"
27 | #include "../../deps/flecs_systems_physics.h"
28 | #include "../../deps/flecs_systems_transform.h"
29 | #include "../../deps/flecs_systems_sokol.h"
30 | #include "../../deps/flecs_game.h"
31 |
32 | #endif
33 |
34 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/common.glsl:
--------------------------------------------------------------------------------
1 | #include "etc/sokol/shaders/constants.glsl"
2 |
3 | vec4 float_to_rgba(const in float v) {
4 | vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;
5 | enc = fract(enc);
6 | enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);
7 | return enc;
8 | }
9 |
10 | float rgba_to_float(const in vec4 rgba) {
11 | return dot(rgba, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
12 | }
13 |
14 | float pow2(const in float v) {
15 | return v * v;
16 | }
17 |
18 | #ifdef FX
19 | float rgba_to_depth(vec4 rgba) {
20 | float d = rgba_to_float(rgba);
21 | d *= log(0.05 * u_far + 1.0);
22 | d = exp(d);
23 | d -= 1.0;
24 | d /= 0.05;
25 | return d;
26 | }
27 | #endif
28 |
29 | float rgba_to_depth_log(vec4 rgba) {
30 | return rgba_to_float(rgba);
31 | }
32 |
33 | highp float rand( const in vec2 uv ) {
34 | const highp float a = 12.9898, b = 78.233, c = 43758.5453;
35 | highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
36 | return fract( sin( sn ) * c );
37 | }
38 |
39 | vec4 unpack_rgba(uint packedColor) {
40 | float r = float((packedColor >> 24) & 0xFFu) / 255.0;
41 | float g = float((packedColor >> 16) & 0xFFu) / 255.0;
42 | float b = float((packedColor >> 8) & 0xFFu) / 255.0;
43 | float a = float(packedColor & 0xFFu) / 255.0;
44 | return vec4(a, g, b, a);
45 | }
46 |
--------------------------------------------------------------------------------
/deps/flecs_components_physics.c:
--------------------------------------------------------------------------------
1 | #define FLECS_COMPONENTS_PHYSICS_IMPL
2 | #include "flecs_components_physics.h"
3 |
4 | ECS_DECLARE(EcsCollider);
5 | ECS_DECLARE(EcsRigidBody);
6 |
7 | void FlecsComponentsPhysicsImport(
8 | ecs_world_t *world)
9 | {
10 | ECS_MODULE(world, FlecsComponentsPhysics);
11 |
12 | ecs_set_name_prefix(world, "Ecs");
13 |
14 | ECS_TAG_DEFINE(world, EcsCollider);
15 | ECS_TAG_DEFINE(world, EcsRigidBody);
16 | ECS_META_COMPONENT(world, EcsVelocity2);
17 | ECS_META_COMPONENT(world, EcsVelocity3);
18 | ECS_META_COMPONENT(world, EcsAngularSpeed);
19 | ECS_META_COMPONENT(world, EcsAngularVelocity);
20 | ECS_META_COMPONENT(world, EcsBounciness);
21 | ECS_META_COMPONENT(world, EcsFriction);
22 |
23 | ecs_set_hooks(world, EcsVelocity2, {
24 | .ctor = flecs_default_ctor
25 | });
26 |
27 | ecs_set_hooks(world, EcsVelocity3, {
28 | .ctor = flecs_default_ctor
29 | });
30 |
31 | ecs_set_hooks(world, EcsAngularSpeed, {
32 | .ctor = flecs_default_ctor
33 | });
34 |
35 | ecs_set_hooks(world, EcsAngularVelocity, {
36 | .ctor = flecs_default_ctor
37 | });
38 |
39 | ecs_set_hooks(world, EcsBounciness, {
40 | .ctor = flecs_default_ctor
41 | });
42 |
43 | ecs_set_hooks(world, EcsFriction, {
44 | .ctor = flecs_default_ctor
45 | });
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/deps/flecs_components_gui.c:
--------------------------------------------------------------------------------
1 | #define FLECS_COMPONENTS_GUI_IMPL
2 |
3 | #include "flecs_components_gui.h"
4 |
5 | ECS_CTOR(EcsText, ptr, {
6 | ptr->value = NULL;
7 | })
8 |
9 | ECS_DTOR(EcsText, ptr, {
10 | ecs_os_free(ptr->value);
11 | ptr->value = NULL;
12 | })
13 |
14 | ECS_COPY(EcsText, dst, src, {
15 | ecs_os_free(dst->value);
16 | dst->value = ecs_os_strdup(src->value);
17 | })
18 |
19 | ECS_MOVE(EcsText, dst, src, {
20 | ecs_os_free(dst->value);
21 | dst->value = src->value;
22 | src->value = NULL;
23 | })
24 |
25 | ECS_CTOR(EcsCanvas, ptr, {
26 | ecs_os_zeromem(ptr);
27 | ptr->ambient_light_ground_intensity = 1.0;
28 | })
29 |
30 | void FlecsComponentsGuiImport(
31 | ecs_world_t *world)
32 | {
33 | ECS_MODULE(world, FlecsComponentsGui);
34 | ECS_IMPORT(world, FlecsComponentsGraphics);
35 | ECS_IMPORT(world, FlecsComponentsCglm);
36 |
37 | ecs_set_name_prefix(world, "Ecs");
38 |
39 | ECS_META_COMPONENT(world, EcsCanvas);
40 | ECS_META_COMPONENT(world, EcsText);
41 | ECS_META_COMPONENT(world, EcsFontSize);
42 | ECS_META_COMPONENT(world, EcsFontStyle);
43 | ECS_META_COMPONENT(world, EcsAlign);
44 | ECS_META_COMPONENT(world, EcsPadding);
45 |
46 | ecs_set_hooks(world, EcsCanvas, {
47 | .ctor = ecs_ctor(EcsCanvas),
48 | });
49 |
50 | ecs_set_hooks(world, EcsText, {
51 | .ctor = ecs_ctor(EcsText),
52 | .dtor = ecs_dtor(EcsText),
53 | .copy = ecs_copy(EcsText),
54 | .move = ecs_move(EcsText)
55 | });
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/include/city.h:
--------------------------------------------------------------------------------
1 | #ifndef CITY_H
2 | #define CITY_H
3 |
4 | /* This generated file contains includes for project dependencies */
5 | #include "city/bake_config.h"
6 |
7 | #undef ECS_META_IMPL
8 | #ifndef FLECS_CITY_IMPL
9 | #define ECS_META_IMPL EXTERN // Ensure meta symbols are only defined once
10 | #endif
11 |
12 | #ifdef __cplusplus
13 | extern "C" {
14 | #endif
15 |
16 | ECS_STRUCT(CityBuildings, {
17 | int16_t min_height;
18 | int16_t max_height;
19 | int16_t min_width;
20 | float x_variation;
21 | float y_variation;
22 | float small_height;
23 | float skyscraper_chance;
24 | float modern_chance;
25 | float backyard_chance;
26 | });
27 |
28 | ECS_STRUCT(CityParks, {
29 | float chance;
30 | float tree_chance;
31 | float plaza_chance;
32 | int32_t tree_count;
33 | });
34 |
35 | ECS_STRUCT(CityProps, {
36 | float chance;
37 | float tree_chance;
38 | float bin_chance;
39 | float hydrant_chance;
40 | float bench_chance;
41 | });
42 |
43 | ECS_STRUCT(CityTraffic, {
44 | float frequency;
45 | float speed;
46 | float chance;
47 | });
48 |
49 | ECS_STRUCT(City, {
50 | int16_t blocks_x;
51 | int16_t blocks_y;
52 | int16_t block_width;
53 | int16_t block_height;
54 | float road_width;
55 | float pavement_width;
56 |
57 | bool lanterns;
58 | bool street_signs;
59 |
60 | CityBuildings buildings;
61 | CityParks parks;
62 | CityProps props;
63 | CityTraffic traffic;
64 |
65 | ecs_entity_t cars_scope;
66 | });
67 |
68 | void FlecsCityImport(
69 | ecs_world_t *world);
70 |
71 | #ifdef __cplusplus
72 | }
73 | #endif
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/atmosphere_frag.glsl:
--------------------------------------------------------------------------------
1 | #include "etc/sokol/shaders/atmosphere.glsl"
2 |
3 | uniform mat4 u_mat_v;
4 | uniform vec3 u_eye_pos;
5 | uniform vec3 u_light_pos;
6 | uniform vec3 u_night_color;
7 | uniform float u_aspect;
8 | uniform float u_offset;
9 |
10 | uniform float intensity;
11 | uniform float planet_radius;
12 | uniform float atmosphere_radius;
13 | uniform vec3 rayleigh_coef;
14 | uniform float mie_coef;
15 | uniform float rayleigh_scale_height;
16 | uniform float mie_scale_height;
17 | uniform float mie_scatter_dir;
18 |
19 | in vec2 uv;
20 | out vec4 frag_color;
21 |
22 | void main() {
23 | vec2 uv_scaled = uv * 1.3 - 0.66;
24 | uv_scaled.x *= u_aspect;
25 | uv_scaled.y += u_offset;
26 |
27 | vec4 coord = vec4(uv_scaled, -1, 0);
28 | vec3 ray = vec3(u_mat_v * coord);
29 | vec3 orig = vec3(u_eye_pos.x, 6372e3 + u_eye_pos.y, u_eye_pos.z);
30 | vec3 atmos = atmosphere(
31 | ray, // normalized ray direction
32 | orig, // ray origin
33 | -u_light_pos, // position of the sun
34 | intensity, // intensity of the sun
35 | planet_radius, // radius of the planet in meters
36 | atmosphere_radius, // radius of the atmosphere in meters
37 | rayleigh_coef, // Rayleigh scattering coefficient
38 | mie_coef, // Mie scattering coefficient
39 | rayleigh_scale_height, // Rayleigh scale height
40 | mie_scale_height, // Mie scale height
41 | mie_scatter_dir // Mie preferred scattering direction
42 | );
43 |
44 | frag_color = vec4(atmos, 1.0) + vec4(u_night_color, 1.0);
45 | }
46 |
--------------------------------------------------------------------------------
/deps/dependee.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependee": {
3 | "lang.c": {
4 | "${cfg sanitize}": {
5 | "defines": [
6 | "FLECS_SANITIZE"
7 | ]
8 | }
9 | },
10 | "lang.cpp": {
11 | "${cfg sanitize}": {
12 | "defines": [
13 | "FLECS_SANITIZE"
14 | ]
15 | }
16 | }
17 | },
18 | "lang.c": {
19 | "${os linux}": {
20 | "lib": [
21 | "rt",
22 | "pthread",
23 | "m",
24 | "GL",
25 | "X11",
26 | "Xi",
27 | "Xcursor",
28 | "dl"
29 | ],
30 | "${cfg debug}": {
31 | "export-symbols": true
32 | },
33 | "${cfg sanitize}": {
34 | "export-symbols": true
35 | }
36 | },
37 | "${os windows}": {
38 | "lib": [
39 | "ws2_32",
40 | "dbgHelp"
41 | ],
42 | "defines": [
43 | "_WINDOWS",
44 | "_USRDLL",
45 | "CGLM_EXPORTS",
46 | "CGLM_DLL"
47 | ]
48 | },
49 | "${cfg sanitize}": {
50 | "defines": [
51 | "FLECS_SANITIZE"
52 | ]
53 | },
54 | "${os darwin}": {
55 | "ldflags": [
56 | "-framework Cocoa",
57 | "-framework QuartzCore",
58 | "-framework OpenGL"
59 | ]
60 | },
61 | "${target em}": {
62 | "ldflags": [
63 | "-s USE_WEBGL2=1"
64 | ],
65 | "${cfg debug}": {
66 | "ldflags": [
67 | "-s GL_DEBUG=1"
68 | ]
69 | },
70 | "embed": [
71 | "etc\/sokol\/shaders"
72 | ]
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/deps/flecs_components_cglm.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_components_cglm_STATIC
3 | #ifndef FLECS_COMPONENTS_CGLM_H
4 | #define FLECS_COMPONENTS_CGLM_H
5 |
6 | /* This generated file contains includes for project dependencies */
7 | /*
8 | )
9 | (.)
10 | .|.
11 | | |
12 | _.--| |--._
13 | .-'; ;`-'& ; `&.
14 | \ & ; & &_/
15 | |"""---...---"""|
16 | \ | | | | | | | /
17 | `---.|.|.|.---'
18 |
19 | * This file is generated by bake.lang.c for your convenience. Headers of
20 | * dependencies will automatically show up in this file. Include bake_config.h
21 | * in your main project file. Do not edit! */
22 |
23 | #ifndef FLECS_COMPONENTS_CGLM_BAKE_CONFIG_H
24 | #define FLECS_COMPONENTS_CGLM_BAKE_CONFIG_H
25 |
26 | /* Headers of public dependencies */
27 | #include "flecs.h"
28 | #include "cglm.h"
29 |
30 | /* Convenience macro for exporting symbols */
31 | #ifndef flecs_components_cglm_STATIC
32 | #if defined(flecs_components_cglm_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
33 | #define FLECS_COMPONENTS_CGLM_API __declspec(dllexport)
34 | #elif defined(flecs_components_cglm_EXPORTS)
35 | #define FLECS_COMPONENTS_CGLM_API __attribute__((__visibility__("default")))
36 | #elif defined(_MSC_VER)
37 | #define FLECS_COMPONENTS_CGLM_API __declspec(dllimport)
38 | #else
39 | #define FLECS_COMPONENTS_CGLM_API
40 | #endif
41 | #else
42 | #define FLECS_COMPONENTS_CGLM_API
43 | #endif
44 |
45 | #endif
46 |
47 |
48 |
49 | #ifdef __cplusplus
50 | extern "C" {
51 | #endif
52 |
53 | FLECS_COMPONENTS_CGLM_API
54 | extern ECS_COMPONENT_DECLARE(vec3);
55 |
56 | FLECS_COMPONENTS_CGLM_API
57 | extern ECS_COMPONENT_DECLARE(vec4);
58 |
59 | FLECS_COMPONENTS_CGLM_API
60 | void FlecsComponentsCglmImport(
61 | ecs_world_t *world);
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif
68 |
69 |
--------------------------------------------------------------------------------
/deps/flecs_components_geometry.c:
--------------------------------------------------------------------------------
1 | #define FLECS_COMPONENTS_GEOMETRY_IMPL
2 | #include "flecs_components_geometry.h"
3 |
4 | ECS_DECLARE(EcsGeometry);
5 | ECS_COMPONENT_DECLARE(EcsStrokeColor);
6 |
7 | ECS_COPY(EcsMesh, dst, src, {
8 | if (dst->vertices) {
9 | ecs_os_free(dst->vertices);
10 | }
11 |
12 | if (src->vertices) {
13 | size_t size = sizeof(vec3) * src->vertex_count;
14 | dst->vertices = ecs_os_malloc(size);
15 | dst->vertex_count = src->vertex_count;
16 | memcpy(dst->vertices, src->vertices, size);
17 | } else {
18 | dst->vertices = NULL;
19 | dst->vertex_count = 0;
20 | }
21 | })
22 |
23 | ECS_MOVE(EcsMesh, dst, src, {
24 | if (dst->vertices) {
25 | ecs_os_free(dst->vertices);
26 | }
27 |
28 | dst->vertices = src->vertices;
29 | dst->vertex_count = src->vertex_count;
30 | src->vertices = NULL;
31 | src->vertex_count = 0;
32 | })
33 |
34 | ECS_DTOR(EcsMesh, ptr, {
35 | ecs_os_free(ptr->vertices);
36 | })
37 |
38 | void FlecsComponentsGeometryImport(
39 | ecs_world_t *world)
40 | {
41 | ECS_MODULE(world, FlecsComponentsGeometry);
42 | ECS_IMPORT(world, FlecsComponentsGraphics);
43 |
44 | ecs_set_name_prefix(world, "Ecs");
45 |
46 | ECS_META_COMPONENT(world, EcsDrawDistance);
47 | ECS_META_COMPONENT(world, EcsLine2);
48 | ECS_META_COMPONENT(world, EcsLine3);
49 | ECS_META_COMPONENT(world, EcsRectangle);
50 | ECS_META_COMPONENT(world, EcsStrokeWidth);
51 | ECS_COMPONENT_DEFINE(world, EcsStrokeColor);
52 | ECS_META_COMPONENT(world, EcsCornerRadius);
53 | ECS_META_COMPONENT(world, EcsBox);
54 | ECS_META_COMPONENT(world, EcsCircle);
55 |
56 | ECS_TAG_DEFINE(world, EcsGeometry);
57 |
58 | ecs_add_pair(world, ecs_id(EcsRectangle), EcsWith, EcsGeometry);
59 | ecs_add_pair(world, ecs_id(EcsBox), EcsWith, EcsGeometry);
60 |
61 | ecs_add_pair(world, ecs_id(EcsRectangle), EcsOnInstantiate, EcsInherit);
62 | ecs_add_pair(world, ecs_id(EcsBox), EcsOnInstantiate, EcsInherit);
63 |
64 | ecs_struct(world, {
65 | .entity = ecs_id(EcsStrokeColor),
66 | .members = {
67 | { "r", ecs_id(ecs_f32_t) },
68 | { "g", ecs_id(ecs_f32_t) },
69 | { "b", ecs_id(ecs_f32_t) }
70 | }
71 | });
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/deps/flecs_systems_transform.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_systems_transform_STATIC
3 | #ifndef FLECS_SYSTEMS_TRANSFORM_H
4 | #define FLECS_SYSTEMS_TRANSFORM_H
5 |
6 | /*
7 | )
8 | (.)
9 | .|.
10 | | |
11 | _.--| |--._
12 | .-'; ;`-'& ; `&.
13 | \ & ; & &_/
14 | |"""---...---"""|
15 | \ | | | | | | | /
16 | `---.|.|.|.---'
17 |
18 | * This file is generated by bake.lang.c for your convenience. Headers of
19 | * dependencies will automatically show up in this file. Include bake_config.h
20 | * in your main project file. Do not edit! */
21 |
22 | #ifndef FLECS_SYSTEMS_TRANSFORM_BAKE_CONFIG_H
23 | #define FLECS_SYSTEMS_TRANSFORM_BAKE_CONFIG_H
24 |
25 | /* Headers of public dependencies */
26 | #include "flecs.h"
27 | #include "cglm.h"
28 | #include "flecs_components_transform.h"
29 |
30 | /* Convenience macro for exporting symbols */
31 | #ifndef flecs_systems_transform_STATIC
32 | #if defined(flecs_systems_transform_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
33 | #define FLECS_SYSTEMS_TRANSFORM_API __declspec(dllexport)
34 | #elif defined(flecs_systems_transform_EXPORTS)
35 | #define FLECS_SYSTEMS_TRANSFORM_API __attribute__((__visibility__("default")))
36 | #elif defined(_MSC_VER)
37 | #define FLECS_SYSTEMS_TRANSFORM_API __declspec(dllimport)
38 | #else
39 | #define FLECS_SYSTEMS_TRANSFORM_API
40 | #endif
41 | #else
42 | #define FLECS_SYSTEMS_TRANSFORM_API
43 | #endif
44 |
45 | #endif
46 |
47 |
48 |
49 | #ifdef __cplusplus
50 | extern "C" {
51 | #endif
52 |
53 | FLECS_SYSTEMS_TRANSFORM_API
54 | void FlecsSystemsTransformImport(
55 | ecs_world_t *world);
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 |
61 | #ifdef __cplusplus
62 | #ifndef FLECS_NO_CPP
63 |
64 | namespace flecs {
65 | namespace systems {
66 |
67 | class transform {
68 | public:
69 | transform(flecs::world& ecs) {
70 | // Load module contents
71 | FlecsSystemsTransformImport(ecs);
72 |
73 | // Bind module contents with C++ types
74 | ecs.module();
75 | }
76 | };
77 |
78 | }
79 | }
80 |
81 | #endif // FLECS_NO_CPP
82 | #endif // __cplusplus
83 |
84 | #endif
85 |
86 |
--------------------------------------------------------------------------------
/deps/flecs_components_transform.c:
--------------------------------------------------------------------------------
1 | #define FLECS_COMPONENTS_TRANSFORM_IMPL
2 |
3 | #include "flecs_components_transform.h"
4 |
5 | ECS_TAG_DECLARE(EcsTransformManually);
6 | ECS_TAG_DECLARE(EcsTransformOnce);
7 | ECS_TAG_DECLARE(EcsTransformNeeded);
8 |
9 | ECS_COMPONENT_DECLARE(EcsTransform2);
10 | ECS_COMPONENT_DECLARE(EcsTransform3);
11 | ECS_COMPONENT_DECLARE(EcsProject2);
12 | ECS_COMPONENT_DECLARE(EcsProject3);
13 |
14 | void FlecsComponentsTransformImport(
15 | ecs_world_t *world)
16 | {
17 | ECS_MODULE(world, FlecsComponentsTransform);
18 | ECS_IMPORT(world, FlecsComponentsCglm);
19 |
20 | ecs_set_name_prefix(world, "Ecs");
21 |
22 | ECS_META_COMPONENT(world, EcsPosition2);
23 | ECS_META_COMPONENT(world, EcsPosition3);
24 | ECS_META_COMPONENT(world, EcsScale2);
25 | ECS_META_COMPONENT(world, EcsScale3);
26 | ECS_META_COMPONENT(world, EcsRotation2);
27 | ECS_META_COMPONENT(world, EcsRotation3);
28 | ECS_META_COMPONENT(world, EcsQuaternion);
29 |
30 | ECS_COMPONENT_DEFINE(world, EcsTransform2);
31 | ECS_COMPONENT_DEFINE(world, EcsTransform3);
32 | ECS_COMPONENT_DEFINE(world, EcsProject2);
33 | ECS_COMPONENT_DEFINE(world, EcsProject3);
34 |
35 | ECS_TAG_DEFINE(world, EcsTransformManually);
36 | ECS_TAG_DEFINE(world, EcsTransformOnce);
37 | ECS_TAG_DEFINE(world, EcsTransformNeeded);
38 |
39 | ecs_add_pair(world, EcsTransformOnce, EcsWith, EcsTransformNeeded);
40 |
41 | ecs_set_hooks(world, EcsPosition2, {
42 | .ctor = flecs_default_ctor
43 | });
44 |
45 | ecs_set_hooks(world, EcsPosition3, {
46 | .ctor = flecs_default_ctor
47 | });
48 |
49 | ecs_set_hooks(world, EcsScale2, {
50 | .ctor = flecs_default_ctor
51 | });
52 |
53 | ecs_set_hooks(world, EcsScale3, {
54 | .ctor = flecs_default_ctor
55 | });
56 |
57 | ecs_set_hooks(world, EcsRotation2, {
58 | .ctor = flecs_default_ctor
59 | });
60 |
61 | ecs_set_hooks(world, EcsRotation3, {
62 | .ctor = flecs_default_ctor
63 | });
64 |
65 | ecs_set_hooks(world, EcsTransform2, {
66 | .ctor = flecs_default_ctor
67 | });
68 |
69 | ecs_set_hooks(world, EcsTransform3, {
70 | .ctor = flecs_default_ctor
71 | });
72 |
73 | ecs_add_pair(world, ecs_id(EcsPosition3), EcsWith, ecs_id(EcsTransform3));
74 | ecs_add_pair(world, ecs_id(EcsRotation3), EcsWith, ecs_id(EcsTransform3));
75 | ecs_add_pair(world, ecs_id(EcsScale3), EcsWith, ecs_id(EcsTransform3));
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/deps/flecs_systems_sokol.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_systems_sokol_STATIC
3 | #ifndef FLECS_SYSTEMS_SOKOL_H
4 | #define FLECS_SYSTEMS_SOKOL_H
5 |
6 | /* This generated file contains includes for project dependencies */
7 | /*
8 | )
9 | (.)
10 | .|.
11 | | |
12 | _.--| |--._
13 | .-'; ;`-'& ; `&.
14 | \ & ; & &_/
15 | |"""---...---"""|
16 | \ | | | | | | | /
17 | `---.|.|.|.---'
18 |
19 | * This file is generated by bake.lang.c for your convenience. Headers of
20 | * dependencies will automatically show up in this file. Include bake_config.h
21 | * in your main project file. Do not edit! */
22 |
23 | #ifndef FLECS_SYSTEMS_SOKOL_BAKE_CONFIG_H
24 | #define FLECS_SYSTEMS_SOKOL_BAKE_CONFIG_H
25 |
26 | /* Headers of public dependencies */
27 | #include "flecs.h"
28 | #include "flecs_components_gui.h"
29 | #include "flecs_components_input.h"
30 | #include "flecs_components_graphics.h"
31 | #include "flecs_components_transform.h"
32 | #include "flecs_components_geometry.h"
33 | #include "flecs_systems_transform.h"
34 | #include "flecs_game.h"
35 |
36 | /* Convenience macro for exporting symbols */
37 | #ifndef flecs_systems_sokol_STATIC
38 | #if defined(flecs_systems_sokol_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
39 | #define FLECS_SYSTEMS_SOKOL_API __declspec(dllexport)
40 | #elif defined(flecs_systems_sokol_EXPORTS)
41 | #define FLECS_SYSTEMS_SOKOL_API __attribute__((__visibility__("default")))
42 | #elif defined(_MSC_VER)
43 | #define FLECS_SYSTEMS_SOKOL_API __declspec(dllimport)
44 | #else
45 | #define FLECS_SYSTEMS_SOKOL_API
46 | #endif
47 | #else
48 | #define FLECS_SYSTEMS_SOKOL_API
49 | #endif
50 |
51 | #endif
52 |
53 |
54 |
55 | #ifdef __cplusplus
56 | extern "C" {
57 | #endif
58 |
59 | FLECS_SYSTEMS_SOKOL_API
60 | void FlecsSystemsSokolImport(
61 | ecs_world_t *world);
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #ifdef __cplusplus
68 | #ifndef FLECS_NO_CPP
69 |
70 | namespace flecs {
71 | namespace systems {
72 |
73 | class sokol {
74 | public:
75 | sokol(flecs::world& ecs) {
76 | // Load module contents
77 | FlecsSystemsSokolImport(ecs);
78 |
79 | // Bind C++ types with module contents
80 | ecs.module();
81 | }
82 | };
83 |
84 | }
85 | }
86 |
87 | #endif
88 | #endif
89 |
90 | #endif
91 |
92 |
--------------------------------------------------------------------------------
/deps/flecs_components_graphics.c:
--------------------------------------------------------------------------------
1 | #define FLECS_COMPONENTS_GRAPHICS_IMPL
2 |
3 | #include "flecs_components_graphics.h"
4 |
5 | ECS_TAG_DECLARE(EcsSun);
6 |
7 | ECS_CTOR(EcsCamera, ptr, {
8 | ptr->position[0] = 0.0f;
9 | ptr->position[1] = 0.0f;
10 | ptr->position[2] = 0.0f;
11 |
12 | ptr->lookat[0] = 0.0f;
13 | ptr->lookat[1] = 1.0f;
14 | ptr->lookat[2] = 1.0f;
15 |
16 | ptr->up[0] = 0.0f;
17 | ptr->up[1] = -1.0f;
18 | ptr->up[2] = 0.0f;
19 |
20 | ptr->fov = 30;
21 | ptr->near_ = 0.1;
22 | ptr->far_ = 1000;
23 | })
24 |
25 | ECS_CTOR(EcsAtmosphere, ptr, {
26 | ptr->intensity = 7.0;
27 | ptr->planet_radius = 6371e3;
28 | ptr->atmosphere_radius = 6471e3;
29 | ptr->rayleigh_coef[0] = 5.5e-6;
30 | ptr->rayleigh_coef[1] = 13.0e-6;
31 | ptr->rayleigh_coef[2] = 22.4e-6;
32 | ptr->mie_coef = 21e-6;
33 | ptr->rayleigh_scale_height = 8e3;
34 | ptr->mie_scale_height = 1.2e3;
35 | ptr->mie_scatter_dir = 0.758;
36 | })
37 |
38 | static void UpdateSelfLights(ecs_iter_t *it) {
39 | EcsSelfLight *sl = ecs_field(it, EcsSelfLight, 0);
40 | EcsRgb *color = ecs_field(it, EcsRgb, 1);
41 | EcsEmissive *emissive = ecs_field(it, EcsEmissive, 2);
42 | EcsPointLight *out = ecs_field(it, EcsPointLight, 3);
43 |
44 | for (int i = 0; i < it->count; i ++) {
45 | out[i].distance = sl[i].distance;
46 | out[i].color[0] = color[i].r;
47 | out[i].color[1] = color[i].g;
48 | out[i].color[2] = color[i].b;
49 | if (emissive) {
50 | out[i].intensity = emissive[i].value;
51 | } else {
52 | out[i].intensity = 1.0;
53 | }
54 | }
55 | }
56 |
57 | void FlecsComponentsGraphicsImport(
58 | ecs_world_t *world)
59 | {
60 | ECS_MODULE(world, FlecsComponentsGraphics);
61 | ECS_IMPORT(world, FlecsComponentsCglm);
62 |
63 | ecs_set_name_prefix(world, "Ecs");
64 | ECS_META_COMPONENT(world, EcsRgb);
65 |
66 | ecs_set_name_prefix(world, "Ecs");
67 | ECS_META_COMPONENT(world, EcsCamera);
68 | ECS_META_COMPONENT(world, EcsLookAt);
69 | ECS_META_COMPONENT(world, EcsDirectionalLight);
70 | ECS_META_COMPONENT(world, EcsPointLight);
71 | ECS_META_COMPONENT(world, EcsSelfLight);
72 | ECS_META_COMPONENT(world, EcsSpecular);
73 | ECS_META_COMPONENT(world, EcsEmissive);
74 | ECS_META_COMPONENT(world, EcsLightIntensity);
75 | ECS_META_COMPONENT(world, EcsAtmosphere);
76 | ECS_TAG_DEFINE(world, EcsSun);
77 |
78 | ecs_add_pair(world, ecs_id(EcsRgb), EcsOnInstantiate, EcsInherit);
79 | ecs_add_pair(world, ecs_id(EcsSpecular), EcsOnInstantiate, EcsInherit);
80 | ecs_add_pair(world, ecs_id(EcsEmissive), EcsOnInstantiate, EcsInherit);
81 |
82 | ecs_add_pair(world, ecs_id(EcsDirectionalLight), EcsOnInstantiate, EcsInherit);
83 | ecs_add_pair(world, ecs_id(EcsPointLight), EcsOnInstantiate, EcsInherit);
84 | ecs_add_pair(world, ecs_id(EcsSelfLight), EcsOnInstantiate, EcsInherit);
85 |
86 | ecs_add_pair(world, ecs_id(EcsSelfLight), EcsWith, ecs_id(EcsPointLight));
87 |
88 | ecs_struct(world, {
89 | .entity = ecs_entity(world, {
90 | .name = "ecs_rgb_t",
91 | .symbol = "ecs_rgb_t",
92 | }),
93 | .members = {
94 | { .name = "r", .type = ecs_id(ecs_f32_t) },
95 | { .name = "g", .type = ecs_id(ecs_f32_t) },
96 | { .name = "b", .type = ecs_id(ecs_f32_t) }
97 | }
98 | });
99 |
100 | ecs_set_hooks(world, EcsAtmosphere, {
101 | .ctor = ecs_ctor(EcsAtmosphere)
102 | });
103 |
104 | ECS_SYSTEM(world, UpdateSelfLights, EcsPostUpdate,
105 | [in] SelfLight,
106 | [in] Rgb,
107 | [in] ?Emissive,
108 | [out] PointLight);
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/deps/flecs_game.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_game_STATIC
3 | #ifndef GAME_H
4 | #define GAME_H
5 |
6 | /* This generated file contains includes for project dependencies */
7 | /*
8 | )
9 | (.)
10 | .|.
11 | | |
12 | _.--| |--._
13 | .-'; ;`-'& ; `&.
14 | \ & ; & &_/
15 | |"""---...---"""|
16 | \ | | | | | | | /
17 | `---.|.|.|.---'
18 |
19 | * This file is generated by bake.lang.c for your convenience. Headers of
20 | * dependencies will automatically show up in this file. Include bake_config.h
21 | * in your main project file. Do not edit! */
22 |
23 | #ifndef FLECS_GAME_BAKE_CONFIG_H
24 | #define FLECS_GAME_BAKE_CONFIG_H
25 |
26 | /* Headers of public dependencies */
27 | #include "cglm.h"
28 | #include "flecs.h"
29 | #include "flecs_components_input.h"
30 | #include "flecs_components_graphics.h"
31 | #include "flecs_components_gui.h"
32 | #include "flecs_components_transform.h"
33 | #include "flecs_components_geometry.h"
34 | #include "flecs_components_physics.h"
35 | #include "flecs_systems_physics.h"
36 |
37 | /* Convenience macro for exporting symbols */
38 | #ifndef flecs_game_STATIC
39 | #if defined(flecs_game_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
40 | #define FLECS_GAME_API __declspec(dllexport)
41 | #elif defined(flecs_game_EXPORTS)
42 | #define FLECS_GAME_API __attribute__((__visibility__("default")))
43 | #elif defined(_MSC_VER)
44 | #define FLECS_GAME_API __declspec(dllimport)
45 | #else
46 | #define FLECS_GAME_API
47 | #endif
48 | #else
49 | #define FLECS_GAME_API
50 | #endif
51 |
52 | #endif
53 |
54 |
55 |
56 | // Reflection system boilerplate
57 | #undef ECS_META_IMPL
58 | #ifndef FLECS_GAME_IMPL
59 | #define ECS_META_IMPL EXTERN // Ensure meta symbols are only defined once
60 | #endif
61 |
62 | #ifdef __cplusplus
63 | extern "C" {
64 | #endif
65 |
66 | FLECS_GAME_API
67 | extern ECS_DECLARE(EcsCameraController);
68 |
69 | FLECS_GAME_API
70 | ECS_STRUCT(EcsCameraAutoMove, {
71 | float after;
72 | float speed;
73 | float t;
74 | });
75 |
76 | FLECS_GAME_API
77 | ECS_STRUCT(EcsTimeOfDay, {
78 | float t;
79 | float speed;
80 | });
81 |
82 | FLECS_GAME_API
83 | ECS_STRUCT(ecs_grid_slot_t, {
84 | ecs_entity_t prefab;
85 | float chance;
86 | });
87 |
88 | FLECS_GAME_API
89 | ECS_STRUCT(ecs_grid_coord_t, {
90 | int32_t count;
91 | float spacing;
92 | float variation;
93 | });
94 |
95 | FLECS_GAME_API
96 | ECS_STRUCT(EcsGrid, {
97 | ecs_grid_coord_t x;
98 | ecs_grid_coord_t y;
99 | ecs_grid_coord_t z;
100 |
101 | EcsPosition3 border;
102 | EcsPosition3 border_offset;
103 |
104 | ecs_entity_t prefab;
105 | ecs_grid_slot_t variations[20];
106 | });
107 |
108 | FLECS_GAME_API
109 | ECS_STRUCT(EcsParticleEmitter, {
110 | ecs_entity_t particle;
111 | float spawn_interval;
112 | float lifespan;
113 | float size_decay;
114 | float color_decay;
115 | float velocity_decay;
116 | float t;
117 | });
118 |
119 | FLECS_GAME_API
120 | ECS_STRUCT(EcsParticle, {
121 | float t;
122 | });
123 |
124 | FLECS_GAME_API
125 | void FlecsGameImport(ecs_world_t *world);
126 |
127 | #ifdef __cplusplus
128 | }
129 | #endif
130 |
131 | #ifdef __cplusplus
132 | #ifndef FLECS_NO_CPP
133 | #include
134 |
135 | namespace flecs {
136 |
137 | struct game {
138 |
139 | game(flecs::world& ecs) {
140 | // Load module contents
141 | FlecsGameImport(ecs);
142 |
143 | // Bind C++ types with module contents
144 | ecs.module();
145 | }
146 | };
147 |
148 | }
149 |
150 | #endif
151 | #endif
152 |
153 | #endif
154 |
155 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/fx_ssao_header.glsl:
--------------------------------------------------------------------------------
1 | #include "etc/sokol/shaders/common.glsl"
2 |
3 | // Based on https://threejs.org/examples/webgl_postprocessing_sao.html
4 |
5 | // Increase/decrease to trade quality for performance
6 | #define NUM_SAMPLES 1
7 | // The sample kernel uses a spiral pattern so most samples are concentrated
8 | // close to the center.
9 | #define NUM_RINGS 3
10 | #define KERNEL_RADIUS 15.0
11 | // Misc params, tweaked to match the renderer
12 | #define BIAS 0.2
13 | #define SCALE 0.1
14 | // Derived constants
15 | #define ANGLE_STEP ((PI2 * float(NUM_RINGS)) / float(NUM_SAMPLES))
16 | #define INV_NUM_SAMPLES (1.0 / float(NUM_SAMPLES))
17 |
18 | float getDepth(const in vec2 t_uv) {
19 | return rgba_to_depth(texture(t_depth, t_uv));
20 | }
21 |
22 | float getViewZ(const in float depth) {
23 | return (u_near * u_far) / (depth - u_far);
24 | }
25 |
26 | // Compute position in world space from depth & projection matrix
27 | vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {
28 | float clipW = u_mat_p[2][3] * viewZ + u_mat_p[3][3];
29 | vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );
30 | clipPosition *= clipW; // unprojection.
31 | return ( u_inv_mat_p * clipPosition ).xyz;
32 | }
33 |
34 | // Compute normal from derived position. Should at some point replace it
35 | // with reading from a normal buffer so it works correctly with smooth
36 | // shading / normal maps.
37 | vec3 getViewNormal( const in vec3 viewPosition, const in vec2 t_uv ) {
38 | return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
39 | }
40 |
41 | float scaleDividedByCameraFar;
42 |
43 | // Compute occlusion of single sample
44 | float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
45 | vec3 viewDelta = sampleViewPosition - centerViewPosition;
46 | float viewDistance = length( viewDelta );
47 | float scaledScreenDistance = scaleDividedByCameraFar * viewDistance;
48 | float n_dot_d = dot(centerViewNormal, viewDelta);
49 | float scaled_n_dot_d = max(0.0, n_dot_d / scaledScreenDistance - BIAS);
50 | float result = scaled_n_dot_d / (1.0 + pow2(scaledScreenDistance));
51 |
52 | // Strip off values that are too large which eliminates shadowing objects
53 | // that are far away.
54 | if (result > 220.0) {
55 | result = 0.0;
56 | }
57 |
58 | // Squash the range and offset noise.
59 | return max(0.0, clamp(result, 1.1, 20.0) / 13.0 - 0.2);
60 | }
61 |
62 | float getAmbientOcclusion( const in vec3 centerViewPosition, float centerDepth ) {
63 | scaleDividedByCameraFar = SCALE / u_far;
64 | vec3 centerViewNormal = getViewNormal( centerViewPosition, uv );
65 |
66 | float angle = rand( uv ) * PI2;
67 | vec2 radius = vec2( KERNEL_RADIUS * INV_NUM_SAMPLES );
68 |
69 | // Use smaller kernels for objects farther away from the camera
70 | radius /= u_target_size * centerDepth * 0.05;
71 | // Make sure tha the sample radius isn't less than a single texel, as this
72 | // introduces noise
73 | radius = max(radius, 5.0 / u_target_size);
74 |
75 | vec2 radiusStep = radius;
76 | float occlusionSum = 0.0;
77 |
78 | // Collect occlusion samples
79 | for( int i = 0; i < NUM_SAMPLES; i ++ ) {
80 | vec2 sampleUv = uv + vec2( cos( angle ), sin( angle ) ) * radius;
81 |
82 | // Don't sample outside of texture coords to prevent edge artifacts
83 | sampleUv = clamp(sampleUv, EPSILON, 1.0 - EPSILON);
84 |
85 | radius += radiusStep;
86 | angle += ANGLE_STEP;
87 |
88 | float sampleDepth = getDepth( sampleUv );
89 | float sampleDepthNorm = sampleDepth / u_far;
90 |
91 | float sampleViewZ = getViewZ( sampleDepth );
92 | vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepthNorm, sampleViewZ );
93 | occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
94 | }
95 |
96 | return occlusionSum * (1.0 / (float(NUM_SAMPLES)));
97 | }
98 |
--------------------------------------------------------------------------------
/deps/flecs_components_physics.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_components_physics_STATIC
3 | #ifndef FLECS_COMPONENTS_PHYSICS_H
4 | #define FLECS_COMPONENTS_PHYSICS_H
5 |
6 | /*
7 | )
8 | (.)
9 | .|.
10 | | |
11 | _.--| |--._
12 | .-'; ;`-'& ; `&.
13 | \ & ; & &_/
14 | |"""---...---"""|
15 | \ | | | | | | | /
16 | `---.|.|.|.---'
17 |
18 | * This file is generated by bake.lang.c for your convenience. Headers of
19 | * dependencies will automatically show up in this file. Include bake_config.h
20 | * in your main project file. Do not edit! */
21 |
22 | #ifndef FLECS_COMPONENTS_PHYSICS_BAKE_CONFIG_H
23 | #define FLECS_COMPONENTS_PHYSICS_BAKE_CONFIG_H
24 |
25 | /* Headers of public dependencies */
26 | #include "flecs.h"
27 | #include "flecs_components_graphics.h"
28 |
29 | /* Convenience macro for exporting symbols */
30 | #ifndef flecs_components_physics_STATIC
31 | #if defined(flecs_components_physics_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
32 | #define FLECS_COMPONENTS_PHYSICS_API __declspec(dllexport)
33 | #elif defined(flecs_components_physics_EXPORTS)
34 | #define FLECS_COMPONENTS_PHYSICS_API __attribute__((__visibility__("default")))
35 | #elif defined(_MSC_VER)
36 | #define FLECS_COMPONENTS_PHYSICS_API __declspec(dllimport)
37 | #else
38 | #define FLECS_COMPONENTS_PHYSICS_API
39 | #endif
40 | #else
41 | #define FLECS_COMPONENTS_PHYSICS_API
42 | #endif
43 |
44 | #endif
45 |
46 |
47 |
48 | // Reflection system boilerplate
49 | #undef ECS_META_IMPL
50 | #ifndef FLECS_COMPONENTS_PHYSICS_IMPL
51 | #define ECS_META_IMPL EXTERN // Ensure meta symbols are only defined once
52 | #endif
53 |
54 | FLECS_COMPONENTS_PHYSICS_API
55 | extern ECS_DECLARE(EcsCollider);
56 |
57 | FLECS_COMPONENTS_PHYSICS_API
58 | extern ECS_DECLARE(EcsRigidBody);
59 |
60 | FLECS_COMPONENTS_PHYSICS_API
61 | ECS_STRUCT(EcsVelocity2, {
62 | float x;
63 | float y;
64 | });
65 |
66 | FLECS_COMPONENTS_PHYSICS_API
67 | ECS_STRUCT(EcsVelocity3, {
68 | float x;
69 | float y;
70 | float z;
71 | });
72 |
73 | FLECS_COMPONENTS_PHYSICS_API
74 | ECS_STRUCT(EcsAngularSpeed, {
75 | float value;
76 | });
77 |
78 | FLECS_COMPONENTS_PHYSICS_API
79 | ECS_STRUCT(EcsAngularVelocity, {
80 | float x;
81 | float y;
82 | float z;
83 | });
84 |
85 | FLECS_COMPONENTS_PHYSICS_API
86 | ECS_STRUCT(EcsBounciness, {
87 | float value;
88 | });
89 |
90 | FLECS_COMPONENTS_PHYSICS_API
91 | ECS_STRUCT(EcsFriction, {
92 | float value;
93 | });
94 |
95 | #ifdef __cplusplus
96 | extern "C" {
97 | #endif
98 |
99 | FLECS_COMPONENTS_PHYSICS_API
100 | void FlecsComponentsPhysicsImport(
101 | ecs_world_t *world);
102 |
103 | #ifdef __cplusplus
104 | }
105 | #endif
106 |
107 | #ifdef __cplusplus
108 | #ifndef FLECS_NO_CPP
109 |
110 | namespace flecs {
111 | namespace components {
112 |
113 | class physics {
114 | public:
115 | using Velocity2 = EcsVelocity2;
116 | using Velocity3 = EcsVelocity3;
117 | using AngularSpeed = EcsAngularSpeed;
118 | using AngularVelocity = EcsAngularVelocity;
119 | using Bounciness = EcsBounciness;
120 | using Friction = EcsFriction;
121 |
122 | physics(flecs::world& ecs) {
123 | // Load module contents
124 | FlecsComponentsPhysicsImport(ecs);
125 |
126 | // Bind C++ types with module contents
127 | ecs.module();
128 | ecs.component();
129 | ecs.component();
130 | ecs.component();
131 | ecs.component();
132 | ecs.component();
133 | ecs.component();
134 | }
135 | };
136 |
137 | }
138 | }
139 |
140 | #endif
141 | #endif
142 |
143 | #endif
144 |
145 |
--------------------------------------------------------------------------------
/etc/sokol/shaders/atmosphere.glsl:
--------------------------------------------------------------------------------
1 | // From https://github.com/wwwtyro/glsl-atmosphere
2 | #include "etc/sokol/shaders/constants.glsl"
3 |
4 | #define iSteps 16
5 | #define jSteps 8
6 |
7 | vec2 rsi(vec3 r0, vec3 rd, float sr) {
8 | // ray-sphere intersection that assumes
9 | // the sphere is centered at the origin.
10 | // No intersection when result.x > result.y
11 | float a = dot(rd, rd);
12 | float b = 2.0 * dot(rd, r0);
13 | float c = dot(r0, r0) - (sr * sr);
14 | float d = (b*b) - 4.0*a*c;
15 | if (d < 0.0) return vec2(1e5,-1e5);
16 | return vec2(
17 | (-b - sqrt(d))/(2.0*a),
18 | (-b + sqrt(d))/(2.0*a)
19 | );
20 | }
21 |
22 | vec3 atmosphere(
23 | vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos,
24 | vec3 kRlh, float kMie, float shRlh, float shMie, float g)
25 | {
26 | // Normalize the sun and view directions.
27 | pSun = normalize(pSun);
28 | r = normalize(r);
29 |
30 | // Calculate the step size of the primary ray.
31 | vec2 p = rsi(r0, r, rAtmos);
32 | if (p.x > p.y) return vec3(0,0,0);
33 | p.y = min(p.y, rsi(r0, r, rPlanet).x);
34 | float iStepSize = (p.y - p.x) / float(iSteps);
35 |
36 | // Initialize the primary ray time.
37 | float iTime = 0.0;
38 |
39 | // Initialize accumulators for Rayleigh and Mie scattering.
40 | vec3 totalRlh = vec3(0,0,0);
41 | vec3 totalMie = vec3(0,0,0);
42 |
43 | // Initialize optical depth accumulators for the primary ray.
44 | float iOdRlh = 0.0;
45 | float iOdMie = 0.0;
46 |
47 | // Calculate the Rayleigh and Mie phases.
48 | float mu = dot(r, pSun);
49 | float mumu = mu * mu;
50 | float gg = g * g;
51 | float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);
52 | float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));
53 |
54 | // Sample the primary ray.
55 | for (int i = 0; i < iSteps; i++) {
56 |
57 | // Calculate the primary ray sample position.
58 | vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);
59 |
60 | // Calculate the height of the sample.
61 | float iHeight = length(iPos) - rPlanet;
62 |
63 | // Calculate the optical depth of the Rayleigh and Mie scattering for this step.
64 | float odStepRlh = exp(-iHeight / shRlh) * iStepSize;
65 | float odStepMie = exp(-iHeight / shMie) * iStepSize;
66 |
67 | // Accumulate optical depth.
68 | iOdRlh += odStepRlh;
69 | iOdMie += odStepMie;
70 |
71 | // Calculate the step size of the secondary ray.
72 | float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);
73 |
74 | // Initialize the secondary ray time.
75 | float jTime = 0.0;
76 |
77 | // Initialize optical depth accumulators for the secondary ray.
78 | float jOdRlh = 0.0;
79 | float jOdMie = 0.0;
80 |
81 | // Sample the secondary ray.
82 | for (int j = 0; j < jSteps; j++) {
83 |
84 | // Calculate the secondary ray sample position.
85 | vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);
86 |
87 | // Calculate the height of the sample.
88 | float jHeight = length(jPos) - rPlanet;
89 |
90 | // Accumulate the optical depth.
91 | jOdRlh += exp(-jHeight / shRlh) * jStepSize;
92 | jOdMie += exp(-jHeight / shMie) * jStepSize;
93 |
94 | // Increment the secondary ray time.
95 | jTime += jStepSize;
96 | }
97 |
98 | // Calculate attenuation.
99 | vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));
100 |
101 | // Accumulate scattering.
102 | totalRlh += odStepRlh * attn;
103 | totalMie += odStepMie * attn;
104 |
105 | // Increment the primary ray time.
106 | iTime += iStepSize;
107 |
108 | }
109 |
110 | // Calculate and return the final color.
111 | return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);
112 | }
113 |
114 | // #pragma glslify: export(atmosphere)
115 |
--------------------------------------------------------------------------------
/deps/flecs_components_geometry.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_components_geometry_STATIC
3 | #ifndef FLECS_COMPONENTS_GEOMETRY_H
4 | #define FLECS_COMPONENTS_GEOMETRY_H
5 |
6 | /*
7 | )
8 | (.)
9 | .|.
10 | | |
11 | _.--| |--._
12 | .-'; ;`-'& ; `&.
13 | \ & ; & &_/
14 | |"""---...---"""|
15 | \ | | | | | | | /
16 | `---.|.|.|.---'
17 |
18 | * This file is generated by bake.lang.c for your convenience. Headers of
19 | * dependencies will automatically show up in this file. Include bake_config.h
20 | * in your main project file. Do not edit! */
21 |
22 | #ifndef FLECS_COMPONENTS_GEOMETRY_BAKE_CONFIG_H
23 | #define FLECS_COMPONENTS_GEOMETRY_BAKE_CONFIG_H
24 |
25 | /* Headers of public dependencies */
26 | #include "flecs.h"
27 | #include "flecs_components_graphics.h"
28 |
29 | /* Convenience macro for exporting symbols */
30 | #ifndef flecs_components_geometry_STATIC
31 | #if defined(flecs_components_geometry_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
32 | #define FLECS_COMPONENTS_GEOMETRY_API __declspec(dllexport)
33 | #elif defined(flecs_components_geometry_EXPORTS)
34 | #define FLECS_COMPONENTS_GEOMETRY_API __attribute__((__visibility__("default")))
35 | #elif defined(_MSC_VER)
36 | #define FLECS_COMPONENTS_GEOMETRY_API __declspec(dllimport)
37 | #else
38 | #define FLECS_COMPONENTS_GEOMETRY_API
39 | #endif
40 | #else
41 | #define FLECS_COMPONENTS_GEOMETRY_API
42 | #endif
43 |
44 | #endif
45 |
46 |
47 |
48 | // Reflection system boilerplate
49 | #undef ECS_META_IMPL
50 | #ifndef FLECS_COMPONENTS_GEOMETRY_IMPL
51 | #define ECS_META_IMPL EXTERN // Ensure meta symbols are only defined once
52 | #endif
53 |
54 | FLECS_COMPONENTS_GEOMETRY_API
55 | ECS_STRUCT(EcsDrawDistance, {
56 | float far_;
57 | });
58 |
59 | FLECS_COMPONENTS_GEOMETRY_API
60 | ECS_STRUCT(EcsLine2, {
61 | vec3 start;
62 | vec3 stop;
63 | });
64 |
65 | FLECS_COMPONENTS_GEOMETRY_API
66 | ECS_STRUCT(EcsLine3, {
67 | vec3 start;
68 | vec3 stop;
69 | });
70 |
71 | FLECS_COMPONENTS_GEOMETRY_API
72 | ECS_STRUCT(EcsRectangle, {
73 | float width;
74 | float height;
75 | });
76 |
77 | FLECS_COMPONENTS_GEOMETRY_API
78 | ECS_STRUCT(EcsStrokeWidth, {
79 | float value;
80 | float left;
81 | float right;
82 | float top;
83 | float bottom;
84 | });
85 |
86 | FLECS_COMPONENTS_GEOMETRY_API
87 | extern ECS_COMPONENT_DECLARE(EcsStrokeColor);
88 | typedef EcsRgb EcsStrokeColor;
89 |
90 | FLECS_COMPONENTS_GEOMETRY_API
91 | ECS_STRUCT(EcsCornerRadius, {
92 | float value;
93 | float top_left;
94 | float top_right;
95 | float bottom_left;
96 | float bottom_right;
97 | });
98 |
99 | typedef EcsRectangle ecs_rect_t;
100 |
101 | FLECS_COMPONENTS_GEOMETRY_API
102 | ECS_STRUCT(EcsCircle, {
103 | float radius;
104 | });
105 |
106 | FLECS_COMPONENTS_GEOMETRY_API
107 | ECS_STRUCT(EcsBox, {
108 | float width;
109 | float height;
110 | float depth;
111 | });
112 |
113 | FLECS_COMPONENTS_GEOMETRY_API
114 | extern ECS_DECLARE(EcsGeometry);
115 |
116 | // Not yet supported
117 | typedef struct EcsMesh {
118 | vec3 *vertices;
119 | int32_t vertex_count;
120 | } EcsMesh;
121 |
122 | #ifdef __cplusplus
123 | extern "C" {
124 | #endif
125 |
126 | FLECS_COMPONENTS_GEOMETRY_API
127 | void FlecsComponentsGeometryImport(
128 | ecs_world_t *world);
129 |
130 | #ifdef __cplusplus
131 | }
132 | #endif
133 |
134 | #ifdef __cplusplus
135 | #ifndef FLECS_NO_CPP
136 |
137 | namespace flecs {
138 | namespace components {
139 |
140 | class geometry {
141 | public:
142 | using Line2 = EcsLine2;
143 | using Line3 = EcsLine3;
144 | using Rectangle = EcsRectangle;
145 | using StrokeWidth = EcsStrokeWidth;
146 | using CornerRadius = EcsCornerRadius;
147 | using Circle = EcsCircle;
148 | using Box = EcsBox;
149 |
150 | struct StrokeColor {
151 | float r;
152 | float g;
153 | float b;
154 | };
155 |
156 | geometry(flecs::world& ecs) {
157 | // Load module contents
158 | FlecsComponentsGeometryImport(ecs);
159 |
160 | // Bind C++ types with module contents
161 | ecs.module();
162 | ecs.component();
163 | ecs.component();
164 | ecs.component();
165 | ecs.component();
166 | ecs.component();
167 | ecs.component();
168 | ecs.component();
169 | }
170 | };
171 |
172 | }
173 | }
174 | #endif
175 | #endif
176 |
177 | #endif
178 |
179 |
--------------------------------------------------------------------------------
/deps/flecs_components_gui.h:
--------------------------------------------------------------------------------
1 | // Comment out this line when using as DLL
2 | #define flecs_components_gui_STATIC
3 | #ifndef FLECS_COMPONENTS_GUI_H
4 | #define FLECS_COMPONENTS_GUI_H
5 |
6 | /* This generated file contains includes for project dependencies */
7 | /*
8 | )
9 | (.)
10 | .|.
11 | | |
12 | _.--| |--._
13 | .-'; ;`-'& ; `&.
14 | \ & ; & &_/
15 | |"""---...---"""|
16 | \ | | | | | | | /
17 | `---.|.|.|.---'
18 |
19 | * This file is generated by bake.lang.c for your convenience. Headers of
20 | * dependencies will automatically show up in this file. Include bake_config.h
21 | * in your main project file. Do not edit! */
22 |
23 | #ifndef FLECS_COMPONENTS_GUI_BAKE_CONFIG_H
24 | #define FLECS_COMPONENTS_GUI_BAKE_CONFIG_H
25 |
26 | /* Headers of public dependencies */
27 | #include "flecs.h"
28 | #include "flecs_components_graphics.h"
29 | #include "flecs_components_cglm.h"
30 |
31 | /* Convenience macro for exporting symbols */
32 | #ifndef flecs_components_gui_STATIC
33 | #if defined(flecs_components_gui_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__))
34 | #define FLECS_COMPONENTS_GUI_API __declspec(dllexport)
35 | #elif defined(flecs_components_gui_EXPORTS)
36 | #define FLECS_COMPONENTS_GUI_API __attribute__((__visibility__("default")))
37 | #elif defined(_MSC_VER)
38 | #define FLECS_COMPONENTS_GUI_API __declspec(dllimport)
39 | #else
40 | #define FLECS_COMPONENTS_GUI_API
41 | #endif
42 | #else
43 | #define FLECS_COMPONENTS_GUI_API
44 | #endif
45 |
46 | #endif
47 |
48 |
49 |
50 | // Reflection system boilerplate
51 | #undef ECS_META_IMPL
52 | #ifndef FLECS_COMPONENTS_GUI_IMPL
53 | #define ECS_META_IMPL EXTERN // Ensure meta symbols are only defined once
54 | #endif
55 |
56 | /* Canvas */
57 |
58 | FLECS_COMPONENTS_GUI_API
59 | ECS_STRUCT(EcsCanvas, {
60 | char *title;
61 | int32_t width;
62 | int32_t height;
63 | int32_t left;
64 | int32_t right;
65 | int32_t top;
66 | int32_t bottom;
67 | ecs_entity_t camera;
68 | ecs_entity_t directional_light;
69 | EcsRgb background_color;
70 | EcsRgb ambient_light;
71 | EcsRgb ambient_light_ground;
72 | float ambient_light_ground_falloff;
73 | float ambient_light_ground_offset;
74 | float ambient_light_ground_intensity;
75 | float fog_density;
76 | float shadow_far;
77 | });
78 |
79 | /* Text & fonts */
80 |
81 | FLECS_COMPONENTS_GUI_API
82 | ECS_STRUCT(EcsText, {
83 | char *value;
84 | });
85 |
86 | FLECS_COMPONENTS_GUI_API
87 | ECS_STRUCT(EcsFontSize, {
88 | int32_t value;
89 | });
90 |
91 | FLECS_COMPONENTS_GUI_API
92 | ECS_ENUM(EcsFontStyle, {
93 | EcsFontStyleRegular,
94 | EcsFontStyleItalic,
95 | EcsFontStyleBold
96 | });
97 |
98 | /* Alignment */
99 |
100 | FLECS_COMPONENTS_GUI_API
101 | ECS_BITMASK(EcsAlign, {
102 | EcsAlignLeft = 1,
103 | EcsAlignCenter = 2,
104 | EcsAlignRight = 4,
105 | EcsAlignTop = 8,
106 | EcsAlignMiddle = 16,
107 | EcsAlignBottom = 32
108 | });
109 |
110 | FLECS_COMPONENTS_GUI_API
111 | ECS_STRUCT(EcsPadding, {
112 | float value;
113 | });
114 |
115 |
116 | #ifdef __cplusplus
117 | extern "C" {
118 | #endif
119 |
120 | FLECS_COMPONENTS_GUI_API
121 | void FlecsComponentsGuiImport(
122 | ecs_world_t *world);
123 |
124 | #ifdef __cplusplus
125 | }
126 | #endif
127 |
128 | #ifdef __cplusplus
129 | #ifndef FLECS_NO_CPP
130 |
131 | namespace flecs {
132 | namespace components {
133 |
134 | class gui {
135 | public:
136 | using Align = EcsAlign;
137 |
138 | struct Canvas : EcsCanvas {
139 | Canvas() {
140 | this->title = nullptr;
141 |
142 | this->width = 0;
143 | this->height = 0;
144 |
145 | this->left = 0;
146 | this->right = 0;
147 | this->top = 0;
148 | this->bottom = 0;
149 |
150 | this->ambient_light.r = 1.0;
151 | this->ambient_light.g = 1.0;
152 | this->ambient_light.b = 1.0;
153 |
154 | this->background_color.r = 0.0;
155 | this->background_color.g = 0.0;
156 | this->background_color.b = 0.0;
157 |
158 | this->camera = 0;
159 | this->directional_light = 0;
160 | }
161 | };
162 |
163 | gui(flecs::world& ecs) {
164 | // Load module contents
165 | FlecsComponentsGuiImport(ecs);
166 |
167 | // Bind C++ types with module contents
168 | ecs.module();
169 | ecs.component