[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
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
#!/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
-#load "core/std"
-
#load_path "./../src/client"
#library_path "./lib"
#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"
-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;
fog_color :: Vector3.{ 0.6, 0.6, 0.6 };
}
-@Relocate // this global variables
+// @Relocate // this global variables
font: Font;
player: Player;
world: ^World;
player_shader: Shader;
-@Relocate
+world_chunk_update_thread: thread.Thread;
+
+// @Relocate
world_fog_block: Shader_Block;
World_Fog :: struct {
u_fog_color: Vector3;
player_manager->draw_players();
}
-@Temporary
+// @Temporary
chat_messages: [..] [] u8;
draw_chat :: () {
-use core
-use opengles
+use core {*}
+use opengles {*}
Canvas :: struct {
-use core
-use stb_truetype
-use opengles
+use core {*}
+use stb_truetype {*}
+use opengles {*}
#local {
font_registry: Map(FontDescriptor, Font);
}
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;
}
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);
#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;
-use core
-use opengles
-use glfw3
+use core {*}
+use opengles {*}
+use glfw3 {*}
immediate_init :: () {
vertex_data = make([] Immediate_Vertex, Maximum_Vertex_Count);
-use core
-use opengles
+use core {*}
+use opengles {*}
+use runtime
Mesh :: struct (Vertex_Type: type_expr) {
handle: GLint;
}
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);
-use core
-use opengles
+use core {*}
+use opengles {*}
+use runtime
Shader :: struct {
vs, fs: GLuint;
-use core
-use opengles
-use stb_image
+use core {*}
+use opengles {*}
+use stb_image {*}
#local texture_cache: Map(str, Texture);
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);
#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;
//
package ui
-use core
-use opengles
-use glfw3
-use main
+use core {package, *}
+use opengles {*}
+use glfw3 {*}
+use main {*}
UI_Id :: u32
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 };
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 };
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;
}
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 };
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 };
use glfw3 { GLFWwindow_p }
-@GlobalVariable window: GLFWwindow_p;
+window: GLFWwindow_p;
debug_screen := false;
-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;
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();
-use core
-use glfw3
-use opengles
+use core {*}
+use glfw3 {*}
+use opengles {*}
+use game_net
+use runtime
+use ui
#local {
ip_addr: [..] u8;
title_font = font_lookup(.{"./assets/fonts/calibri.ttf", 64});
- @HACK @HACK @HACK
+ // @HACK // @HACK // @HACK
player_manager = new(Player_Manager);
}
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);
}
}
-#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;
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);
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;
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);
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);
}
on_connect_callback: On_Connect_Callback;
any_to_buffer :: macro (x: ^$T) => ([] u8).{ ~~x, sizeof T };
-}
\ No newline at end of file
+}
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);
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;
-use core
+use core {*}
-@GlobalVariable
+// @GlobalVariable
camera: Camera;
Camera :: struct {
-use core
+use core {*}
Color :: struct {
r, g, b : f32;
-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
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 :: () {
// 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
return "";
}
-#local log_level := Log_Level.Debug;
\ No newline at end of file
+#local log_level := Log_Level.Debug;
-use core
+use core {*}
Ray :: struct {
origin, direction: Vector3;
+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}
}
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,
};
}
- 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),
}
}
-#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
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
&& 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 };
}
-use core
-use opengles
+use core {*}
+use opengles {*}
Chunk_Vertex :: struct {
position : Vector3;
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 {
#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);
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};
-use core
+use core {*}
AABB :: struct {
x0, y0, z0, x1, y1, z1: f32;
-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?
-use core
+use core {*}
Remote_Player :: struct {
name: str;
mesh_draw(Meshes.white_box);
}
}
-}
\ No newline at end of file
+}
-use core
+use core {*}
World :: struct {
chunk_dist: i32;
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;
}
}
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),
//
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;
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);
}
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;
}
}
-use core
+use core {*}
+use perlin
#local seed :: 8675309
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);
Game_Version :: 0x0001
Game_Port :: cast(u16) 5123
-
-#load_path "./../lib"
package runtime.vars
-#load "core/std"
+// #load "core/std"
#load_path "./../src/server"
#library_path "./lib"
#load "./../client/utils/vecmath"
#load_all "./../shared"
+#load_path "./../lib"
#load "onyx-net/module"
-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;
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);
}
case .Chat_Message, .Block_Updates {
- @TODO // Validation of block updates
+ // @TODO // Validation of block updates
packet := new(onet.Packet);
packet.flags |= .Reliable;
package packets
use main { Vector3, Vector3i }
use main { Block }
+use core
Type :: enum (u8) {
Connect;
updates :: (use bu: ^Block_Updates) => ([] Update).{
~~^update_data, ~~update_count
};
-}
\ No newline at end of file
+}