very crude update to new version of onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Jun 2023 02:53:47 +0000 (21:53 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Jun 2023 02:53:47 +0000 (21:53 -0500)
38 files changed:
onyx-pkg.ini
run_tree/lib/onyx_glfw3.so
run_tree/lib/onyx_opengles.so
run_tree/lib/stb_image.so
run_tree/lib/stb_truetype.so
run_tree/run.sh
server/run.sh
src/client/build.onyx
src/client/game.onyx
src/client/gfx/canvas.onyx
src/client/gfx/font.onyx
src/client/gfx/immediate.onyx
src/client/gfx/mesh.onyx
src/client/gfx/shader.onyx
src/client/gfx/texture.onyx
src/client/gfx/ui.onyx
src/client/globals.onyx
src/client/main.onyx
src/client/menu/connect_menu.onyx
src/client/net/handlers.onyx
src/client/net/net.onyx
src/client/net/outbound.onyx
src/client/utils/camera.onyx
src/client/utils/colors.onyx
src/client/utils/input.onyx
src/client/utils/logger.onyx
src/client/utils/utils.onyx
src/client/utils/vecmath.onyx
src/client/world/chunk.onyx
src/client/world/physics.onyx
src/client/world/player.onyx
src/client/world/player_manager.onyx
src/client/world/world.onyx
src/client/world/worldgen.onyx
src/config.onyx
src/server/build.onyx
src/server/server.onyx
src/shared/packets.onyx

index 93355acaca804d722fea603fedb263462109c500..a0f136c123ca1192aa55979a349c458b4bf7b927 100644 (file)
@@ -8,18 +8,21 @@ version=0.0.1
 [config]
 lib_source_directory=./lib
 lib_bin_directory=./run_tree/lib
+run_cmd=
+debug_cmd=
+test_cmd=
 
 [native_library]
 build_cmd=
 library=
 
 [dependencies]
-git://onyxlang.io/repo/onyx-net=0.0.3
-git://onyxlang.io/repo/glfw3=0.0.2
-git://onyxlang.io/repo/opengles=0.0.2
-git://onyxlang.io/repo/perlin=0.1.0
-git://onyxlang.io/repo/stb_image=0.0.2
-git://onyxlang.io/repo/stb_truetype=0.0.2
+git://onyxlang.io/repo/onyx-net=0.0.7
+git://onyxlang.io/repo/glfw3=0.0.3
+git://onyxlang.io/repo/opengles=0.0.8
+git://onyxlang.io/repo/perlin=0.1.1
+git://onyxlang.io/repo/stb_image=0.0.3
+git://onyxlang.io/repo/stb_truetype=0.0.3
 
 [dependency_folders]
 git://onyxlang.io/repo/onyx-net=onyx-net
index 168d72232358ac5bac3318ec34ec4ec33d726648..02169df0e9cdc35bf10a20009dbe3911872848f9 100755 (executable)
Binary files a/run_tree/lib/onyx_glfw3.so and b/run_tree/lib/onyx_glfw3.so differ
index 333ecb020151cd4f3ed26aea879d8d63b3b08d19..5c82218372a2710ecb76621086d2e9dbc708a77e 100755 (executable)
Binary files a/run_tree/lib/onyx_opengles.so and b/run_tree/lib/onyx_opengles.so differ
index a2305d7fa7ef57322449ce6b8b524c205176b446..da56c1e593ba3f69aab05c70a2006adcd181cc32 100755 (executable)
Binary files a/run_tree/lib/stb_image.so and b/run_tree/lib/stb_image.so differ
index 55c198d41a5003fc9cc3f03100103f50d5a534a7..00b4dbeed7ca1b033a8d34f18dececdf2c83dd26 100755 (executable)
Binary files a/run_tree/lib/stb_truetype.so and b/run_tree/lib/stb_truetype.so differ
index 7370e6921649d0a18e96c38c8a0c1aad454c52b3..47e6fbe40f212e5246648ee0f806ce67a196fd04 100755 (executable)
@@ -1,6 +1,7 @@
 
 case "$1" in
-    build) onyx -V build -I ../src/client -o game.wasm $@ ;;
-    debug) onyx-run --debug game.wasm ;;
-    *)     onyx-run game.wasm ;;
+    build) onyx build -V build -I ../src/client -o game.wasm $@ ;;
+    watch) onyx watch build.onyx -I ../src/client ;;
+    debug) onyx run --debug game.wasm ;;
+    *)     onyx run game.wasm ;;
 esac
index b740f252cd8d3d0f76e38c26dbc07f2589ec5bc4..bb9a16be64d8c00379447c92d20c2507e16a7e5a 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 case "$1" in
-    build) onyx -V build -I ../src/server -o server.wasm $@ ;;
+    build) onyx build -V build -I ../src/server -o server.wasm $@ ;;
     debug) onyx-run --debug server.wasm ;;
     *)     onyx-run server.wasm ;;
 esac
index 13681112222b52c0c2fd1679a0e0e0d8f9bf7ecf..5fc9521dee108205394d93228544cdf61d24f89c 100644 (file)
@@ -1,5 +1,3 @@
-#load "core/std"
-
 #load_path "./../src/client"
 #library_path "./lib"
 
@@ -16,9 +14,4 @@
 #load_all "./../shared"
 
 // Onyx modules
-#load "glfw3/module"
-#load "opengles/module"
-#load "perlin/module"
-#load "stb_image/module"
-#load "stb_truetype/module"
-#load "onyx-net/module"
+#load "./../lib/packages"
index 48b44202fcf015fa1c3cec1e558ff8fb7433fe87..f205f0878063faa77f37c65ddf099c415ee1e4b4 100644 (file)
@@ -1,8 +1,10 @@
 
-use core
-use glfw3
-use opengles
-use stb_truetype
+use core {*}
+use glfw3 {*}
+use opengles {*}
+use stb_truetype {*}
+use ui
+use game_net
 
 #local {
     world_shader: Shader;
@@ -12,7 +14,7 @@ use stb_truetype
     fog_color :: Vector3.{ 0.6, 0.6, 0.6 };
 }
 
-@Relocate // this global variables
+// @Relocate // this global variables
 font: Font;
 player: Player;
 world: ^World;
@@ -21,7 +23,9 @@ selected_block: Vector3i;
 
 player_shader: Shader;
 
-@Relocate
+world_chunk_update_thread: thread.Thread;
+
+// @Relocate
 world_fog_block: Shader_Block;
 World_Fog :: struct {
     u_fog_color: Vector3;
@@ -142,7 +146,7 @@ draw_scene :: () {
     player_manager->draw_players();
 }
 
-@Temporary
+// @Temporary
 chat_messages: [..] [] u8;
 
 draw_chat :: () {
index 862c451649ba4383fde55856e71cb5f57bfce34e..99c16bb27b3897805381bce41d511fa83a02c24a 100644 (file)
@@ -1,6 +1,6 @@
 
-use core
-use opengles
+use core {*}
+use opengles {*}
 
 
 Canvas :: struct {
index f9dee0d1ba7131f21c92553bab8ec303ee164fc4..3e51eabab5ca67b9fcd3f079bfe4b81cca18d79e 100644 (file)
@@ -1,7 +1,7 @@
 
-use core
-use stb_truetype
-use opengles
+use core {*}
+use stb_truetype {*}
+use opengles {*}
 
 #local {
     font_registry: Map(FontDescriptor, Font);
@@ -126,7 +126,7 @@ font_print :: (font: Font, x, y: f32, format: str, va: ..any) {
 }
 
 font_draw :: (font: Font, x, y: f32, msg: str) {
-    quads: ^stbtt_aligned_quad = alloc.from_stack(msg.count * sizeof stbtt_aligned_quad);
+    quads: [^] stbtt_aligned_quad = alloc.from_stack(msg.count * sizeof stbtt_aligned_quad);
     quad_num := 0;
 
     x_, y_ := x, y;
@@ -147,7 +147,7 @@ font_draw :: (font: Font, x, y: f32, msg: str) {
 }
 
 font_draw_centered :: (font: Font, x, y, max_width: f32, msg: str) {
-    quads: ^stbtt_aligned_quad = alloc.from_stack(msg.count * sizeof stbtt_aligned_quad);
+    quads: [^] stbtt_aligned_quad = alloc.from_stack(msg.count * sizeof stbtt_aligned_quad);
     quad_num := 0;
 
     width := font_get_width(font, msg);
@@ -259,9 +259,9 @@ FontDescriptor :: struct {
 #operator == (f1, f2: FontDescriptor) => f1.path == f2.path && f1.size == f2.size;
 
 font_lookup :: (fd := FontDescriptor.{ "assets/calibri.ttf", 12 }) -> Font {
-    if font_registry->has(fd) {
-        return font_registry[fd];
-    }
+    font_registry->get_opt(fd)->with([font] {
+        return font;
+    });
     
     font := font_make(fd);
     font_registry[fd] = font;
index f5fbed726430aaa9cc5fe4d9dd3c7c5208be8a02..887531d3f11b669354124b47e5b770589b7c1028 100644 (file)
@@ -1,7 +1,7 @@
 
-use core
-use opengles
-use glfw3
+use core {*}
+use opengles {*}
+use glfw3 {*}
 
 immediate_init :: () {
     vertex_data = make([] Immediate_Vertex, Maximum_Vertex_Count);
index 89f1946d281460056264d810e524be839d386c86..fb22edff069e2a19599644488178131235702578 100644 (file)
@@ -1,5 +1,6 @@
-use core
-use opengles
+use core {*}
+use opengles {*}
+use runtime
 
 Mesh :: struct (Vertex_Type: type_expr) {
     handle: GLint;
@@ -60,7 +61,7 @@ mesh_make :: (verticies: [] $T, indicies: [] u32, gl_hint := GL_STATIC_DRAW) ->
 }
 
 mesh_update_verticies :: (use mesh: ^Mesh, verticies: [] mesh.Vertex_Type) {
-    @TODO // Add bounds checking to arrays here.
+    // @TODO // Add bounds checking to arrays here.
 
     glBindBuffer(GL_ARRAY_BUFFER, vertex_handle);
     glBufferSubData(GL_ARRAY_BUFFER, 0, verticies.count * sizeof mesh.Vertex_Type, verticies.data);
index a00b4dc4682da2581e0fa15ff31d4c59d9fc8afc..5119aa23fa5e3d4c3c92d26dec1411258be7b1fc 100644 (file)
@@ -1,6 +1,7 @@
 
-use core
-use opengles
+use core {*}
+use opengles {*}
+use runtime
 
 Shader :: struct {
     vs, fs: GLuint;
index 0cf82726214f31fa519adb333fd68a3a465fc04e..869408dbbfa449a1967c1a0880837f74c8058cb6 100644 (file)
@@ -1,7 +1,7 @@
 
-use core
-use opengles
-use stb_image
+use core {*}
+use opengles {*}
+use stb_image {*}
 
 #local texture_cache: Map(str, Texture);
 
@@ -13,10 +13,10 @@ Texture :: struct {
 
 texture_lookup :: #match {}
 #match texture_lookup (filename: str) -> (Texture, bool) {
-    if texture_cache->has(filename) {
-        return texture_cache[filename], true;
-    }
-    
+    texture_cache->get_opt(filename)->with([texture] {
+        return texture, true;
+    });
+             
     buffer: [512] u8;
     memory.copy(~~ buffer, filename.data, math.min(filename.count, 511));
     return texture_lookup(cast(cstr) buffer);
@@ -24,9 +24,9 @@ texture_lookup :: #match {}
 
 #match texture_lookup (path: cstr) -> (Texture, bool) {
     filename := string.from_cstr(path);
-    if texture_cache->has(filename) {
-        return texture_cache[filename], true;
-    }
+    texture_cache->get_opt(filename)->with([texture] {
+        return texture, true;
+    });
 
     tex: Texture;
     tex.filename = filename;
index b807ef5f4391fb24356b40b3a1ba7b0d948b1668..daa7f1b2bcb9b6fd0a2458b8e874d2bc31507f01 100644 (file)
@@ -3,10 +3,10 @@
 //
 package ui
 
-use core
-use opengles
-use glfw3
-use main
+use core {package, *}
+use opengles {*}
+use glfw3 {*}
+use main {*}
 
 UI_Id :: u32
 
@@ -119,7 +119,7 @@ Slider_Theme :: struct {
 
     box_color        := Color.{ 0.1, 0.1, 0.1 };
     box_border_color := Color.{ 0.2, 0.2, 0.2 };
-    box_border_width := 4.0f;   @InPixels
+    box_border_width := 4.0f;   // @InPixels
 
     bar_color                := Color.{ 0.4, 0.4, 0.4 };
     bar_hover_color          := Color.{ 0, 0, 1 };
@@ -205,10 +205,10 @@ Textbox_Theme :: struct {
     click_color      := Color.{ 0.5, 0.5, 0.7 };
 
     border_color := Color.{ 0.2, 0.2, 0.2 };
-    border_width := 6.0f;   @InPixels
+    border_width := 6.0f;   // @InPixels
 
     cursor_color := Color.{ 0.5, 0.5, 0.5 };
-    cursor_width := 4.0f;   @InPixels
+    cursor_width := 4.0f;   // @InPixels
     cursor_blink_speed := 0.04f;   // Bigger is faster
 
     placeholder_text_color := Color.{ 0.5, 0.5, 0.5 };
@@ -224,7 +224,7 @@ Textbox_Theme :: struct {
         cursor_animation := 0.0f;
         cursor_animation_speed := 0.02f;
 
-        @HACK // Otherwise the action keys are evaluated every frame.
+        // @HACK // Otherwise the action keys are evaluated every frame.
         action_key_timeout := 0.0f;
     }
 
@@ -467,8 +467,8 @@ Checkbox_Theme :: struct {
     use animation_theme := Animation_Theme.{};
 
     box_color        := Color.{ 0.2, 0.2, 0.2 };
-    box_border_width := 4.0f;    @InPixels
-    box_size         := 20.0f;   @InPixels
+    box_border_width := 4.0f;    // @InPixels
+    box_size         := 20.0f;   // @InPixels
 
     checked_color       := Color.{ 1, 0, 0 };
     checked_hover_color := Color.{ 1, 0.6, 0.6 };
@@ -558,8 +558,8 @@ Radio_Theme :: struct {
     use animation_theme := Animation_Theme.{};
 
     box_color        := Color.{ 0.2, 0.2, 0.2 };
-    box_border_width := 4.0f;    @InPixels
-    box_size         := 20.0f;   @InPixels
+    box_border_width := 4.0f;    // @InPixels
+    box_size         := 20.0f;   // @InPixels
 
     checked_color       := Color.{ 0, 0, 1 };
     checked_hover_color := Color.{ 0.6, 0.6, 1 };
index 4776e63849c482f2eafbb1702bbe4be9489d3707..53be2f1ef32f0a6c9295fef49862e6aea1004fbd 100644 (file)
@@ -1,5 +1,5 @@
 
 use glfw3 { GLFWwindow_p }
-@GlobalVariable window: GLFWwindow_p;
+window: GLFWwindow_p;
 
 debug_screen := false;
index 6ae413bf2dcdbd39f072818c051353b20e8582a7..1cc48fceb617d2b3db1d48f57e4d8aceb40fc620 100644 (file)
@@ -1,8 +1,11 @@
 
-use core
-use glfw3
-use opengles
+use core {*}
+use glfw3 {*}
+use opengles {*}
 use core.intrinsics.onyx { __initialize }
+use runtime
+use ui
+use game_net
 
 State :: struct {
     data:   rawptr;
@@ -98,12 +101,12 @@ create_window :: () => {
 
     glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
-    glfwSetWindowSizeCallback(window, "on_resize");
+    glfwSetWindowSizeCallback(window, #export_name on_resize);
 
     return window;
 }
 
-#export "on_resize" (window: GLFWwindow_p, width, height: u32) {
+on_resize :: (window: GLFWwindow_p, width, height: u32) {
     glViewport(0, 0, width, height);
     camera_set_window_size(^camera, ~~width, ~~height);
     update_view_matrix();
index 19be689f22ef9da74a238ce46c1002c51f15e460..14069ea05fd1a88e3c2ed1978617f4e5dab50ec5 100644 (file)
@@ -1,7 +1,10 @@
 
-use core
-use glfw3
-use opengles
+use core {*}
+use glfw3 {*}
+use opengles {*}
+use game_net
+use runtime
+use ui
 
 #local {
     ip_addr: [..] u8;
@@ -19,7 +22,7 @@ Connect_Menu :: struct {
 
         title_font = font_lookup(.{"./assets/fonts/calibri.ttf", 64});
 
-        @HACK @HACK @HACK
+        // @HACK // @HACK // @HACK
         player_manager = new(Player_Manager);
     }
 
index 19f315642a35e9bafa79d665974b73ec623b7b95..a56d8157df4b96e687f487e5853fe6716470446c 100644 (file)
@@ -1,20 +1,19 @@
 package game_net
 
-#local {
-    use core
-    use main   
-    onet :: onyx_net
-}
+use core {*}
+use main {*}
+use packets
+use onyx_net { onet :: package }
 
-#tag Packet_Handler.{ .Verify_Connect }
-#local handle_verify_connect :: (packet: ^packets.Verify_Connect) {
+@Packet_Handler.{ .Verify_Connect }
+(packet: ^packets.Verify_Connect) {
     player_manager.player_id = packet.player_id;
 
     push_game_state(Game_State, null);
 }
 
-#tag Packet_Handler.{ .Player_Joined }
-#local handle_player_joined :: (packet: ^packets.Player_Joined) {
+@Packet_Handler.{ .Player_Joined }
+(packet: ^packets.Player_Joined) {
     name := packet->name();
     player_manager->add_player(packet.player_id, name);
 
@@ -23,17 +22,17 @@ package game_net
     }
 }
 
-#tag Packet_Handler.{ .Connection_Rejected }
-#local handle_connection_rejected :: (packet: ^packets.Connection_Rejected) {
-    @NetworkErrors // Handle this case.
+@Packet_Handler.{ .Connection_Rejected }
+(packet: ^packets.Connection_Rejected) {
+    // @NetworkErrors // Handle this case.
     printf("Connection refused: {}\n", packet.reason);
 
     pop_game_state();
     push_game_state(Connect_Menu, null);
 }
 
-#tag Packet_Handler.{ .Chat_Message }
-#local handle_chat_message :: (packet: ^packets.Chat_Message) {
+@Packet_Handler.{ .Chat_Message }
+(packet: ^packets.Chat_Message) {
     buf: [1024] u8;
     msg: str;
 
@@ -47,8 +46,8 @@ package game_net
     chat_messages << string.alloc_copy(msg);
 }
 
-#tag Packet_Handler.{ .Player_Moved }
-#local handle_player_moved :: (packet: ^packets.Player_Moved) {
+@Packet_Handler.{ .Player_Moved }
+(packet: ^packets.Player_Moved) {
     if packet.player_id == player_manager.player_id do return;
 
     player := player_manager->get_player(packet.player_id);
@@ -58,8 +57,8 @@ package game_net
     player.on_ground = packet.on_ground;
 }
 
-#tag Packet_Handler.{ .Block_Updates }
-#local handle_block_updates :: (packet: ^packets.Block_Updates) {
+@Packet_Handler.{ .Block_Updates }
+(packet: ^packets.Block_Updates) {
     updates := packet->updates();
     for updates {
         pos := it.position;
index b6528d2e5ce2e0b48cc2f9b4d7af47dac053fe77..a984d025a4da717e6c9917a97e2c8f5d74a9fa47 100644 (file)
@@ -1,13 +1,12 @@
 package game_net
 
-#local {
-    use core
-    use main
-    onet :: onyx_net
-}
+use core {*}
+use main {*}
+use packets
+use onyx_net { onet :: package }
 
 register_handles :: () {
-    use runtime.info;
+    use runtime.info {*};
 
     procs := get_procedures_with_tag(Packet_Handler);
     defer delete(^procs);
@@ -15,14 +14,14 @@ register_handles :: () {
         packet_handles[it.tag.type] = *cast(^(rawptr) -> void) ^it.func;
     }
 
-    println(packet_handles);
+    printf("{p}\n", packet_handles);
 }
 
 connect :: (ip_addr: [] u8, port: u16) {
     addr: net.Socket_Address;
     addr.addr = net.str_to_ipv4(ip_addr);
     addr.port = port;
-    host', _ := onet.host_create(null, 1);
+    host~, _ := onet.host_create(null, 1);
     peer = onet.host_connect(host, ^addr, 2);
 }
 
@@ -73,4 +72,4 @@ Packet_Handler :: struct {
     on_connect_callback: On_Connect_Callback;
 
     any_to_buffer :: macro (x: ^$T) => ([] u8).{ ~~x, sizeof T };
-}
\ No newline at end of file
+}
index 16b189600a5f6a5a114d40a9c9395392da73949c..ed96a38ebc9268e7eb5c4f7481b7ec097c5cfa20 100644 (file)
@@ -1,10 +1,10 @@
 package game_net
 
-#local {
-    use core
-    use main
-    onet :: onyx_net
-}
+use core {*}
+use main {*}
+use packets
+use onyx_net { onet :: package }
+use runtime
 
 send_connect :: (name: str) {
     msg := cast(^packets.Connect) calloc(sizeof packets.Connect + name.count);
@@ -64,7 +64,7 @@ send_block_updates :: (updates: [] packets.Block_Updates.Update) {
     block_updates.type = .Block_Updates;
     block_updates.update_count = ~~updates.count;
 
-    block_update := cast(^packets.Block_Updates.Update) ^block_updates.update_data;
+    block_update := cast([^]packets.Block_Updates.Update) ^block_updates.update_data;
     for updates.count {
         block_update[it].position  = updates[it].position;
         block_update[it].new_block = updates[it].new_block;
index 1e701b17858dd76061f3d989c861fd6e3d044d01..388f0966a33d16e8961d4976e05148aea24023fe 100644 (file)
@@ -1,6 +1,6 @@
-use core
+use core {*}
 
-@GlobalVariable
+// @GlobalVariable
 camera: Camera;
 
 Camera :: struct {
index b8f18f20a7a8bc8c76b5ddf2772e0c47114c876d..36fbf39fcef9f9a75bf4a57800a8f70d60c3862f 100644 (file)
@@ -1,5 +1,5 @@
 
-use core
+use core {*}
 
 Color :: struct {
     r, g, b :  f32;
index 6ae5a5707e26628f5c2d70494ef08f125f184d2b..53e84683c35dba6443f4278b4d0937497ce59cdc 100644 (file)
@@ -1,5 +1,5 @@
-use core
-use glfw3
+use core {package, *}
+use glfw3 {*}
 
 // If you are offseting the mouse coordinate for world space
 // or UI scrolling etc., set this function to be the function
@@ -32,8 +32,10 @@ Key_Descriptor :: struct {
     key: u32;
     scancode: u32 = 0;
     mod: u32      = 0;
+
+    hash :: (use this: Key_Descriptor) => core.hash.to_u32(key);
 }
-#match hash.to_u32 (use x: Key_Descriptor) => hash.to_u32(key);
+
 #operator == macro (x, y: Key_Descriptor) => x.key == y.key;
 
 input_update :: () {
index 8d76c714cd975674695ba27cb54100bcf1013bbc..4e1ff1aa96b167b862af6ef9d510a9a0e3e7cc7d 100644 (file)
@@ -2,7 +2,7 @@
 // This may become an in-game or external file logger in the future,
 // but for now this is just for logging to the command line.
 
-use core
+use core {*}
 
 Enable_Log_Colors :: false
 
@@ -54,4 +54,4 @@ debug_log_va :: (level: Log_Level, format: str, args: [] any) {
     return "";
 }
 
-#local log_level := Log_Level.Debug;
\ No newline at end of file
+#local log_level := Log_Level.Debug;
index 5b3c592e334c1c5cd904e74a6c09d7fe6f8bac5b..79764696ce46724f4c4c6af61a62b298b550decb 100644 (file)
@@ -1,4 +1,4 @@
-use core
+use core {*}
 
 Ray :: struct {
     origin, direction: Vector3;
index dc91d55ae9b70733fd43956505402af5792347b1..f7e512cbc3d7c54ae5bfe0fe81d4d62e1aa98bb6 100644 (file)
@@ -1,25 +1,27 @@
+use core {package, math}
+
 #tag conv.Custom_Format.{format_vector2i}
 #tag conv.Custom_Parse.{parse_vector2i}
 Vector2i :: struct {
     x, y: i32;
-    
 }
 
 #tag conv.Custom_Format.{format_vector2}
 #tag conv.Custom_Parse.{parse_vector2}
 Vector2 :: struct {
     x, y: f32;
+}
 
-    mag :: macro (v: Vector2) => math.sqrt(v.x * v.x + v.y * v.y);
+#inject Vector2 {
+    mag :: (v: Vector2) => math.sqrt(v.x * v.x + v.y * v.y);
 
-    square_mag :: macro (v: Vector2) => v.x * v.x + v.y * v.y;
+    square_mag :: (v: Vector2) => v.x * v.x + v.y * v.y;
 
-    norm :: macro (v: Vector2) -> Vector2 {
+    norm :: (v: Vector2) -> Vector2 {
         l := math.sqrt(v.x * v.x + v.y * v.y);
         return .{ v.x / l, v.y / l };
     }
 
-
     Zero :: Vector2.{0, 0}
 }
 
@@ -28,26 +30,36 @@ Vector3i :: struct {
     x, y, z: i32;
 }
 
+#inject Vector3i {
+    manhattan_dist :: (v1, v2: Vector3i) => {
+        return math.abs(v1.x - v2.x)
+             + math.abs(v1.y - v2.y)
+             + math.abs(v1.z - v2.z);
+    }
+}
+
 #tag conv.Custom_Format.{format_vector3}
 Vector3 :: struct {
     x, y, z: f32;
+}
 
-    mag :: macro (v: Vector3) => math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
+#inject Vector3 {
+    mag :: (v: Vector3) => math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
 
-    square_mag :: macro (v: Vector3) => v.x * v.x + v.y * v.y + v.z * v.z;
+    square_mag :: (v: Vector3) => v.x * v.x + v.y * v.y + v.z * v.z;
 
-    neg :: macro (v: Vector3) => Vector3.{ -v.x, -v.y, -v.z };
+    neg :: (v: Vector3) => Vector3.{ -v.x, -v.y, -v.z };
 
-    dot :: macro (v1, v2: Vector3) -> f32 {
+    dot :: (v1, v2: Vector3) -> f32 {
         return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
     }
 
-    norm :: macro (v: Vector3) -> Vector3 {
+    norm :: (v: Vector3) -> Vector3 {
         l := math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
         return .{ v.x / l, v.y / l, v.z / l };
     }
 
-    cross :: macro (v1, v2: Vector3) -> Vector3 {
+    cross :: (v1, v2: Vector3) -> Vector3 {
         return .{
             v1.y * v2.z - v1.z * v2.y,
             v1.z * v2.x - v1.x * v2.z,
@@ -55,7 +67,7 @@ Vector3 :: struct {
         };
     }
 
-    clamp :: macro (v: Vector3, min: Vector3, max: Vector3) -> Vector3 {
+    clamp :: (v: Vector3, min: Vector3, max: Vector3) -> Vector3 {
         return .{
             math.clamp(v.x, min.x, max.x),
             math.clamp(v.y, min.y, max.y),
@@ -64,30 +76,30 @@ Vector3 :: struct {
     }
 }
 
-#operator + macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };
-#operator - macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x - v2.x, v1.y - v2.y };
-#operator * macro (v: Vector2i, s: i32) => (typeof v ).{ v.x * s,     v.y * s     };
-#operator * macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x * v2.x, v1.y * v2.y };
-#operator == macro (v1, v2: Vector2i)  => v1.x == v2.x && v1.y == v2.y;
-#match core.hash.to_u32 macro (v: Vector2i) => 13 * v.x + 17 * v.y;
-
-#operator + macro (v1, v2: Vector2)    => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };
-#operator - macro (v1, v2: Vector2)    => (typeof v1).{ v1.x - v2.x, v1.y - v2.y };
-#operator * macro (v: Vector2, s: f32) => (typeof v ).{ v.x * s,     v.y * s     };
-#operator * macro (v1, v2: Vector2)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y };
-#operator == macro (v1, v2: Vector2)   => v1.x == v2.x && v1.y == v2.y;
-
-#operator + macro (v1, v2: Vector3)    => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
-#operator - macro (v1, v2: Vector3)    => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
-#operator * macro (v: Vector3, s: f32) => Vector3.{ v.x * s,     v.y * s,     v.z * s };
-#operator * macro (v1, v2: Vector3)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
-#operator == macro (v1, v2: Vector3)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
-
-#operator + macro (v1, v2: Vector3i)    => Vector3i.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
-#operator - macro (v1, v2: Vector3i)    => Vector3i.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
-#operator * macro (v: Vector3i, s: i32) => Vector3i.{ v.x * s,     v.y * s,     v.z * s };
-#operator * macro (v1, v2: Vector3i)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
-#operator == macro (v1, v2: Vector3i)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
+#operator + (v1, v2: Vector2i)   => Vector2i.{ v1.x + v2.x, v1.y + v2.y };
+#operator - (v1, v2: Vector2i)   => Vector2i.{ v1.x - v2.x, v1.y - v2.y };
+#operator * (v: Vector2i, s: i32) => Vector2i.{ v.x * s,     v.y * s     };
+#operator * (v1, v2: Vector2i)   => Vector2i.{ v1.x * v2.x, v1.y * v2.y };
+#operator == (v1, v2: Vector2i)  => v1.x == v2.x && v1.y == v2.y;
+#match core.hash.to_u32 (v: Vector2i) => 13 * v.x + 17 * v.y;
+
+#operator + (v1, v2: Vector2)    => Vector2.{ v1.x + v2.x, v1.y + v2.y };
+#operator - (v1, v2: Vector2)    => Vector2.{ v1.x - v2.x, v1.y - v2.y };
+#operator * (v:  Vector2, s: f32) => Vector2.{ v.x * s,     v.y * s     };
+#operator * (v1, v2: Vector2)    => Vector2.{ v1.x * v2.x, v1.y * v2.y };
+#operator == (v1, v2: Vector2)   => v1.x == v2.x && v1.y == v2.y;
+
+#operator + (v1, v2: Vector3)    => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+#operator - (v1, v2: Vector3)    => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+#operator * (v: Vector3, s: f32) => Vector3.{ v.x * s,     v.y * s,     v.z * s };
+#operator * (v1, v2: Vector3)    => Vector3.{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
+#operator == (v1, v2: Vector3)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
+
+#operator + (v1, v2: Vector3i)    => Vector3i.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+#operator - (v1, v2: Vector3i)    => Vector3i.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+#operator * (v: Vector3i, s: i32) => Vector3i.{ v.x * s,     v.y * s,     v.z * s };
+#operator * (v1, v2: Vector3i)    => Vector3i.{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
+#operator == (v1, v2: Vector3i)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
 
 #local {
     conv :: core.conv
@@ -139,7 +151,9 @@ Vector3 :: struct {
 
 Rect :: struct {
     x, y, w, h: f32;
+}
 
+#inject Rect {
     intersects :: (r1, r2: Rect) -> bool {
         return r1.x < r2.x + r2.w
             && r1.x + r1.w > r2.x
@@ -152,10 +166,10 @@ Rect :: struct {
             && r.y <= p.y && r.y + r.h >= p.y;
     }
 
-    center :: macro (use r: Rect) => Vector2.{ r.x+r.w/2, r.y+r.h/2 };
+    center :: (use r: Rect) => Vector2.{ r.x+r.w/2, r.y+r.h/2 };
 
-    top_left     :: macro (use r: Rect) => Vector2.{ r.x,   r.y   };
-    top_right    :: macro (use r: Rect) => Vector2.{ r.x+r.w, r.y   };
-    bottom_left  :: macro (use r: Rect) => Vector2.{ r.x,   r.y+r.h };
-    bottom_right :: macro (use r: Rect) => Vector2.{ r.x+r.w, r.y+r.h };
+    top_left     :: (use r: Rect) => Vector2.{ r.x,   r.y   };
+    top_right    :: (use r: Rect) => Vector2.{ r.x+r.w, r.y   };
+    bottom_left  :: (use r: Rect) => Vector2.{ r.x,   r.y+r.h };
+    bottom_right :: (use r: Rect) => Vector2.{ r.x+r.w, r.y+r.h };
 }
index 4a280ca29c1bf638bf9892111b3f92c85f8f9f6d..9b7ebc35eeb38de3ea2f60827774e938a09b8ca5 100644 (file)
@@ -1,5 +1,5 @@
-use core
-use opengles
+use core {*}
+use opengles {*}
 
 Chunk_Vertex :: struct {
     position : Vector3;
@@ -42,7 +42,7 @@ chunk_make :: (x, y, z: i32, allocator := context.allocator) -> ^Chunk {
 chunk_free :: (chunk: ^Chunk) {
     chunk_destroy_mesh(chunk);
     delete(^chunk.blocks);
-    delete(chunk);
+    cfree(chunk);
 }
 
 #local in_chunk_bounds :: macro (x, y, z: i32) -> bool {
@@ -167,7 +167,7 @@ chunk_destroy_mesh :: (use chunk: ^Chunk) {
 #local block_texture: Texture;
 chunk_draw :: (chunk: ^Chunk) {
     if block_texture.filename.data == null {
-        block_texture', _ := texture_lookup("assets/textures/block.png");
+        block_texture~, _ := texture_lookup("assets/textures/block.png");
     }
 
     texture_use(^block_texture);
@@ -188,7 +188,7 @@ chunk_foreach :: macro (chunk: ^Chunk, body: Code) {
 chunk_highlight_block :: (x, y, z: f32) {
     data := 0xf000;
 
-    vertex_data := cast(^Chunk_Vertex) alloc.from_stack(sizeof Chunk_Vertex * 8);
+    vertex_data := cast([&] Chunk_Vertex) alloc.from_stack(sizeof Chunk_Vertex * 8);
     vertex_data[0] = .{.{x-0.001,y-0.001,z-0.001},.{0,0},data};
     vertex_data[1] = .{.{x-0.001,y+1.001,z-0.001},.{0,0},data};
     vertex_data[2] = .{.{x+1.001,y+1.001,z-0.001},.{0,0},data};
index 5406d1530334725f57565e54079fc36c76f9af7f..13429078f63a1f115c8bd8d8a52710cc3242ad48 100644 (file)
@@ -1,4 +1,4 @@
-use core
+use core {*}
 
 AABB :: struct {
     x0, y0, z0, x1, y1, z1: f32;
index 5d6d18fa6bd7bcad46e752c8db912fde4453820c..3565e9abe81e1c489e629c8ac59681b498dfe5dd 100644 (file)
@@ -1,5 +1,6 @@
-use core
-use glfw3
+use core {*}
+use glfw3 {*}
+use game_net
 
 Player :: struct {
     camera: ^Camera; // Should the camera exist on the player? Or should the player just control the camera?
index 05bf4e637e2fa7161e37217c7a29617b3e7503cb..b15b4f27c5006ad0e1414a415b55315a40957016 100644 (file)
@@ -1,4 +1,4 @@
-use core
+use core {*}
 
 Remote_Player :: struct {
     name: str;
@@ -44,4 +44,4 @@ Player_Manager :: struct {
             mesh_draw(Meshes.white_box);
         }
     }
-}
\ No newline at end of file
+}
index 66d5d5d48722d8e5ad61daaa21e332a5274abfec..2dde6a07a18edb21ff678392711220128d905e6f 100644 (file)
@@ -1,5 +1,5 @@
 
-use core
+use core {*}
 
 World :: struct {
     chunk_dist: i32;
@@ -8,17 +8,21 @@ World :: struct {
     center_chunk: Vector3i;
 
     chunks_to_load: [..] Vector3i;
+    chunk_mutex: sync.Mutex;
+    chunk_load_timeout: u32;
 }
 
 world_make :: (allocator := context.allocator) -> ^World {
     world := new(World, allocator);
-    world.chunk_dist = 1;
+    world.chunk_dist = 2;
     world.center_chunk = .{0,0,0};
 
     sl := world.chunk_dist * 2 + 1;
     world.chunks = make([] ^Chunk, sl * sl * sl);
     array.fill(world.chunks, null);
 
+    sync.mutex_init(^world.chunk_mutex);
+
     return world;
 }
 
@@ -46,7 +50,7 @@ world_unload_chunk :: #match {
 }
 
 world_get_chunk :: #match {
-    @CompilerBug // If I write the following function in quick form:
+    // @CompilerBug // If I write the following function in quick form:
     //
     // (world: ^World, v: Vector3i) => world_get_chunk(world, v.x, v.y, v.z),
     //
@@ -136,6 +140,7 @@ world_move_center :: (use world: ^World, new_center: Vector3i) {
 
     sl := world.chunk_dist * 2 + 1;
     current_chunks := array.copy(world.chunks);
+    sync.scoped_mutex(^chunk_mutex);
     array.fill(world.chunks, null);
 
     center_chunk = new_center;
@@ -153,6 +158,13 @@ world_move_center :: (use world: ^World, new_center: Vector3i) {
         if world_get_chunk(world, x, y, z) == null do world.chunks_to_load << .{x, y, z};
     }
 
+    nc := new_center;
+    context->set_user_data(^nc);
+    array.sort(chunks_to_load, (x, y) => {
+        c := *(context->get_user_data(Vector3i));
+        return y->manhattan_dist(c) - x->manhattan_dist(c);
+    });
+
     delete(^current_chunks);
 }
 
@@ -191,10 +203,14 @@ world_get_aabbs :: (use world: ^World, center: Vector3, radius: f32, buffer: []
 
 world_update :: (use world: ^World, dt: f32) {
     if chunks_to_load.count > 0 {
-        chunk_to_load := chunks_to_load[0];
-        array.delete(^chunks_to_load, 0);
+        if chunk_load_timeout == 0 {
+            chunk_to_load := array.pop(^chunks_to_load);
+            world_load_chunk(world, chunk_to_load);
 
-        world_load_chunk(world, chunk_to_load);
+            chunk_load_timeout = 5;
+        }
+        
+        chunk_load_timeout -= 1;
     }
 }
 
index ae69f8c7caee0e943bc0b5a25d1de353ec11a144..fcf0c3bd08acfc582c655271af59e1463e938c59 100644 (file)
@@ -1,5 +1,6 @@
 
-use core
+use core {*}
+use perlin
 
 #local seed :: 8675309
 
@@ -11,7 +12,7 @@ generate_chunk :: (world: ^World, chunk: ^Chunk) {
 
         n := perlin.noise(px, ~~(10 * seed), pz);
         l := perlin.noise(px, ~~(10 * seed), pz);
-        l = (math.clamp(math.max(0, l), 0.2, 0.5) - 0.2) / 0.6 + 0.5;
+        l = (math.clamp(math.max(l, 0), 0.2, 0.5) - 0.2) / 0.6 + 0.5;
         h := cast(i32) (n * 32 + 18);
         h = math.max(h, 14);
         if n < -0.9 do h += ~~((n + 0.9) * 4);
index 9d0ad7c20fd97dac42578197b4b85ac1b45dcaf0..ca7f86768c6904089d4413e0c9df2730f0231dd3 100644 (file)
@@ -4,5 +4,3 @@ package runtime.vars
 
 Game_Version :: 0x0001
 Game_Port :: cast(u16) 5123
-
-#load_path "./../lib"
index 1a6c22e0bdb60308b540f59b246755f3f1a8295d..3b74d5422a1f18168b94572115ca168fc8c86748 100644 (file)
@@ -1,6 +1,6 @@
 package runtime.vars
 
-#load "core/std"
+// #load "core/std"
 
 #load_path "./../src/server"
 #library_path "./lib"
@@ -11,4 +11,5 @@ package runtime.vars
 #load "./../client/utils/vecmath"
 #load_all "./../shared"
 
+#load_path "./../lib"
 #load "onyx-net/module"
index abf004ecd2d340d3eb3cafb4fd5e1f92ca460d4c..f1f22beaa1b47cd6634b323af108beda2e4680ad 100644 (file)
@@ -1,8 +1,10 @@
 
-use core
+use core {*}
 use core.intrinsics.onyx {__initialize}
 
-#local onet :: onyx_net
+use packets
+use onyx_net {onet :: package}
+use runtime
 
 Player_Data :: struct {
     id: u16;
@@ -25,7 +27,7 @@ setup_server :: () {
     addr: net.Socket_Address;
     addr.port = runtime.vars.Game_Port;
 
-    host', err := onet.host_create(^addr, 16);
+    host~, err := onet.host_create(^addr, 16);
     if err != .None {
         println(err);
         os.exit(1);
@@ -88,7 +90,7 @@ handle_packet :: (peer: ^onet.Peer, packet_data: [] u8) {
         }
 
         case .Chat_Message, .Block_Updates {
-            @TODO // Validation of block updates
+            // @TODO // Validation of block updates
 
             packet := new(onet.Packet);
             packet.flags |= .Reliable;
index 7a9acbd9bace90a1101504540c01581366b4d8e3..f514e16a0789faeed7e9729f1c3e4e87cd58aa84 100644 (file)
@@ -2,6 +2,7 @@
 package packets
 use main { Vector3, Vector3i }
 use main { Block }
+use core
 
 Type :: enum (u8) {
     Connect;
@@ -97,4 +98,4 @@ Block_Updates :: struct #pack {
     updates :: (use bu: ^Block_Updates) => ([] Update).{
         ~~^update_data, ~~update_count
     };
-}
\ No newline at end of file
+}