Compare commits
28 Commits
248a256559
...
afd7edd93d
| Author | SHA1 | Date | |
|---|---|---|---|
| afd7edd93d | |||
| 805a1d1a23 | |||
| 31612b8526 | |||
| f25e06dcfe | |||
| d9eb9b2bf5 | |||
| 1643b4e1a5 | |||
| f12f919c63 | |||
| 85d424f6e5 | |||
| 3f8efe1f13 | |||
| d1e9c8c099 | |||
| 628c944e4c | |||
| 2f8fdcf5cd | |||
| 878d925c5d | |||
| 352fd4352f | |||
| 6d60547d78 | |||
| a96bd954bb | |||
| eb9374ad10 | |||
| 30168029d2 | |||
| 045f2707f7 | |||
| da9030fa90 | |||
| d972017f57 | |||
| 981fb4cbb4 | |||
| d284853f24 | |||
| 20b0b26e29 | |||
| 76e61ed233 | |||
| 1dc045cbed | |||
| 823092ad95 | |||
| baf5ef9533 |
12
game/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.~*
|
||||||
|
.\#*
|
||||||
|
\#*
|
||||||
|
*~
|
||||||
|
*.o
|
||||||
|
main
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
__pycache__
|
||||||
|
minecraft/region*.lights.vtx
|
||||||
|
minecraft/region*.dump
|
||||||
|
minecraft/gen/map.txt
|
||||||
85
game/Makefile
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#PREFIX = x86_64-w64-mingw32-
|
||||||
|
CC=$(PREFIX)gcc
|
||||||
|
CXX=$(PREFIX)g++
|
||||||
|
|
||||||
|
OPT = -O0 -march=x86-64-v3
|
||||||
|
|
||||||
|
CSTD = -std=gnu23
|
||||||
|
CXXSTD = -std=gnu++23
|
||||||
|
CFLAGS += -g
|
||||||
|
CFLAGS += -fpic
|
||||||
|
CFLAGS += -I./include
|
||||||
|
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -Wno-error=unused-but-set-variable
|
||||||
|
CFLAGS += -Wno-error=unknown-pragmas -Wno-unknown-pragmas
|
||||||
|
CFLAGS += $(shell pkg-config --cflags glfw3)
|
||||||
|
CFLAGS += -fno-strict-aliasing
|
||||||
|
|
||||||
|
LDFLAGS += -lm
|
||||||
|
LDFLAGS += $(shell pkg-config --libs glfw3)
|
||||||
|
|
||||||
|
MINECRAFT_OBJS = \
|
||||||
|
minecraft/love2dworld/inthash.o \
|
||||||
|
minecraft/grandlecturn/inthash.o \
|
||||||
|
minecraft/midnightmeadow/inthash.o \
|
||||||
|
src/minecraft.o \
|
||||||
|
src/world/world.o \
|
||||||
|
src/world/entry_table.o
|
||||||
|
|
||||||
|
OBJS = \
|
||||||
|
src/gl.o \
|
||||||
|
src/opengl.o \
|
||||||
|
src/test.o \
|
||||||
|
src/font/bitmap.o \
|
||||||
|
src/font/outline.o \
|
||||||
|
src/window.o \
|
||||||
|
src/bresenham.o \
|
||||||
|
src/file.o \
|
||||||
|
src/non_block.o \
|
||||||
|
src/view.o \
|
||||||
|
src/hud.o \
|
||||||
|
src/lighting.o \
|
||||||
|
src/collision_scene.o \
|
||||||
|
src/line_art.o \
|
||||||
|
src/boids.o \
|
||||||
|
src/boids_scene.o \
|
||||||
|
src/dds_validate.o \
|
||||||
|
src/collada/scene.o \
|
||||||
|
src/collada/effect.o \
|
||||||
|
src/collada/node_state.o \
|
||||||
|
src/collada/animate.o \
|
||||||
|
src/lua_api.o \
|
||||||
|
src/pixel_line_art.o \
|
||||||
|
src/flame.o \
|
||||||
|
data/scenes/ship20/ship20.o \
|
||||||
|
data/scenes/noodle/noodle.o \
|
||||||
|
data/scenes/shadow_test/shadow_test.o \
|
||||||
|
data/scenes/book/book.o \
|
||||||
|
$(MINECRAFT_OBJS)
|
||||||
|
|
||||||
|
all: test.so
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(ARCH) $(CSTD) $(CFLAGS) $(OPT) -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) $(ARCH) $(CXXSTD) $(CFLAGS) $(OPT) -c $< -o $@
|
||||||
|
|
||||||
|
test.so: $(OBJS)
|
||||||
|
$(CC) $(ARCH) $(OPT) -shared -g $^ -o $@ -lSDL3
|
||||||
|
|
||||||
|
main: $(OBJS) src/main.o
|
||||||
|
$(CC) $(ARCH) $(LDFLAGS) $(OPT) -g $^ -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
find . -type f ! -name "*.*" -delete
|
||||||
|
|
||||||
|
.SUFFIXES:
|
||||||
|
.INTERMEDIATE:
|
||||||
|
.SECONDARY:
|
||||||
|
.PHONY: all clean phony
|
||||||
|
|
||||||
|
%: RCS/%,v
|
||||||
|
%: RCS/%
|
||||||
|
%: %,v
|
||||||
|
%: s.%
|
||||||
|
%: SCCS/s.%
|
||||||
35
game/build_collada.sh
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
set -eux
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
~/love-demo/scene/noodle/noodle.DAE \
|
||||||
|
data/scenes/noodle/noodle.cpp \
|
||||||
|
data/scenes/noodle/noodle.vtx \
|
||||||
|
data/scenes/noodle/noodle.vjw \
|
||||||
|
data/scenes/noodle/noodle.idx
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
include/data/scenes/noodle.h
|
||||||
|
|
||||||
|
# shadow_test
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
~/love-demo/scene/shadow_test/shadow_test.DAE \
|
||||||
|
data/scenes/shadow_test/shadow_test.cpp \
|
||||||
|
data/scenes/shadow_test/shadow_test.vtx \
|
||||||
|
data/scenes/shadow_test/shadow_test.vjw \
|
||||||
|
data/scenes/shadow_test/shadow_test.idx
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
include/data/scenes/shadow_test.h
|
||||||
|
|
||||||
|
# book
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
~/Downloads/book.DAE \
|
||||||
|
data/scenes/book/book.cpp \
|
||||||
|
data/scenes/book/book.vtx \
|
||||||
|
data/scenes/book/book.vjw \
|
||||||
|
data/scenes/book/book.idx
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main \
|
||||||
|
include/data/scenes/book.h
|
||||||
@ -16,16 +16,17 @@ function love.conf(t)
|
|||||||
t.accelerometerjoystick = false
|
t.accelerometerjoystick = false
|
||||||
t.externalstorage = false
|
t.externalstorage = false
|
||||||
t.graphics.gammacorrect = false
|
t.graphics.gammacorrect = false
|
||||||
|
t.graphics.excluderenderers = {"vulkan", "metal"}
|
||||||
|
|
||||||
t.audio.mic = false
|
t.audio.mic = false
|
||||||
t.audio.mixwithsystem = true
|
t.audio.mixwithsystem = true
|
||||||
|
|
||||||
t.window.title = "test"
|
t.window.title = "test"
|
||||||
t.window.icon = nil
|
t.window.icon = nil
|
||||||
t.window.width = 960
|
t.window.width = 1024
|
||||||
t.window.height = 720
|
t.window.height = 1024
|
||||||
t.window.borderless = false
|
t.window.borderless = false
|
||||||
t.window.resizable = false
|
t.window.resizable = true
|
||||||
t.window.minwidth = 10
|
t.window.minwidth = 10
|
||||||
t.window.minheight = 9
|
t.window.minheight = 9
|
||||||
t.window.fullscreen = false
|
t.window.fullscreen = false
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"index" : 200,
|
|
||||||
"texture" : "asset/image/sample/javascript-racer-master/images/sprites/column.png",
|
|
||||||
"offset" : -0.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"index" : 200,
|
|
||||||
"texture" : "asset/image/sample/javascript-racer-master/images/sprites/cactus.png",
|
|
||||||
"offset" : 4
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"index" : 150,
|
|
||||||
"texture" : "asset/image/sample/javascript-racer-master/images/sprites/stump.png",
|
|
||||||
"offset" : 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
4616
game/data/scenes/book/book.cpp
Normal file
BIN
game/data/scenes/book/book.idx
Normal file
BIN
game/data/scenes/book/book.vjw
Normal file
BIN
game/data/scenes/book/book.vtx
Normal file
2611
game/data/scenes/noodle/noodle.cpp
Normal file
BIN
game/data/scenes/noodle/noodle.idx
Normal file
BIN
game/data/scenes/noodle/noodle.vjw
Normal file
BIN
game/data/scenes/noodle/noodle.vtx
Normal file
2279
game/data/scenes/shadow_test/shadow_test.cpp
Normal file
BIN
game/data/scenes/shadow_test/shadow_test.idx
Normal file
0
game/data/scenes/shadow_test/shadow_test.vjw
Normal file
BIN
game/data/scenes/shadow_test/shadow_test.vtx
Normal file
429
game/data/scenes/ship20/ship20.cpp
Normal file
@ -0,0 +1,429 @@
|
|||||||
|
#include "collada/types.h"
|
||||||
|
|
||||||
|
#include "data/scenes/ship20.h"
|
||||||
|
|
||||||
|
namespace ship20 {
|
||||||
|
|
||||||
|
using namespace collada::types;
|
||||||
|
|
||||||
|
light const light_environmentambientlight = {
|
||||||
|
.type = light_type::AMBIENT,
|
||||||
|
.color = { 0.0f, 0.0f, 0.0f },
|
||||||
|
};
|
||||||
|
|
||||||
|
light const light_omni002_light = {
|
||||||
|
.type = light_type::POINT,
|
||||||
|
.color = { 1.0f, 1.0f, 1.0f },
|
||||||
|
};
|
||||||
|
|
||||||
|
light const light_omni003_light = {
|
||||||
|
.type = light_type::POINT,
|
||||||
|
.color = { 1.0f, 1.0f, 1.0f },
|
||||||
|
};
|
||||||
|
|
||||||
|
// shipple2_png
|
||||||
|
image const image_shipple2_png = {
|
||||||
|
.uri = "data/scenes/ship20/shipple2.dds",
|
||||||
|
};
|
||||||
|
|
||||||
|
image const * const images[] = {
|
||||||
|
&image_shipple2_png,
|
||||||
|
};
|
||||||
|
|
||||||
|
effect const effect_diffusetexture = {
|
||||||
|
.type = effect_type::BLINN,
|
||||||
|
.blinn = {
|
||||||
|
.emission = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.ambient = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.588f, 0.588f, 0.588f, 1.0f},
|
||||||
|
},
|
||||||
|
.diffuse = {
|
||||||
|
.type = color_or_texture_type::TEXTURE,
|
||||||
|
.texture = { .image_index = 0 }, // shipple2_png
|
||||||
|
},
|
||||||
|
.specular = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.5f, 0.5f, 0.5f, 1.0f},
|
||||||
|
},
|
||||||
|
.shininess = 10.0f,
|
||||||
|
.reflective = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.reflectivity = 0.0f,
|
||||||
|
.transparent = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {1.0f, 1.0f, 1.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.transparency = 1.0f,
|
||||||
|
.index_of_refraction = 0.0f,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
effect const effect_cyanengine = {
|
||||||
|
.type = effect_type::BLINN,
|
||||||
|
.blinn = {
|
||||||
|
.emission = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.9647059f, 1.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.ambient = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.diffuse = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.specular = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.shininess = 10.0f,
|
||||||
|
.reflective = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.reflectivity = 0.0f,
|
||||||
|
.transparent = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {1.0f, 1.0f, 1.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.transparency = 1.0f,
|
||||||
|
.index_of_refraction = 0.0f,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
effect const effect_emissivetexture = {
|
||||||
|
.type = effect_type::BLINN,
|
||||||
|
.blinn = {
|
||||||
|
.emission = {
|
||||||
|
.type = color_or_texture_type::TEXTURE,
|
||||||
|
.texture = { .image_index = 0 }, // shipple2_png
|
||||||
|
},
|
||||||
|
.ambient = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.588f, 0.588f, 0.588f, 1.0f},
|
||||||
|
},
|
||||||
|
.diffuse = {
|
||||||
|
.type = color_or_texture_type::TEXTURE,
|
||||||
|
.texture = { .image_index = 0 }, // shipple2_png
|
||||||
|
},
|
||||||
|
.specular = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.shininess = 10.0f,
|
||||||
|
.reflective = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.reflectivity = 0.0f,
|
||||||
|
.transparent = {
|
||||||
|
.type = color_or_texture_type::COLOR,
|
||||||
|
.color = {1.0f, 1.0f, 1.0f, 1.0f},
|
||||||
|
},
|
||||||
|
.transparency = 1.0f,
|
||||||
|
.index_of_refraction = 0.0f,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
material const material_diffusetexture_material = {
|
||||||
|
.effect = &effect_diffusetexture,
|
||||||
|
};
|
||||||
|
|
||||||
|
material const material_cyanengine_material = {
|
||||||
|
.effect = &effect_cyanengine,
|
||||||
|
};
|
||||||
|
|
||||||
|
material const material_emissivetexture_material = {
|
||||||
|
.effect = &effect_emissivetexture,
|
||||||
|
};
|
||||||
|
|
||||||
|
input_element const input_elements_position_0_3_normal_0_3_texcoord_0_3[] = {
|
||||||
|
{
|
||||||
|
.semantic = "POSITION",
|
||||||
|
.semantic_index = 0,
|
||||||
|
.format = input_format::FLOAT3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.semantic = "NORMAL",
|
||||||
|
.semantic_index = 0,
|
||||||
|
.format = input_format::FLOAT3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.semantic = "TEXCOORD",
|
||||||
|
.semantic_index = 0,
|
||||||
|
.format = input_format::FLOAT3,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
triangles const triangles_geom_ship[] = {
|
||||||
|
{
|
||||||
|
.count = 2949, // triangles
|
||||||
|
.index_offset = 0, // indices
|
||||||
|
.inputs_index = 0, // index into inputs_list
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.count = 60, // triangles
|
||||||
|
.index_offset = 8847, // indices
|
||||||
|
.inputs_index = 0, // index into inputs_list
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.count = 239, // triangles
|
||||||
|
.index_offset = 9027, // indices
|
||||||
|
.inputs_index = 0, // index into inputs_list
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
geometry const geometry_geom_ship = {
|
||||||
|
.mesh = {
|
||||||
|
.triangles = triangles_geom_ship,
|
||||||
|
.triangles_count = 3,
|
||||||
|
|
||||||
|
.vertex_buffer_offset = 0,
|
||||||
|
.vertex_buffer_size = 133272,
|
||||||
|
|
||||||
|
.index_buffer_offset = 0,
|
||||||
|
.index_buffer_size = 38976,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
geometry const * const geometries[] = {
|
||||||
|
&geometry_geom_ship,
|
||||||
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_environmentambientlight[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_environmentambientlight[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_environmentambientlight[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_environmentambientlight[] = {
|
||||||
|
{
|
||||||
|
.light = &light_environmentambientlight,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_environmentambientlight[] = {};
|
||||||
|
|
||||||
|
node const node_node_environmentambientlight = {
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_environmentambientlight,
|
||||||
|
.transforms_count = 0,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_environmentambientlight,
|
||||||
|
.instance_geometries_count = 0,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_environmentambientlight,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_environmentambientlight,
|
||||||
|
.instance_lights_count = 1,
|
||||||
|
|
||||||
|
.channels = node_channels_node_environmentambientlight,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_ship[] = {
|
||||||
|
{
|
||||||
|
.type = transform_type::ROTATE,
|
||||||
|
.rotate = {0.0f, 0.0f, 1.0f, -180.0f},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_material const instance_geometry_instance_materials_node_ship_0[] = {
|
||||||
|
{
|
||||||
|
.element_index = 1, // an index into mesh.triangles
|
||||||
|
.material = &material_cyanengine_material,
|
||||||
|
|
||||||
|
.emission = { .input_set = -1 },
|
||||||
|
.ambient = { .input_set = -1 },
|
||||||
|
.diffuse = { .input_set = -1 },
|
||||||
|
.specular = { .input_set = -1 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.element_index = 0, // an index into mesh.triangles
|
||||||
|
.material = &material_diffusetexture_material,
|
||||||
|
|
||||||
|
.emission = { .input_set = -1 },
|
||||||
|
.ambient = { .input_set = -1 },
|
||||||
|
.diffuse = { .input_set = 0 },
|
||||||
|
.specular = { .input_set = -1 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.element_index = 2, // an index into mesh.triangles
|
||||||
|
.material = &material_emissivetexture_material,
|
||||||
|
|
||||||
|
.emission = { .input_set = 0 },
|
||||||
|
.ambient = { .input_set = -1 },
|
||||||
|
.diffuse = { .input_set = 0 },
|
||||||
|
.specular = { .input_set = -1 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_ship[] = {
|
||||||
|
{
|
||||||
|
.geometry = &geometry_geom_ship,
|
||||||
|
|
||||||
|
.instance_materials = instance_geometry_instance_materials_node_ship_0,
|
||||||
|
.instance_materials_count = 3,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_ship[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_ship[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_ship[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
node const node_node_ship = {
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_ship,
|
||||||
|
.transforms_count = 1,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_ship,
|
||||||
|
.instance_geometries_count = 1,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_ship,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_ship,
|
||||||
|
.instance_lights_count = 0,
|
||||||
|
|
||||||
|
.channels = node_channels_node_ship,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_omni002[] = {
|
||||||
|
{
|
||||||
|
.type = transform_type::TRANSLATE,
|
||||||
|
.translate = {-286.5521f, 395.7583f, 161.5579f},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_omni002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_omni002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_omni002[] = {
|
||||||
|
{
|
||||||
|
.light = &light_omni002_light,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_omni002[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
node const node_node_omni002 = {
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_omni002,
|
||||||
|
.transforms_count = 1,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_omni002,
|
||||||
|
.instance_geometries_count = 0,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_omni002,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_omni002,
|
||||||
|
.instance_lights_count = 1,
|
||||||
|
|
||||||
|
.channels = node_channels_node_omni002,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
transform const transforms_node_omni003[] = {
|
||||||
|
{
|
||||||
|
.type = transform_type::TRANSLATE,
|
||||||
|
.translate = {333.2103f, -314.4593f, 161.5578f},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_geometry const instance_geometries_node_omni003[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_controller const instance_controllers_node_omni003[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
instance_light const instance_lights_node_omni003[] = {
|
||||||
|
{
|
||||||
|
.light = &light_omni003_light,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
channel const * const node_channels_node_omni003[] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
node const node_node_omni003 = {
|
||||||
|
.parent_index = -1,
|
||||||
|
|
||||||
|
.type = node_type::NODE,
|
||||||
|
|
||||||
|
.transforms = transforms_node_omni003,
|
||||||
|
.transforms_count = 1,
|
||||||
|
|
||||||
|
.instance_geometries = instance_geometries_node_omni003,
|
||||||
|
.instance_geometries_count = 0,
|
||||||
|
|
||||||
|
.instance_controllers = instance_controllers_node_omni003,
|
||||||
|
.instance_controllers_count = 0,
|
||||||
|
|
||||||
|
.instance_lights = instance_lights_node_omni003,
|
||||||
|
.instance_lights_count = 1,
|
||||||
|
|
||||||
|
.channels = node_channels_node_omni003,
|
||||||
|
.channels_count = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
node const * const nodes[] = {
|
||||||
|
&node_node_environmentambientlight, // 0
|
||||||
|
&node_node_ship, // 1
|
||||||
|
&node_node_omni002, // 2
|
||||||
|
&node_node_omni003, // 3
|
||||||
|
};
|
||||||
|
|
||||||
|
inputs const inputs_list[] = {
|
||||||
|
{
|
||||||
|
.elements = input_elements_position_0_3_normal_0_3_texcoord_0_3,
|
||||||
|
.elements_count = 3,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
collada::types::descriptor const descriptor = {
|
||||||
|
.nodes = nodes,
|
||||||
|
.nodes_count = (sizeof (nodes)) / (sizeof (nodes[0])),
|
||||||
|
|
||||||
|
.inputs_list = inputs_list,
|
||||||
|
.inputs_list_count = (sizeof (inputs_list)) / (sizeof (inputs_list[0])),
|
||||||
|
|
||||||
|
.images = images,
|
||||||
|
.images_count = (sizeof (images)) / (sizeof (images[0])),
|
||||||
|
|
||||||
|
.position_normal_texture_buffer = "data/scenes/ship20/ship20.vtx",
|
||||||
|
.joint_weight_buffer = "data/scenes/ship20/ship20.vjw",
|
||||||
|
.index_buffer = "data/scenes/ship20/ship20.idx",
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
BIN
game/data/scenes/ship20/ship20.idx
Normal file
0
game/data/scenes/ship20/ship20.vjw
Normal file
BIN
game/data/scenes/ship20/ship20.vtx
Normal file
BIN
game/data/scenes/ship20/shipple2.dds
Normal file
BIN
game/font/bitmap/terminus_128x128_8x16.data
Normal file
BIN
game/font/bitmap/terminus_128x64_6x12.data
Normal file
BIN
game/font/bitmap/terminus_256x128_10x18.data
Normal file
BIN
game/font/bitmap/terminus_256x128_12x24.data
Normal file
BIN
game/font/bitmap/terminus_256x256_16x32.data
Normal file
BIN
game/font/outline/uncial_antiqua_36.data
Normal file
BIN
game/font/terminus_128x128_8x16.data
Normal file
BIN
game/font/terminus_128x64_6x12.data
Normal file
BIN
game/font/terminus_256x128_10x18.data
Normal file
BIN
game/font/terminus_256x128_12x24.data
Normal file
BIN
game/font/terminus_256x256_16x32.data
Normal file
311
game/include/KHR/khrplatform.h
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be included
|
||||||
|
** in all copies or substantial portions of the Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||||
|
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||||
|
* The last semantic modification to khrplatform.h was at commit ID:
|
||||||
|
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by filing pull requests or issues on
|
||||||
|
* the EGL Registry repository linked above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||||
|
# define KHRONOS_STATIC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(KHRONOS_STATIC)
|
||||||
|
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||||
|
* header compatible with static linking. */
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
||||||
53
game/include/boids.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace boids {
|
||||||
|
|
||||||
|
struct boid_configuration {
|
||||||
|
float vision_length;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float coefficient;
|
||||||
|
} cohesion;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float coefficient;
|
||||||
|
} alignment;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float minimum_length;
|
||||||
|
float coefficient;
|
||||||
|
} separation;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float coefficient;
|
||||||
|
} bounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct boid_forces {
|
||||||
|
float vision_neighbor_count;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
// intermediate state
|
||||||
|
XMVECTOR center_of_mass;
|
||||||
|
XMVECTOR force;
|
||||||
|
} cohesion;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
// intermediate state
|
||||||
|
XMVECTOR average_velocity;
|
||||||
|
XMVECTOR force;
|
||||||
|
} alignment;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
// intermediate state
|
||||||
|
XMVECTOR force;
|
||||||
|
} separation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct boid {
|
||||||
|
XMVECTOR position;
|
||||||
|
XMVECTOR velocity;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern boid_configuration configuration;
|
||||||
|
|
||||||
|
boid_forces const & evaluate(boid const * const boids, int length, int boid_index);
|
||||||
|
}
|
||||||
12
game/include/boids_scene.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace boids_scene {
|
||||||
|
|
||||||
|
void update(int up, int down, int left, int right,
|
||||||
|
int w, int s, int a, int d,
|
||||||
|
int t, int g, int f, int h,
|
||||||
|
int i, int k, int j, int l);
|
||||||
|
|
||||||
|
void load();
|
||||||
|
void draw();
|
||||||
|
}
|
||||||
13
game/include/bresenham.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void bresenham(int x1, int y1, int z1,
|
||||||
|
int x2, int y2, int z2,
|
||||||
|
void (*func)(int x, int y, int z));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
15
game/include/collada/animate.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "collada/instance_types.h"
|
||||||
|
|
||||||
|
namespace collada::animate {
|
||||||
|
static inline float fract(float f)
|
||||||
|
{
|
||||||
|
return f - floorf(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float loop(float f, float n)
|
||||||
|
{
|
||||||
|
return fract(f / n) * n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void animate_node(instance_types::node& node_instance, float t);
|
||||||
|
}
|
||||||
8
game/include/collada/effect.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace collada::effect {
|
||||||
|
extern unsigned int program_static;
|
||||||
|
extern unsigned int program_skinned;
|
||||||
|
|
||||||
|
void load_effects();
|
||||||
|
}
|
||||||
32
game/include/collada/instance_types.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "directxmath/directxmath.h"
|
||||||
|
|
||||||
|
#include "collada/types.h"
|
||||||
|
|
||||||
|
namespace collada::instance_types {
|
||||||
|
|
||||||
|
struct __attribute__((aligned(16))) lookat {
|
||||||
|
XMVECTOR eye;
|
||||||
|
XMVECTOR at;
|
||||||
|
XMVECTOR up;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __attribute__((aligned(16))) transform {
|
||||||
|
union {
|
||||||
|
instance_types::lookat lookat;
|
||||||
|
XMMATRIX matrix;
|
||||||
|
XMVECTOR vector;
|
||||||
|
};
|
||||||
|
types::transform_type type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct node {
|
||||||
|
// immutable state
|
||||||
|
types::node const * node;
|
||||||
|
|
||||||
|
// mutable state
|
||||||
|
transform * transforms;
|
||||||
|
XMMATRIX world;
|
||||||
|
};
|
||||||
|
}
|
||||||
13
game/include/collada/node_state.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "collada/types.h"
|
||||||
|
#include "collada/instance_types.h"
|
||||||
|
|
||||||
|
namespace collada::node_state {
|
||||||
|
struct state {
|
||||||
|
instance_types::node * node_instances;
|
||||||
|
|
||||||
|
void allocate_node_instances(types::node const * const * const nodes, int nodes_count);
|
||||||
|
void update_node_world_transform(instance_types::node & node_instance);
|
||||||
|
};
|
||||||
|
};
|
||||||
57
game/include/collada/scene.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "collada/types.h"
|
||||||
|
#include "collada/instance_types.h"
|
||||||
|
#include "collada/node_state.h"
|
||||||
|
|
||||||
|
namespace collada::scene {
|
||||||
|
struct static_skinned {
|
||||||
|
unsigned int static_mesh;
|
||||||
|
unsigned int skinned_mesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct state {
|
||||||
|
types::descriptor const * descriptor;
|
||||||
|
node_state::state node_state;
|
||||||
|
|
||||||
|
unsigned int vertex_buffer_pnt;
|
||||||
|
unsigned int vertex_buffer_jw;
|
||||||
|
unsigned int index_buffer;
|
||||||
|
unsigned int joint_uniform_buffer;
|
||||||
|
|
||||||
|
static_skinned * vertex_arrays;
|
||||||
|
int * vertex_buffer_strides_pnt;
|
||||||
|
|
||||||
|
unsigned int * textures;
|
||||||
|
|
||||||
|
// drawing
|
||||||
|
void load_layouts();
|
||||||
|
void load_images();
|
||||||
|
void load_scene(types::descriptor const * const descriptor);
|
||||||
|
|
||||||
|
void set_color_or_texture(types::color_or_texture const& color_or_texture,
|
||||||
|
unsigned int color_uniform,
|
||||||
|
unsigned int texture_unit);
|
||||||
|
void set_instance_material(types::instance_material const& instance_material);
|
||||||
|
|
||||||
|
void draw_geometry(types::geometry const & geometry,
|
||||||
|
types::instance_material const * const instance_materials,
|
||||||
|
int const instance_materials_count);
|
||||||
|
void draw_instance_geometries(types::instance_geometry const * const instance_geometries,
|
||||||
|
int const instance_geometries_count);
|
||||||
|
void draw_skin(types::skin const& skin,
|
||||||
|
types::instance_material const * const instance_materials,
|
||||||
|
int const instance_materials_count);
|
||||||
|
void draw_instance_controllers(types::instance_controller const * const instance_controllers,
|
||||||
|
int const instance_controllers_count);
|
||||||
|
|
||||||
|
void draw_node(types::node const & node, instance_types::node const & node_instance);
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
// state updates
|
||||||
|
void update(float t);
|
||||||
|
|
||||||
|
// query
|
||||||
|
instance_types::node * find_node_by_name(char const * name);
|
||||||
|
};
|
||||||
|
}
|
||||||
410
game/include/collada/types.h
Normal file
@ -0,0 +1,410 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace collada::types {
|
||||||
|
|
||||||
|
struct float2 {
|
||||||
|
float const x;
|
||||||
|
float const y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct float3 {
|
||||||
|
float const x;
|
||||||
|
float const y;
|
||||||
|
float const z;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct float4 {
|
||||||
|
float const x;
|
||||||
|
float const y;
|
||||||
|
float const z;
|
||||||
|
float const w;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct float7 {
|
||||||
|
float const a;
|
||||||
|
float const b;
|
||||||
|
float const c;
|
||||||
|
float const d;
|
||||||
|
float const e;
|
||||||
|
float const f;
|
||||||
|
float const g;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct matrix {
|
||||||
|
float const _11, _12, _13, _14;
|
||||||
|
float const _21, _22, _23, _24;
|
||||||
|
float const _31, _32, _33, _34;
|
||||||
|
float const _41, _42, _43, _44;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// geometry
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum class input_format {
|
||||||
|
FLOAT1,
|
||||||
|
FLOAT2,
|
||||||
|
FLOAT3,
|
||||||
|
FLOAT4,
|
||||||
|
INT1,
|
||||||
|
INT2,
|
||||||
|
INT3,
|
||||||
|
INT4,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct input_element {
|
||||||
|
char const * const semantic;
|
||||||
|
int const semantic_index;
|
||||||
|
enum input_format const format;
|
||||||
|
};
|
||||||
|
|
||||||
|
// inputs uniqueness is by evaluted pointer
|
||||||
|
struct inputs {
|
||||||
|
input_element const * const elements;
|
||||||
|
int const elements_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct triangles {
|
||||||
|
int const count;
|
||||||
|
int const index_offset;
|
||||||
|
int const inputs_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mesh {
|
||||||
|
// `triangles` must become a union if non-triangles are implemented.
|
||||||
|
// instance_geometry is an index into this array.
|
||||||
|
types::triangles const * triangles;
|
||||||
|
int const triangles_count;
|
||||||
|
|
||||||
|
int const vertex_buffer_offset;
|
||||||
|
int const vertex_buffer_size;
|
||||||
|
|
||||||
|
int const index_buffer_offset;
|
||||||
|
int const index_buffer_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct geometry {
|
||||||
|
types::mesh mesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// light
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum class light_type {
|
||||||
|
AMBIENT,
|
||||||
|
DIRECTIONAL,
|
||||||
|
POINT,
|
||||||
|
SPOT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct light {
|
||||||
|
light_type type;
|
||||||
|
float3 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// image
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct image {
|
||||||
|
const char * uri;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// effect
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum class color_or_texture_type {
|
||||||
|
COLOR,
|
||||||
|
TEXTURE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct texture {
|
||||||
|
int const image_index; // index in to images
|
||||||
|
};
|
||||||
|
|
||||||
|
struct color_or_texture {
|
||||||
|
color_or_texture_type type;
|
||||||
|
union {
|
||||||
|
float4 color;
|
||||||
|
types::texture texture;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct blinn {
|
||||||
|
color_or_texture const emission;
|
||||||
|
color_or_texture const ambient;
|
||||||
|
color_or_texture const diffuse;
|
||||||
|
color_or_texture const specular;
|
||||||
|
float const shininess;
|
||||||
|
color_or_texture const reflective;
|
||||||
|
float const reflectivity;
|
||||||
|
color_or_texture const transparent;
|
||||||
|
float const transparency;
|
||||||
|
float const index_of_refraction;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lambert {
|
||||||
|
color_or_texture const emission;
|
||||||
|
color_or_texture const ambient;
|
||||||
|
color_or_texture const diffuse;
|
||||||
|
color_or_texture const reflective;
|
||||||
|
float const reflectivity;
|
||||||
|
color_or_texture const transparent;
|
||||||
|
float const transparency;
|
||||||
|
float const index_of_refraction;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct phong {
|
||||||
|
color_or_texture const emission;
|
||||||
|
color_or_texture const ambient;
|
||||||
|
color_or_texture const diffuse;
|
||||||
|
color_or_texture const specular;
|
||||||
|
float const shininess;
|
||||||
|
color_or_texture const reflective;
|
||||||
|
float const reflectivity;
|
||||||
|
color_or_texture const transparent;
|
||||||
|
float const transparency;
|
||||||
|
float const index_of_refraction;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct constant {
|
||||||
|
float4 const color;
|
||||||
|
color_or_texture const reflective;
|
||||||
|
float const reflectivity;
|
||||||
|
color_or_texture const transparent;
|
||||||
|
float const transparency;
|
||||||
|
float const index_of_refraction;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class effect_type {
|
||||||
|
BLINN,
|
||||||
|
LAMBERT,
|
||||||
|
PHONG,
|
||||||
|
CONSTANT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct effect {
|
||||||
|
effect_type const type;
|
||||||
|
union {
|
||||||
|
types::blinn const blinn;
|
||||||
|
types::lambert const lambert;
|
||||||
|
types::phong const phong;
|
||||||
|
types::constant const constant;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// node
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct lookat {
|
||||||
|
float3 const eye;
|
||||||
|
float3 const at;
|
||||||
|
float3 const up;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class transform_type {
|
||||||
|
LOOKAT,
|
||||||
|
MATRIX,
|
||||||
|
ROTATE,
|
||||||
|
SCALE,
|
||||||
|
SKEW,
|
||||||
|
TRANSLATE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct transform {
|
||||||
|
transform_type const type;
|
||||||
|
union {
|
||||||
|
types::lookat const lookat;
|
||||||
|
types::matrix const matrix;
|
||||||
|
float4 const rotate;
|
||||||
|
float3 const scale;
|
||||||
|
float7 const skew;
|
||||||
|
float3 const translate;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class node_type {
|
||||||
|
JOINT,
|
||||||
|
NODE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct material {
|
||||||
|
types::effect const * const effect;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bind_vertex_input {
|
||||||
|
int input_set; // TEXCOORD semantic input slot
|
||||||
|
};
|
||||||
|
|
||||||
|
struct instance_material {
|
||||||
|
int const element_index; // an index into mesh.triangles
|
||||||
|
types::material const * const material;
|
||||||
|
|
||||||
|
// heavily simplified from collada data model
|
||||||
|
bind_vertex_input const emission;
|
||||||
|
bind_vertex_input const ambient;
|
||||||
|
bind_vertex_input const diffuse;
|
||||||
|
bind_vertex_input const specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct instance_geometry {
|
||||||
|
types::geometry const * const geometry;
|
||||||
|
|
||||||
|
instance_material const * const instance_materials;
|
||||||
|
int const instance_materials_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct skin {
|
||||||
|
types::geometry const * const geometry; // source
|
||||||
|
|
||||||
|
matrix const bind_shape_matrix; // one per skin
|
||||||
|
matrix const * const inverse_bind_matrices; // one per joint
|
||||||
|
|
||||||
|
int const vertex_buffer_offset;
|
||||||
|
int const vertex_buffer_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct controller {
|
||||||
|
types::skin skin;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct instance_controller {
|
||||||
|
types::controller const * const controller;
|
||||||
|
|
||||||
|
//node const * const skeleton; // a reference to the root of the joint heirarchy
|
||||||
|
|
||||||
|
int const * const joint_node_indices; // one per joint
|
||||||
|
int const joint_count;
|
||||||
|
|
||||||
|
instance_material const * const instance_materials;
|
||||||
|
int const instance_materials_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct instance_light {
|
||||||
|
types::light const * const light;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// animation
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
enum class interpolation {
|
||||||
|
LINEAR,
|
||||||
|
BEZIER,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct source {
|
||||||
|
union {
|
||||||
|
float const * const float_array;
|
||||||
|
enum interpolation const * const interpolation_array;
|
||||||
|
};
|
||||||
|
int const count;
|
||||||
|
int const stride;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sampler {
|
||||||
|
source const input;
|
||||||
|
source const output;
|
||||||
|
source const in_tangent;
|
||||||
|
source const out_tangent;
|
||||||
|
source const interpolation;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class target_attribute {
|
||||||
|
A, // alpha color component
|
||||||
|
ANGLE, // euler angle
|
||||||
|
B, // blue color component
|
||||||
|
G, // green color component
|
||||||
|
P, // third texture component
|
||||||
|
Q, // fourth texture component
|
||||||
|
R, // red color component
|
||||||
|
S, // first texture coordinate
|
||||||
|
T, // second texture coordinate
|
||||||
|
TIME, // time in seconds
|
||||||
|
U, // first generic parameter
|
||||||
|
V, // second generic parameter
|
||||||
|
W, // fourth cartesian coordinate
|
||||||
|
X, // first cartesian coordinate
|
||||||
|
Y, // second cartesian coordinate
|
||||||
|
Z, // third cartesian coordinate
|
||||||
|
ALL,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct channel {
|
||||||
|
sampler const * const source_sampler;
|
||||||
|
int const target_node_index; // an index into the nodes array
|
||||||
|
int const target_transform_index;
|
||||||
|
types::target_attribute const target_attribute;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct animation {
|
||||||
|
animation const * const animations; // nested animations
|
||||||
|
int const animations_count;
|
||||||
|
|
||||||
|
channels const * const channels;
|
||||||
|
int const channels_count;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct camera {
|
||||||
|
float xfov;
|
||||||
|
float yfov;
|
||||||
|
float znear;
|
||||||
|
float zfar;
|
||||||
|
float aspect_ratio;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// scene
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct node {
|
||||||
|
char const * name;
|
||||||
|
|
||||||
|
int const parent_index;
|
||||||
|
|
||||||
|
node_type const type;
|
||||||
|
|
||||||
|
transform const * const transforms;
|
||||||
|
int const transforms_count;
|
||||||
|
|
||||||
|
instance_geometry const * const instance_geometries;
|
||||||
|
int const instance_geometries_count;
|
||||||
|
|
||||||
|
instance_controller const * const instance_controllers;
|
||||||
|
int const instance_controllers_count;
|
||||||
|
|
||||||
|
instance_light const * const instance_lights;
|
||||||
|
int const instance_lights_count;
|
||||||
|
|
||||||
|
channel const * const * const channels;
|
||||||
|
int const channels_count;
|
||||||
|
|
||||||
|
//node const * const * const nodes;
|
||||||
|
//int const nodes_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct descriptor {
|
||||||
|
// these are only the top-level nodes; nodes may have children
|
||||||
|
node const * const * const nodes;
|
||||||
|
int const nodes_count;
|
||||||
|
|
||||||
|
inputs const * const inputs_list;
|
||||||
|
int const inputs_list_count;
|
||||||
|
|
||||||
|
image const * const * const images;
|
||||||
|
int const images_count;
|
||||||
|
|
||||||
|
//animation const * const animations;
|
||||||
|
//int const animations_count;
|
||||||
|
|
||||||
|
// hmm, this part is not really platform-agnostic:
|
||||||
|
char const * const position_normal_texture_buffer;
|
||||||
|
char const * const joint_weight_buffer;
|
||||||
|
char const * const index_buffer;
|
||||||
|
};
|
||||||
|
}
|
||||||
7
game/include/collada_scene/ship20.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "collada/types.h"
|
||||||
|
|
||||||
|
namespace collada_scene::ship20 {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
253
game/include/collision.h
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "directxmath/directxmath.h"
|
||||||
|
|
||||||
|
namespace collision {
|
||||||
|
|
||||||
|
struct AABB {
|
||||||
|
XMVECTOR min;
|
||||||
|
XMVECTOR max;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Sphere {
|
||||||
|
XMVECTOR center;
|
||||||
|
float radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Capsule {
|
||||||
|
XMVECTOR a;
|
||||||
|
XMVECTOR b;
|
||||||
|
float radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline AABB cube_aabb(XMVECTOR const & center, float half)
|
||||||
|
{
|
||||||
|
half = fabsf(half);
|
||||||
|
XMVECTOR min = center + XMVectorReplicate(-half);
|
||||||
|
XMVECTOR max = center + XMVectorReplicate( half);
|
||||||
|
return AABB(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline XMVECTOR closest_point_point_aabb(XMVECTOR const & p, AABB const & aabb)
|
||||||
|
{
|
||||||
|
return XMVectorClamp(p, aabb.min, aabb.max);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool test_sphere_aabb(Sphere const & sphere, AABB const & aabb, XMVECTOR & point)
|
||||||
|
{
|
||||||
|
point = closest_point_point_aabb(sphere.center, aabb);
|
||||||
|
|
||||||
|
XMVECTOR v = point - sphere.center;
|
||||||
|
return XMVectorGetX(XMVector3Dot(v, v)) <= sphere.radius * sphere.radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void vector_swap_control(XMVECTOR & a, XMVECTOR & b, XMVECTOR const & control)
|
||||||
|
{
|
||||||
|
XMVECTOR tmp = XMVectorSelect(a, b, control);
|
||||||
|
b = XMVectorSelect(b, a, control);
|
||||||
|
a = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool intersect_ray_aabb(XMVECTOR const & point, XMVECTOR const & direction, AABB const & aabb, float & t_result, XMVECTOR & v_result)
|
||||||
|
{
|
||||||
|
// check parallel
|
||||||
|
XMVECTOR parallel = XMVectorLess(XMVectorAbs(direction), XMVectorSplatEpsilon());
|
||||||
|
XMVECTOR point_lt_aabb = XMVectorLess(point, aabb.min);
|
||||||
|
XMVECTOR point_gt_aabb = XMVectorGreater(point, aabb.max);
|
||||||
|
if (XMVectorGetX(parallel) != 0) // if (x < epsilon)
|
||||||
|
if (XMVectorGetX(point_lt_aabb) != 0 || XMVectorGetX(point_gt_aabb) != 0)
|
||||||
|
return false; // direction x is parallel and point x outside aabb
|
||||||
|
if (XMVectorGetY(parallel) != 0) // if (y < epsilon)
|
||||||
|
if (XMVectorGetY(point_lt_aabb) != 0 || XMVectorGetY(point_gt_aabb) != 0)
|
||||||
|
return false; // direction y is parallel and point y outside aabb
|
||||||
|
if (XMVectorGetZ(parallel) != 0) // if (z < epsilon)
|
||||||
|
if (XMVectorGetZ(point_lt_aabb) != 0 || XMVectorGetZ(point_gt_aabb) != 0)
|
||||||
|
return false; // direction z is parallel and point z outside aabb
|
||||||
|
|
||||||
|
XMVECTOR direction_reciprocal = XMVectorReciprocalEst(direction);
|
||||||
|
XMVECTOR t1 = (aabb.min - point) * direction_reciprocal;
|
||||||
|
XMVECTOR t2 = (aabb.max - point) * direction_reciprocal;
|
||||||
|
vector_swap_control(t2, t1, XMVectorGreater(t1, t2));
|
||||||
|
|
||||||
|
float tmin = XMVectorGetX(t1);
|
||||||
|
if (XMVectorGetY(t1) > tmin) tmin = XMVectorGetY(t1);
|
||||||
|
if (XMVectorGetZ(t1) > tmin) tmin = XMVectorGetZ(t1);
|
||||||
|
float tmax = XMVectorGetX(t2);
|
||||||
|
if (XMVectorGetY(t2) < tmax) tmax = XMVectorGetY(t2);
|
||||||
|
if (XMVectorGetZ(t2) < tmax) tmax = XMVectorGetZ(t2);
|
||||||
|
if (tmin > tmax) return false; // no intersection
|
||||||
|
|
||||||
|
t_result = tmin;
|
||||||
|
v_result = point + direction * tmin;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float clamp(float f, float min, float max)
|
||||||
|
{
|
||||||
|
if (f < min) return min;
|
||||||
|
if (f > max) return max;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void closest_point_segment_segment(XMVECTOR const & a1, XMVECTOR const & b1, // segment 1
|
||||||
|
XMVECTOR const & a2, XMVECTOR const & b2, // segment 2
|
||||||
|
float & t1, // (s)
|
||||||
|
float & t2, // (t)
|
||||||
|
XMVECTOR & c1, // closest point to segment 1
|
||||||
|
XMVECTOR & c2) // closest point to segment 2
|
||||||
|
{
|
||||||
|
const float epsilon = 1.192092896e-7f;
|
||||||
|
|
||||||
|
XMVECTOR d1 = b1 - a1;
|
||||||
|
XMVECTOR d2 = b2 - a2;
|
||||||
|
XMVECTOR r = a1 - a2;
|
||||||
|
float l1 = XMVectorGetX(XMVector3Dot(d1, d1)); // squared length of segment 1 (a)
|
||||||
|
float l2 = XMVectorGetX(XMVector3Dot(d2, d2)); // squared length of segment 2 (e)
|
||||||
|
float d1r = XMVectorGetX(XMVector3Dot(d1, r)); // (c)
|
||||||
|
float d2r = XMVectorGetX(XMVector3Dot(d2, r)); // (f)
|
||||||
|
|
||||||
|
if (l1 <= epsilon && l2 <= epsilon) {
|
||||||
|
// both segments are points
|
||||||
|
t1 = 0.0f;
|
||||||
|
t2 = 0.0f;
|
||||||
|
c1 = a1;
|
||||||
|
c2 = a2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (l1 <= epsilon) {
|
||||||
|
// segment 1 is a point
|
||||||
|
t1 = 0.0f;
|
||||||
|
t2 = clamp(d2r / l2, 0.0f, 1.0f);
|
||||||
|
} else if (l2 <= epsilon) {
|
||||||
|
// segment 2 is a point
|
||||||
|
t1 = clamp(-d1r / l1, 0.0, 1.0f);
|
||||||
|
t2 = 0.0f;
|
||||||
|
} else {
|
||||||
|
float b = XMVectorGetX(XMVector3Dot(d1, d2));
|
||||||
|
float denom = l1 * l2 - b * b;
|
||||||
|
if (denom != 0.0f) {
|
||||||
|
// segments are not parallel
|
||||||
|
t1 = clamp((b * d2r - d1r * l2) / denom, 0.0f, 1.0f);
|
||||||
|
} else {
|
||||||
|
t1 = 0.0f;
|
||||||
|
}
|
||||||
|
t2 = (b * t1 + d2r) / l2;
|
||||||
|
if (t2 < 0.0f) {
|
||||||
|
t2 = 0.0f;
|
||||||
|
t1 = clamp(-d1r / l1, 0.0f, 1.0f);
|
||||||
|
} else if (t2 > 1.0f) {
|
||||||
|
t2 = 1.0f;
|
||||||
|
t1 = clamp((b - d1r) / l1, 0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c1 = a1 + d1 * t1;
|
||||||
|
c2 = a2 + d2 * t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool intersect_capsule_capsule(Capsule const & capsule1, Capsule const & capsule2,
|
||||||
|
XMVECTOR & p1, XMVECTOR & p2)
|
||||||
|
{
|
||||||
|
float t1;
|
||||||
|
float t2;
|
||||||
|
XMVECTOR c1; // closest point in capsule1
|
||||||
|
XMVECTOR c2; // closest point in capsule2
|
||||||
|
closest_point_segment_segment(capsule1.a, capsule1.b,
|
||||||
|
capsule2.a, capsule2.b,
|
||||||
|
t1, t2,
|
||||||
|
c1, c2);
|
||||||
|
float distance2 = XMVectorGetX(XMVector3Dot(c1 - c2, c1 - c2));
|
||||||
|
float radius = capsule1.radius + capsule2.radius;
|
||||||
|
if (distance2 >= radius * radius)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float length = XMVectorGetX(XMVector3Length(c1 - c2));
|
||||||
|
XMVECTOR normal = XMVector3NormalizeEst(c2 - c1);
|
||||||
|
printf("length2 %f\n", capsule1.radius - length);
|
||||||
|
p1 = c1 + normal * capsule1.radius;
|
||||||
|
p2 = c2 + normal;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const float interval_epsilon = 0.001f;
|
||||||
|
|
||||||
|
static inline bool intersect_moving_sphere_aabb(Sphere const & sphere, XMVECTOR const & direction,
|
||||||
|
float t0, float t1, AABB const & aabb,
|
||||||
|
float & t, XMVECTOR & point)
|
||||||
|
{
|
||||||
|
float mid = (t0 + t1) * 0.5f;
|
||||||
|
XMVECTOR center = sphere.center + direction * mid;
|
||||||
|
float radius = (mid - t0) * XMVectorGetX(XMVector3Length(direction)) + sphere.radius;
|
||||||
|
Sphere bound(center, radius);
|
||||||
|
if (!test_sphere_aabb(bound, aabb, point))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (t1 - t0 < interval_epsilon) {
|
||||||
|
t = t0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intersect_moving_sphere_aabb(sphere, direction, t0, mid, aabb, t, point))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return intersect_moving_sphere_aabb(sphere, direction, mid, t1, aabb, t, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline AABB moving_sphere_aabb(Sphere const & sphere, XMVECTOR const & direction)
|
||||||
|
{
|
||||||
|
XMVECTOR min = sphere.center + XMVectorReplicate(-sphere.radius);
|
||||||
|
XMVECTOR max = sphere.center + XMVectorReplicate( sphere.radius);
|
||||||
|
|
||||||
|
min = XMVectorMin(min, min + direction);
|
||||||
|
max = XMVectorMax(max, max + direction);
|
||||||
|
return AABB(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct state {
|
||||||
|
float t;
|
||||||
|
bool intersected;
|
||||||
|
XMVECTOR intersection_point;
|
||||||
|
XMVECTOR intersection_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void check_collision(collision::Sphere const & sphere, XMVECTOR const & direction,
|
||||||
|
XMVECTOR const & cube_center, float cube_half,
|
||||||
|
state & state)
|
||||||
|
{
|
||||||
|
collision::AABB aabb = collision::cube_aabb(cube_center, cube_half);
|
||||||
|
float t;
|
||||||
|
XMVECTOR intersection_point;
|
||||||
|
bool intersected = collision::intersect_moving_sphere_aabb(sphere, direction,
|
||||||
|
0, 1, aabb,
|
||||||
|
t, intersection_point);
|
||||||
|
XMVECTOR intersection_position = sphere.center + direction * t;
|
||||||
|
if (intersected && t < state.t) {
|
||||||
|
state.t = t;
|
||||||
|
state.intersected = true;
|
||||||
|
state.intersection_point = intersection_point;
|
||||||
|
state.intersection_position = intersection_position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline XMVECTOR sphere_collision_response(Sphere const & sphere, XMVECTOR const & direction,
|
||||||
|
XMVECTOR const & intersection_point,
|
||||||
|
XMVECTOR const & intersection_position,
|
||||||
|
XMVECTOR & intersection_normal)
|
||||||
|
{
|
||||||
|
XMVECTOR origin = intersection_point;
|
||||||
|
XMVECTOR normal = XMVector3Normalize(intersection_position - intersection_point);
|
||||||
|
XMVECTOR destination = sphere.center + direction;
|
||||||
|
XMVECTOR distance = XMVector3Dot(destination, normal) - XMVector3Dot(normal, origin);
|
||||||
|
XMVECTOR new_destination = (destination - normal * distance) + normal * sphere.radius;
|
||||||
|
XMVECTOR new_direction = new_destination - intersection_position;
|
||||||
|
|
||||||
|
intersection_normal = normal;
|
||||||
|
|
||||||
|
return new_direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
game/include/collision_scene.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace collision_scene {
|
||||||
|
void load();
|
||||||
|
void draw();
|
||||||
|
void update(int up, int down, int left, int right,
|
||||||
|
int w, int s, int a, int d,
|
||||||
|
int t, int g, int f, int h,
|
||||||
|
int i, int k, int j, int l);
|
||||||
|
}
|
||||||
3
game/include/data/scenes/book.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace book {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
3
game/include/data/scenes/noodle.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace noodle {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
3
game/include/data/scenes/shadow_test.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace shadow_test {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
3
game/include/data/scenes/ship20.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace ship20 {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
127
game/include/dds.h
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// dds.h
|
||||||
|
//
|
||||||
|
// This header defines constants and structures that are useful when parsing
|
||||||
|
// DDS files. DDS files were originally designed to use several structures
|
||||||
|
// and constants that are native to DirectDraw and are defined in ddraw.h,
|
||||||
|
// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar
|
||||||
|
// (compatible) constants and structures so that one can use DDS files
|
||||||
|
// without needing to include ddraw.h.
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef _DDS_H_
|
||||||
|
#define _DDS_H_
|
||||||
|
|
||||||
|
#pragma pack(push,1)
|
||||||
|
|
||||||
|
#define DDS_MAGIC 0x20534444 // "DDS "
|
||||||
|
|
||||||
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
|
((unsigned int)(unsigned char)(ch0) | ((unsigned int)(unsigned char)(ch1) << 8) | \
|
||||||
|
((unsigned int)(unsigned char)(ch2) << 16) | ((unsigned int)(unsigned char)(ch3) << 24 ))
|
||||||
|
|
||||||
|
struct DDS_PIXELFORMAT
|
||||||
|
{
|
||||||
|
unsigned int dwSize;
|
||||||
|
unsigned int dwFlags;
|
||||||
|
unsigned int dwFourCC;
|
||||||
|
unsigned int dwRGBBitCount;
|
||||||
|
unsigned int dwRBitMask;
|
||||||
|
unsigned int dwGBitMask;
|
||||||
|
unsigned int dwBBitMask;
|
||||||
|
unsigned int dwABitMask;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||||
|
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||||
|
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||||
|
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||||
|
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DXT1 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DXT2 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DXT3 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DXT4 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DXT5 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_R8G8B8 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
|
||||||
|
|
||||||
|
const DDS_PIXELFORMAT DDSPF_R5G6B5 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 };
|
||||||
|
|
||||||
|
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
||||||
|
const DDS_PIXELFORMAT DDSPF_DX10 =
|
||||||
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||||
|
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||||
|
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
|
||||||
|
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||||
|
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||||
|
|
||||||
|
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||||
|
#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
||||||
|
#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX
|
||||||
|
|
||||||
|
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
||||||
|
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
||||||
|
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
||||||
|
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
||||||
|
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
||||||
|
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
||||||
|
|
||||||
|
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
|
||||||
|
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
|
||||||
|
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
|
||||||
|
|
||||||
|
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned int dwSize;
|
||||||
|
unsigned int dwHeaderFlags;
|
||||||
|
unsigned int dwHeight;
|
||||||
|
unsigned int dwWidth;
|
||||||
|
unsigned int dwPitchOrLinearSize;
|
||||||
|
unsigned int dwDepth; // only if DDS_HEADER_FLAGS_VOLUME is set in dwHeaderFlags
|
||||||
|
unsigned int dwMipMapCount;
|
||||||
|
unsigned int dwReserved1[11];
|
||||||
|
DDS_PIXELFORMAT ddspf;
|
||||||
|
unsigned int dwSurfaceFlags;
|
||||||
|
unsigned int dwCubemapFlags;
|
||||||
|
unsigned int dwReserved2[3];
|
||||||
|
} DDS_HEADER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
DXGI_FORMAT dxgiFormat;
|
||||||
|
D3D10_RESOURCE_DIMENSION resourceDimension;
|
||||||
|
unsigned int miscFlag;
|
||||||
|
unsigned int arraySize;
|
||||||
|
unsigned int reserved;
|
||||||
|
} DDS_HEADER_DXT10;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
#endif // _DDS_H
|
||||||
10
game/include/dds_validate.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "dds.h"
|
||||||
|
|
||||||
|
struct DDS_FILE {
|
||||||
|
unsigned int dwMagic;
|
||||||
|
DDS_HEADER header;
|
||||||
|
};
|
||||||
|
|
||||||
|
DDS_FILE const * dds_validate(void * data, unsigned int size, void ** out_data, int * out_size);
|
||||||
2221
game/include/directxmath/directxmath.h
Normal file
2187
game/include/directxmath/directxmathconvert.inl
Normal file
3413
game/include/directxmath/directxmathmatrix.inl
Normal file
2425
game/include/directxmath/directxmathmisc.inl
Normal file
14689
game/include/directxmath/directxmathvector.inl
Normal file
14
game/include/file.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern char const * g_source_path;
|
||||||
|
extern int g_source_path_length;
|
||||||
|
|
||||||
|
void * read_file(const char * filename, int * out_size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
7
game/include/flame.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace flame {
|
||||||
|
void load_program();
|
||||||
|
void load_texture();
|
||||||
|
void draw(unsigned int light_uniform_buffer, int light_count);
|
||||||
|
}
|
||||||
68
game/include/font.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace font {
|
||||||
|
|
||||||
|
struct font_desc {
|
||||||
|
char const * const path;
|
||||||
|
int const texture_width;
|
||||||
|
int const texture_height;
|
||||||
|
int const glyph_width;
|
||||||
|
int const glyph_height;
|
||||||
|
};
|
||||||
|
|
||||||
|
font_desc const terminus[] = {
|
||||||
|
{
|
||||||
|
.path = "font/terminus_128x64_6x12.data",
|
||||||
|
.texture_width = 128,
|
||||||
|
.texture_height = 64,
|
||||||
|
.glyph_width = 6,
|
||||||
|
.glyph_height = 12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/terminus_128x128_8x16.data",
|
||||||
|
.texture_width = 128,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 8,
|
||||||
|
.glyph_height = 16,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/terminus_256x128_10x18.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 10,
|
||||||
|
.glyph_height = 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/terminus_256x128_12x24.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 12,
|
||||||
|
.glyph_height = 24,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/terminus_256x256_16x32.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 256,
|
||||||
|
.glyph_width = 16,
|
||||||
|
.glyph_height = 32,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int const terminus_length = (sizeof (terminus)) / (sizeof (font_desc));
|
||||||
|
|
||||||
|
struct font {
|
||||||
|
font_desc const * desc;
|
||||||
|
unsigned int texture;
|
||||||
|
int stride;
|
||||||
|
struct {
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
} cell;
|
||||||
|
};
|
||||||
|
|
||||||
|
void load_shader();
|
||||||
|
font load_font(font_desc const& desc);
|
||||||
|
void load_fonts(font * const fonts, font_desc const * const descs, int length);
|
||||||
|
int best_font(font_desc const * const descs, int length);
|
||||||
|
void draw_start(font const& font, unsigned int vertex_array_object, unsigned int index_buffer);
|
||||||
|
int draw_string(font const& font, char const * const s, int x, int y);
|
||||||
|
}
|
||||||
68
game/include/font/bitmap.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace font::bitmap {
|
||||||
|
|
||||||
|
struct font_desc {
|
||||||
|
char const * const path;
|
||||||
|
int const texture_width;
|
||||||
|
int const texture_height;
|
||||||
|
int const glyph_width;
|
||||||
|
int const glyph_height;
|
||||||
|
};
|
||||||
|
|
||||||
|
font_desc const terminus[] = {
|
||||||
|
{
|
||||||
|
.path = "font/bitmap/terminus_128x64_6x12.data",
|
||||||
|
.texture_width = 128,
|
||||||
|
.texture_height = 64,
|
||||||
|
.glyph_width = 6,
|
||||||
|
.glyph_height = 12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/bitmap/terminus_128x128_8x16.data",
|
||||||
|
.texture_width = 128,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 8,
|
||||||
|
.glyph_height = 16,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/bitmap/terminus_256x128_10x18.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 10,
|
||||||
|
.glyph_height = 18,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/bitmap/terminus_256x128_12x24.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 128,
|
||||||
|
.glyph_width = 12,
|
||||||
|
.glyph_height = 24,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.path = "font/bitmap/terminus_256x256_16x32.data",
|
||||||
|
.texture_width = 256,
|
||||||
|
.texture_height = 256,
|
||||||
|
.glyph_width = 16,
|
||||||
|
.glyph_height = 32,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int const terminus_length = (sizeof (terminus)) / (sizeof (font_desc));
|
||||||
|
|
||||||
|
struct font {
|
||||||
|
font_desc const * desc;
|
||||||
|
unsigned int texture;
|
||||||
|
int stride;
|
||||||
|
struct {
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
} cell;
|
||||||
|
};
|
||||||
|
|
||||||
|
void load_shader();
|
||||||
|
void load_fonts(font * const fonts, font_desc const * const descs, int length);
|
||||||
|
int best_font(font_desc const * const descs, int length);
|
||||||
|
void draw_start(font const& font, unsigned int vertex_array_object, unsigned int index_buffer);
|
||||||
|
int draw_string(font const& font, char const * const s, int x, int y);
|
||||||
|
void set_base_color(float r, float g, float b);
|
||||||
|
}
|
||||||
29
game/include/font/outline.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "outline_types.h"
|
||||||
|
|
||||||
|
namespace font::outline {
|
||||||
|
|
||||||
|
struct font_desc {
|
||||||
|
char const * const path;
|
||||||
|
};
|
||||||
|
|
||||||
|
font_desc const uncial_antiqua[] = {
|
||||||
|
{
|
||||||
|
.path = "font/outline/uncial_antiqua_36.data",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int const uncial_antiqua_length = (sizeof (uncial_antiqua)) / (sizeof (font_desc));
|
||||||
|
|
||||||
|
struct font {
|
||||||
|
unsigned int texture;
|
||||||
|
types::font const * font;
|
||||||
|
types::glyph const * glyphs;
|
||||||
|
};
|
||||||
|
|
||||||
|
void load_shader();
|
||||||
|
void load_fonts(font * const fonts, font_desc const * const descs, int length);
|
||||||
|
|
||||||
|
void draw_start(font const& font, unsigned int vertex_array_object, unsigned int index_buffer);
|
||||||
|
int draw_string(font const& font, char const * const s, int x, int y);
|
||||||
|
}
|
||||||
49
game/include/font/outline_types.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// this file is designed to be platform-agnostic
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace font::outline::types {
|
||||||
|
|
||||||
|
// metrics are 26.6 fixed point
|
||||||
|
struct glyph_metrics {
|
||||||
|
int32_t horiBearingX;
|
||||||
|
int32_t horiBearingY;
|
||||||
|
int32_t horiAdvance;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
static_assert((sizeof (struct glyph_metrics)) == ((sizeof (int32_t)) * 3));
|
||||||
|
|
||||||
|
struct glyph_bitmap {
|
||||||
|
uint16_t x;
|
||||||
|
uint16_t y;
|
||||||
|
uint16_t width;
|
||||||
|
uint16_t height;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
static_assert((sizeof (struct glyph_bitmap)) == ((sizeof (uint16_t)) * 4));
|
||||||
|
|
||||||
|
struct glyph {
|
||||||
|
struct glyph_bitmap bitmap;
|
||||||
|
struct glyph_metrics metrics;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
static_assert((sizeof (struct glyph)) == ((sizeof (struct glyph_bitmap)) + (sizeof (struct glyph_metrics))));
|
||||||
|
|
||||||
|
struct font {
|
||||||
|
uint32_t first_char_code;
|
||||||
|
uint32_t last_char_code;
|
||||||
|
struct face_metrics {
|
||||||
|
int32_t height; // 26.6 fixed point
|
||||||
|
int32_t max_advance; // 26.6 fixed point
|
||||||
|
} face_metrics;
|
||||||
|
uint16_t glyph_count;
|
||||||
|
uint16_t _texture_stride;
|
||||||
|
uint16_t texture_width;
|
||||||
|
uint16_t texture_height;
|
||||||
|
uint32_t max_z_curve_ix;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
static_assert((sizeof (struct font)) == ((sizeof (uint32_t)) * 7));
|
||||||
|
|
||||||
|
}
|
||||||
80
game/include/geometry_buffer.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "glad/gl.h"
|
||||||
|
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
|
template <int render_target_count>
|
||||||
|
struct geometry_buffer {
|
||||||
|
unsigned int framebuffer;
|
||||||
|
unsigned int target[render_target_count]; // textures
|
||||||
|
unsigned int renderbuffer;
|
||||||
|
int initialized;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct target_type {
|
||||||
|
GLint internal_format;
|
||||||
|
GLenum attachment;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct target_name {
|
||||||
|
enum {
|
||||||
|
POSITION = 0,
|
||||||
|
NORMAL = 1,
|
||||||
|
COLOR = 2,
|
||||||
|
BLOCK = 3,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <int render_target_count>
|
||||||
|
void init_geometry_buffer(geometry_buffer<render_target_count>& geometry_buffer, target_type const * const types)
|
||||||
|
{
|
||||||
|
int width = window::width;
|
||||||
|
int height = window::height;
|
||||||
|
|
||||||
|
if ((geometry_buffer.initialized == 1) && (width == geometry_buffer.width) && (height == geometry_buffer.height)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geometry_buffer.initialized) {
|
||||||
|
glDeleteFramebuffers(1, &geometry_buffer.framebuffer);
|
||||||
|
glDeleteTextures(render_target_count, geometry_buffer.target);
|
||||||
|
glDeleteRenderbuffers(1, &geometry_buffer.renderbuffer);
|
||||||
|
}
|
||||||
|
glGenFramebuffers(1, &geometry_buffer.framebuffer);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, geometry_buffer.framebuffer);
|
||||||
|
|
||||||
|
glGenTextures(render_target_count, geometry_buffer.target);
|
||||||
|
for (int i = 0; i < render_target_count; i++) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, geometry_buffer.target[i]);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, types[i].internal_format, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, types[i].attachment, GL_TEXTURE_2D, geometry_buffer.target[i], 0);
|
||||||
|
}
|
||||||
|
static_assert(render_target_count <= 8);
|
||||||
|
static GLenum const attachments[8] = {
|
||||||
|
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
|
||||||
|
GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7,
|
||||||
|
};
|
||||||
|
glDrawBuffers(render_target_count, attachments); // bound to GL_DRAW_FRAMEBUFFER
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &geometry_buffer.renderbuffer);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, geometry_buffer.renderbuffer);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||||
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, geometry_buffer.renderbuffer);
|
||||||
|
|
||||||
|
assert(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
geometry_buffer.initialized = 1;
|
||||||
|
geometry_buffer.width = width;
|
||||||
|
geometry_buffer.height = height;
|
||||||
|
}
|
||||||
3205
game/include/glad/gl.h
Normal file
6
game/include/hash.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
inthash(const int32_t key);
|
||||||
6
game/include/hud.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace hud {
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
}
|
||||||
14
game/include/lighting.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace lighting {
|
||||||
|
|
||||||
|
struct light_parameters {
|
||||||
|
float quadratic;
|
||||||
|
float linear;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern light_parameters global;
|
||||||
|
|
||||||
|
void load();
|
||||||
|
void draw(unsigned int light_uniform_buffer, int light_count);
|
||||||
|
}
|
||||||
22
game/include/line_art.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "directxmath/directxmath.h"
|
||||||
|
|
||||||
|
namespace line_art {
|
||||||
|
void load();
|
||||||
|
|
||||||
|
void load_ray_vertex_buffer(XMVECTOR const & a, XMVECTOR const & b);
|
||||||
|
|
||||||
|
XMMATRIX view();
|
||||||
|
XMMATRIX projection();
|
||||||
|
|
||||||
|
void set_transform(XMMATRIX const & transform);
|
||||||
|
void draw_line(XMMATRIX const & transform, XMVECTOR const & a, XMVECTOR const & b);
|
||||||
|
void draw_sphere(XMMATRIX const & transform, XMVECTOR const & center, float radius);
|
||||||
|
void draw_capsule(XMMATRIX const & transform, XMVECTOR a, XMVECTOR b, float radius);
|
||||||
|
void draw_cube(XMMATRIX const & transform, XMVECTOR const & position);
|
||||||
|
void scene_start(XMMATRIX const & transform);
|
||||||
|
void draw_grid(XMMATRIX const & transform);
|
||||||
|
void set_color(float r, float g, float b);
|
||||||
|
void set_colorv(XMFLOAT3 const & value);
|
||||||
|
}
|
||||||
22
game/include/lua_api.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int draw_font_start();
|
||||||
|
int draw_font(int font_ix, char const * text, int x, int y);
|
||||||
|
|
||||||
|
int draw_font(int font_ix, char const * text, int x, int y);
|
||||||
|
void draw_font_set_base_color(float r, float g, float b);
|
||||||
|
|
||||||
|
void draw_line_quad_start();
|
||||||
|
void draw_line(int x1, int y1, int x2, int y2);
|
||||||
|
void draw_set_color(float r, float g, float b);
|
||||||
|
void draw_quad(int x1, int y1, int x2, int y2,
|
||||||
|
int x3, int y3, int x4, int y4);
|
||||||
|
|
||||||
|
void set_sphere(float x, float y, float vx, float vy);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
10
game/include/minecraft.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "world/world.h"
|
||||||
|
|
||||||
|
namespace minecraft {
|
||||||
|
extern world::state * current_world;
|
||||||
|
|
||||||
|
void load();
|
||||||
|
void draw();
|
||||||
|
}
|
||||||
22
game/include/minecraft_data.inc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
short index_buffer_configuration_offsets[] = {
|
||||||
|
0, 0, 6, 12, 24, 30, 42, 54,
|
||||||
|
72, 78, 90, 102, 120, 132, 150, 168,
|
||||||
|
192, 198, 210, 222, 240, 252, 270, 288,
|
||||||
|
312, 324, 342, 360, 384, 402, 426, 450,
|
||||||
|
480, 486, 498, 510, 528, 540, 558, 576,
|
||||||
|
600, 612, 630, 648, 672, 690, 714, 738,
|
||||||
|
768, 780, 798, 816, 840, 858, 882, 906,
|
||||||
|
936, 954, 978, 1002, 1032, 1056, 1086, 1116,
|
||||||
|
};
|
||||||
|
// generated from
|
||||||
|
struct {
|
||||||
|
short offset;
|
||||||
|
short count;
|
||||||
|
} index_buffer_custom_offsets[] = {
|
||||||
|
{1152, 3180}, // candle.obj
|
||||||
|
{4332, 1584}, // custom_mushroom.obj
|
||||||
|
{5916, 36}, // fence.obj
|
||||||
|
{5952, 24}, // stair.obj
|
||||||
|
{5976, 12}, // tall_grass.obj
|
||||||
|
{5988, 2082}, // wall_torch.obj
|
||||||
|
};
|
||||||
9
game/include/new.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T * New(int elements)
|
||||||
|
{
|
||||||
|
return (T *)aligned_alloc(16, (sizeof (T)) * elements);
|
||||||
|
}
|
||||||
13
game/include/non_block.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace non_block {
|
||||||
|
extern unsigned int index_buffer;
|
||||||
|
extern unsigned int per_vertex_buffer;
|
||||||
|
extern unsigned int vertex_array_object;
|
||||||
|
|
||||||
|
void load_index_buffer();
|
||||||
|
void load_per_vertex_buffer();
|
||||||
|
void load_vertex_attributes();
|
||||||
|
void load_program();
|
||||||
|
void draw();
|
||||||
|
}
|
||||||
17
game/include/opengl.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned int compile_from_files(const char * vertex_path,
|
||||||
|
const char * geometry_path,
|
||||||
|
const char * fragment_path);
|
||||||
|
|
||||||
|
unsigned int load_uniform_buffer(char const * const path, int * out_size);
|
||||||
|
|
||||||
|
void load_dds_texture_2D(char const * const path);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
12
game/include/pixel_line_art.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace pixel_line_art {
|
||||||
|
|
||||||
|
void load();
|
||||||
|
|
||||||
|
void draw_line_quad_start();
|
||||||
|
void draw_line(int x1, int y1, int x2, int y2);
|
||||||
|
void draw_set_color(float r, float g, float b);
|
||||||
|
void draw_quad(int x1, int y1, int x2, int y2,
|
||||||
|
int x3, int y3, int x4, int y4);
|
||||||
|
}
|
||||||
2941
game/include/sal.h
Normal file
26
game/include/test.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void load(const char * source_path);
|
||||||
|
void draw();
|
||||||
|
void love2d_state_load();
|
||||||
|
void love2d_state_restore();
|
||||||
|
void update_keyboard(int up, int down, int left, int right,
|
||||||
|
int w, int s, int a, int d,
|
||||||
|
int t, int g, int f, int h,
|
||||||
|
int i, int k, int j, int l);
|
||||||
|
void update_mouse(int x, int y);
|
||||||
|
void update_joystick(int joystick_index,
|
||||||
|
float lx, float ly, float rx, float ry, float tl, float tr,
|
||||||
|
int up, int down, int left, int right,
|
||||||
|
int a, int b, int x, int y,
|
||||||
|
int leftshoulder, int rightshoulder,
|
||||||
|
int start);
|
||||||
|
void update(float time);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
49
game/include/view.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "directxmath/directxmath.h"
|
||||||
|
|
||||||
|
namespace view {
|
||||||
|
struct view_state {
|
||||||
|
// positions
|
||||||
|
XMVECTOR eye;
|
||||||
|
XMVECTOR at;
|
||||||
|
|
||||||
|
// vectors
|
||||||
|
XMVECTOR up;
|
||||||
|
XMVECTOR forward;
|
||||||
|
XMVECTOR normal; // cross(forward, up)
|
||||||
|
XMVECTOR direction; // rotationaxis(forward, pitch)
|
||||||
|
|
||||||
|
// angles
|
||||||
|
float fov;
|
||||||
|
float pitch;
|
||||||
|
|
||||||
|
// transforms
|
||||||
|
XMMATRIX projection_transform;
|
||||||
|
XMMATRIX view_transform;
|
||||||
|
XMMATRIX transform;
|
||||||
|
|
||||||
|
// transform views
|
||||||
|
XMFLOAT4X4 float_transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern view_state state;
|
||||||
|
|
||||||
|
namespace first_person {
|
||||||
|
void apply_transform(float forward, float strafe, float elevation,
|
||||||
|
float delta_yaw, float delta_pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace third_person {
|
||||||
|
XMVECTOR apply_transform(float forward, float strafe, float elevation,
|
||||||
|
float delta_yaw, float delta_pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
XMVECTOR get_normal();
|
||||||
|
XMVECTOR get_direction();
|
||||||
|
void apply_fov(float delta);
|
||||||
|
void update_transforms();
|
||||||
|
void load();
|
||||||
|
|
||||||
|
const float at_distance = 10;
|
||||||
|
}
|
||||||
14
game/include/window.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace window {
|
||||||
|
extern float width;
|
||||||
|
extern float height;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
void update_window(int width, int height);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
27
game/include/world/entry_table.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
namespace world::entry_table {
|
||||||
|
|
||||||
|
typedef struct global_entry {
|
||||||
|
int global_index;
|
||||||
|
uint8_t block_id;
|
||||||
|
uint8_t block_data;
|
||||||
|
uint16_t _padding;
|
||||||
|
} global_entry_t;
|
||||||
|
static_assert((sizeof (global_entry_t)) == 8);
|
||||||
|
|
||||||
|
typedef uint32_t (hash_func_t)(const int32_t key);
|
||||||
|
|
||||||
|
void load_entry_table(char const * const path,
|
||||||
|
global_entry_t ** out_entry_table,
|
||||||
|
int * out_entry_table_length,
|
||||||
|
hash_func_t * hash_func);
|
||||||
|
|
||||||
|
global_entry_t * const world_lookup(hash_func_t * hash_func,
|
||||||
|
global_entry_t * entry_table,
|
||||||
|
int entry_table_length,
|
||||||
|
int x, int y, int z);
|
||||||
|
}
|
||||||
15
game/include/world/inthash.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint32_t love2dworld_hash(const int32_t key);
|
||||||
|
uint32_t grandlecturn_hash(const int32_t key);
|
||||||
|
uint32_t midnightmeadow_hash(const int32_t key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
54
game/include/world/world.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "world/entry_table.h"
|
||||||
|
|
||||||
|
namespace world {
|
||||||
|
struct vtx_cfg {
|
||||||
|
const char * vtx;
|
||||||
|
const char * cfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct descriptor {
|
||||||
|
int const region_count;
|
||||||
|
vtx_cfg const * const vertex_paths;
|
||||||
|
char const * const entry_table_path;
|
||||||
|
char const * const lights_path;
|
||||||
|
entry_table::hash_func_t * hash_func;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct world_id {
|
||||||
|
enum {
|
||||||
|
LOVE2DWORLD = 0,
|
||||||
|
GRANDLECTURN = 1,
|
||||||
|
MIDNIGHTMEADOW = 2,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// also update index_buffer_custom_offsets in include/minecraft_data.inc
|
||||||
|
const int custom_block_types = 6;
|
||||||
|
const int instance_cfg_length = 64 + custom_block_types;
|
||||||
|
|
||||||
|
struct instance_cfg_entry {
|
||||||
|
int count;
|
||||||
|
int offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct region {
|
||||||
|
unsigned int per_instance_vertex_buffer;
|
||||||
|
instance_cfg_entry instance_cfg[instance_cfg_length];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct state {
|
||||||
|
world::descriptor const * descriptor;
|
||||||
|
world::region * region; // malloc region_count
|
||||||
|
entry_table::global_entry_t * entry_table;
|
||||||
|
unsigned int light_uniform_buffer;
|
||||||
|
int light_count;
|
||||||
|
int entry_table_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern descriptor const descriptors[];
|
||||||
|
extern int const descriptors_length;
|
||||||
|
}
|
||||||
BIN
game/love_src/asset/image/arrow_right.png
Normal file
|
After Width: | Height: | Size: 620 B |
|
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 280 B |
|
Before Width: | Height: | Size: 496 B After Width: | Height: | Size: 496 B |
|
Before Width: | Height: | Size: 557 B After Width: | Height: | Size: 557 B |
|
Before Width: | Height: | Size: 643 B After Width: | Height: | Size: 643 B |
|
Before Width: | Height: | Size: 575 B After Width: | Height: | Size: 575 B |