-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Base Server formatting changed. - Base Client received more implementations. - Add the core namespace to the main namespace. - Implement more of the Packet struct. - Utilize Options more in the main file and start implementing the client, cluster, and master implementations. - Add the spawning namespace under the core namespace. - Add the Spawnee struct. - Add the Player struct and extend Spawnee. - Further implement the proper Client struct.
- Loading branch information
Showing
10 changed files
with
209 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
//! A standard client that connects to a server. | ||
|
||
const std = @import("std"); | ||
const sustenet = @import("root").sustenet; | ||
const network = @import("network"); | ||
|
||
const AutoHashMap = std.AutoHashMap; | ||
const BaseEvent = sustenet.events.BaseEvent; | ||
const BaseClient = @import("root").sustenet.transport.BaseClient; | ||
|
||
const Client = @This(); | ||
|
||
pub const ConnectionType = enum { MasterServer, ClusterServer, None }; | ||
pub const Connection = struct { ip: network.Address.IPv4, port: u16 }; | ||
|
||
pub const packetHandler = *const fn (from_client: i32, packet: i32) void; | ||
var packetHandlers: ?AutoHashMap(i32, packetHandler) = null; | ||
|
||
active_connection: ConnectionType, | ||
master_connection: ?Connection, | ||
cluster_connection: ?Connection, | ||
|
||
on_initialized: BaseEvent, // Init these early | ||
on_cluster_server_list: BaseEvent, | ||
|
||
super: BaseClient, | ||
|
||
const Client = @This(); | ||
pub fn new(_: ?[]const u8, _: ?u16) Client { | ||
var client = Client{ | ||
.super = BaseClient.new(-1), | ||
|
||
pub fn new(port: u16) Client { | ||
const client = Client{ | ||
.super = BaseClient.new(port), | ||
.active_connection = ConnectionType.None, | ||
.master_connection = null, | ||
.cluster_connection = null, | ||
.on_initialized = BaseEvent{}, | ||
.on_cluster_server_list = BaseEvent{}, | ||
}; | ||
|
||
// client.super.on_connected = BaseEvent.init(); | ||
// client.super.on_received = BaseEvent.init(); | ||
// client.super.on_initialized = BaseEvent.init(); | ||
|
||
client.initializeClientData(); | ||
return client; | ||
} | ||
|
||
pub fn connect(self: *Client) !void { | ||
try self.super.connect(); | ||
pub fn connect(_: *Client) !void { | ||
// try self.super.connect(); | ||
} | ||
|
||
pub fn initializeClientData(_: *Client) void {} | ||
|
||
//#region Memory Functions | ||
pub fn deinit(self: *Client) void { | ||
self.super.deinit(); | ||
} | ||
//#endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const sustenet = @import("root").sustenet; | ||
const Vector3 = sustenet.zig_numerics.vector.Vec3(f32); | ||
|
||
const Spawnee = sustenet.core.spawning.Spawnee; | ||
const Player = @This(); | ||
|
||
super: Spawnee, | ||
username: []u8, | ||
|
||
pub fn new(id: u32, username: []const u8, spawn_position: Vector3) Player { | ||
const player = Player{ | ||
.super = Spawnee.new(id, spawn_position), | ||
.username = username, | ||
}; | ||
return player; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const sustenet = @import("root").sustenet; | ||
const zig_numerics = sustenet.zig_numerics; | ||
|
||
const Vector3 = zig_numerics.vector.Vec3(f32); | ||
const Quaternion = zig_numerics.quaternion.Quaternion(f32); | ||
const Spawnee = @This(); | ||
|
||
id: u32, | ||
position: Vector3, | ||
rotation: Quaternion, | ||
|
||
pub fn new(id: u32, position: Vector3, rotation: Quaternion) Spawnee { | ||
return Spawnee{ | ||
.id = id, | ||
.position = position, | ||
.rotation = rotation, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! Spawning namespace | ||
|
||
pub const Player = @import("Player.zig"); | ||
pub const Spawnee = @import("Spawnee.zig"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Core namespace | ||
|
||
pub const spawning = @import("Spawning/spawning.zig"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters