From 9b0c118ae11763163d39c5bcaf4e271e2f3658a4 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 23 Mar 2026 03:57:14 -0500 Subject: [PATCH] world switching, re-enable lighting --- Makefile | 5 +++-- include/minecraft.h | 2 ++ shader/lighting.frag | 2 +- src/hud.cpp | 3 ++- src/minecraft.cpp | 5 ++--- src/test.cpp | 35 +++++++++++++++++++++++++++++++++++ src/view.cpp | 5 ++--- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 7c036f3..d6488cf 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,9 @@ all: test.so %.o: %.cpp $(CXX) $(ARCH) $(CXXSTD) $(CFLAGS) $(OPT) -c $< -o $@ -test.pack: pack_main - ./pack_main $@ $(shell cat filenames.txt) +PACK_FILENAMES = $(shell cat filenames.txt) +test.pack: pack_main $(PACK_FILENAMES) + ./pack_main $@ $(PACK_FILENAMES) test.pack.o: test.pack $(OBJCOPY) -I binary -O $(OBJARCH) $< $@ diff --git a/include/minecraft.h b/include/minecraft.h index c4d7470..bcdfcba 100644 --- a/include/minecraft.h +++ b/include/minecraft.h @@ -4,6 +4,8 @@ namespace minecraft { extern world::state * current_world; + static const int max_world_count = 10; + extern world::state world_state[max_world_count]; void load(); void draw(); diff --git a/shader/lighting.frag b/shader/lighting.frag index 1c86864..ab6e19f 100644 --- a/shader/lighting.frag +++ b/shader/lighting.frag @@ -26,7 +26,7 @@ void main() vec3 out_color = color.xyz * 0.1; - if (false) { + if (LightCount != 0) { for (int i = 0; i < LightCount; i++) { vec3 light_position = light[i].xzy + vec3(0, 0, 0.5); float light_distance = length(light_position - position.xyz); diff --git a/src/hud.cpp b/src/hud.cpp index 3a72e49..46f7b84 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -103,10 +103,11 @@ namespace hud { font::bitmap::draw_string(ter_best, " move: w/a/s/d", 10, y); y += ter_best.desc->glyph_height; font::bitmap::draw_string(ter_best, " look: up/down/left/right", 10, y); y += ter_best.desc->glyph_height; font::bitmap::draw_string(ter_best, " elevate: q/e", 10, y); y += ter_best.desc->glyph_height; + font::bitmap::draw_string(ter_best, " warp: l", 10, y); y += ter_best.desc->glyph_height; font::bitmap::draw_string(ter_best, "gamepad:", 10, y); y += ter_best.desc->glyph_height; font::bitmap::draw_string(ter_best, " move: right stick", 10, y); y += ter_best.desc->glyph_height; font::bitmap::draw_string(ter_best, " look: left stick", 10, y); y += ter_best.desc->glyph_height; - font::bitmap::draw_string(ter_best, " elevate: trigger left/right", 10, y); y += ter_best.desc->glyph_height; + font::bitmap::draw_string(ter_best, " warp: a", 10, y); y += ter_best.desc->glyph_height; if (frame++ > 60 * 10) return; diff --git a/src/minecraft.cpp b/src/minecraft.cpp index acbc908..f531d2c 100644 --- a/src/minecraft.cpp +++ b/src/minecraft.cpp @@ -45,8 +45,7 @@ namespace minecraft { static unsigned int texture; - static const int max_world_count = 10; - static world::state world_state[max_world_count]; + world::state world_state[max_world_count]; world::state * current_world; void load_program() @@ -272,7 +271,7 @@ namespace minecraft { for (int i = 0; i < world::descriptors_length; i++) { per_world::load_world(&world::descriptors[i], world_state[i]); } - current_world = &world_state[world::world_id::MIDNIGHTMEADOW]; + current_world = &world_state[world::world_id::GRANDLECTURN]; } static inline int popcount(int x) diff --git a/src/test.cpp b/src/test.cpp index 7cc0a95..6b6d526 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -292,6 +292,29 @@ void minecraft_view_update(XMVECTOR direction) view::state.eye = view::state.at - view::state.direction * view::at_distance; } +static int world_id = 0; + +void next_world() +{ + world_id += 1; + if (world_id == 2) + world_id = 0; + + if (world_id == 0) { + view::state.eye = XMVectorSet(4.71f, 65.30, 57.92, 1); + } else { + // midnightmeadow + view::state.eye = XMVectorSet(13.71f, -3.36, 92.92, 1); + } + view::state.at = view::state.eye + view::state.direction * view::at_distance; + + minecraft::current_world = &minecraft::world_state[world_id]; + + printf("next world\n"); +} + +static int last_l = 0; + 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, @@ -327,8 +350,15 @@ void update_keyboard(int up, int down, int left, int right, if (true) { minecraft_view_update(direction); } + + if (l && last_l == 0) { + next_world(); + } + last_l = l; } +static int last_a = 0; + 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, @@ -350,6 +380,11 @@ void update_joystick(int joystick_index, minecraft_view_update(direction); } + if (a && last_a == 0) { + next_world(); + } + last_a = a; + //view::state.eye = view::state.eye + direction; //view::state.at = view::state.at - view::state.direction * view::at_distance; diff --git a/src/view.cpp b/src/view.cpp index 60eb921..0fe8871 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -105,11 +105,10 @@ namespace view { // position // grandlecturn - //state.eye = XMVectorSet(4.71f, 65.30, 57.92, 1); + state.eye = XMVectorSet(4.71f, 65.30, 57.92, 1); // midnightmeadow - state.eye = XMVectorSet(13.71f, -3.36, 90.92, 1); - + //state.eye = XMVectorSet(13.71f, -3.36, 90.92, 1); state.at = state.eye + state.direction * at_distance; //state.at = XMVectorSet(0, 0, 0, 1); //state.eye = XMVectorSet(0, -100, 0, 1);