Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8c712ab
Author: DragonFighter603 <[email protected]>
Date:   Fri May 19 21:18:49 2023 +0200

    #10 generation framework

commit 117b306
Author: DragonFighter603 <[email protected]>
Date:   Fri May 19 19:22:45 2023 +0200

    #10 tile types to enum

commit fc9efbe
Author: DragonFighter603 <[email protected]>
Date:   Fri May 19 18:17:07 2023 +0200

    started framework for world gen

commit 2d9e933
Author: Spydr06 <[email protected]>
Date:   Thu May 18 21:49:52 2023 +0200

    start laying out the material system, implementation will follow soon

commit b7297aa
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 17:13:47 2023 +0200

    #10

commit 2dd5675
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 16:56:29 2023 +0200

    Update client.rs

commit 9bbfbe2
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 16:48:37 2023 +0200

    #10 client receives chunks properly

commit 622d5ad
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 16:00:18 2023 +0200

    small fix to logging

commit 2062c0e
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 15:57:20 2023 +0200

    update color on pack

commit ea13626
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 15:57:01 2023 +0200

    better logging for spamming messages

commit b39ddd3
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 15:17:55 2023 +0200

    #10 made requesting chunks a client side responsability

commit 97cb107
Merge: 457428e acfa06a
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 13:30:25 2023 +0200

    Merge branch 'master' of https://github.com/DragonFIghter603/aeonetica

commit 457428e
Author: DragonFighter603 <[email protected]>
Date:   Thu May 18 13:30:17 2023 +0200

    refactored logs

commit acfa06a
Author: Spydr06 <[email protected]>
Date:   Thu May 18 12:58:42 2023 +0200

    make `server/build.py` automatically detect needed mods

commit 5a96364
Author: DragonFighter603 <[email protected]>
Date:   Tue May 16 20:23:16 2023 +0200

    fix #18

commit eadc7e9
Author: Spydr06 <[email protected]>
Date:   Mon May 15 22:03:37 2023 +0200

    fix error

commit cbc2b26
Merge: ee2eb62 d561793
Author: Spydr06 <[email protected]>
Date:   Mon May 15 22:02:47 2023 +0200

    Merge branch 'master' of https://github.com/Dragonfighter603/aeonetica

commit ee2eb62
Author: Spydr06 <[email protected]>
Date:   Mon May 15 22:02:39 2023 +0200

    add `UILayer` as a test and started making plans on how to implement a user-definable rendering pipeline

commit d561793
Merge: c045eae e1e4655
Author: DragonFighter603 <[email protected]>
Date:   Mon May 15 21:00:20 2023 +0200

    Merge branch 'master' of https://github.com/DragonFIghter603/aeonetica

commit c045eae
Author: DragonFighter603 <[email protected]>
Date:   Mon May 15 21:00:12 2023 +0200

    Update server.rs

commit e1e4655
Author: Spydr06 <[email protected]>
Date:   Mon May 15 15:05:23 2023 +0200

    expand build script to allow building every part of aeonetica in one command

commit 4aa52b7
Author: Spydr06 <[email protected]>
Date:   Sun May 14 20:46:01 2023 +0200

    use `ErrorResult<T>` everywhere and make `Error` boxed by default
  • Loading branch information
justanothercell committed May 19, 2023
1 parent 72e6ddd commit 2a11a4a
Show file tree
Hide file tree
Showing 43 changed files with 573 additions and 240 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ server/mods/**.zip
perf.data*

local_testing/
win_ter_setup.py

assets/font_and_glyphs/generated.png
assets/font_and_glyphs/generated_x16.png
Expand Down
14 changes: 14 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python3

import subprocess
import sys
import os

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)

if __name__ == '__main__':
os.chdir(dname)
subprocess.call([sys.executable, 'server/build.py'])
subprocess.call([sys.executable, 'client/build.py'])

28 changes: 28 additions & 0 deletions client/assets/flat-color-shader.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[description]
default shader for the FlatColor material

#[vertex]
#version 450 core

layout (location = 0) in vec3 a_Position;
layout (location = 1) in vec4 a_Color;

uniform mat4 u_ViewProjection;

out vec4 v_Color;

void main() {
v_Color = a_Color;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}

#[fragment]
#version 450 core

in vec4 v_Color;

out vec4 color;

void main() {
color = v_Color;
}
34 changes: 34 additions & 0 deletions client/assets/flat-texture-shader.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[description]
default shader for the FlatTexture material

#[vertex]
#version 450 core

layout (location = 0) in vec3 a_Position;
layout (location = 1) in vec2 a_TexCoord;
layout (location = 2) in int a_TexIdx;

uniform mat4 u_ViewProjection;

out vec2 v_TexCoord;
flat out int v_TexIdx;

void main() {
v_TexCoord = a_TexCoord;
v_TexIdx = a_TexIdx;
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
}

#[fragment]
#version 450 core

in vec2 v_TexCoord;
flat in int v_TexIdx;

uniform sampler2D u_Textures[16];

out vec4 color;

void main() {
color = texture(u_Textures[v_TexIdx], v_TexCoord);
}
17 changes: 17 additions & 0 deletions client/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python3

import subprocess
import sys
import os

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)

BOLD = '\033[1m'
ENDC = '\033[0m'
BLUE = '\033[94m'

if __name__ == '__main__':
os.chdir(dname)
print(f'{BOLD}{BLUE}=>> COMPILING CLIENT:{ENDC}')
subprocess.call(['cargo', 'run' if len(sys.argv) > 1 and sys.argv[1] in ['-r', '--run'] else 'build'])
6 changes: 3 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ pub fn run(mut client: ClientRuntime, client_id: ClientId, store: &mut DataStore
window.poll_events(&mut client, &mut context);

let _ = client.handle_queued(store, &mut context).map_err(|e| {
log_err!("{e}")
log!(ERROR, "{e}")
});

window.render(&mut context, &mut client, store, delta_time as f64 / FULL_SEC as f64);
window.on_render(&mut context, &mut client, store, delta_time as f64 / FULL_SEC as f64);

delta_time = t.elapsed().as_nanos() as usize;
time += delta_time;

frames += 1;

if time - last_full_sec >= FULL_SEC {
log!("fps: {}", frames);
log!(PACK, "fps: {}", frames);
last_full_sec = time;
frames = 0;
}
Expand Down
32 changes: 16 additions & 16 deletions client/src/client_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::process::exit;
use std::thread;
use std::rc::Rc;
use std::time::Duration;
use aeonetica_engine::error::{Error, Fatality};
use aeonetica_engine::error::{Error, Fatality, ErrorResult};
use aeonetica_engine::error::builtin::ModError;
use aeonetica_engine::libloading::{Library, Symbol};
use aeonetica_engine::nanoserde::SerBin;
use aeonetica_engine::{ENGINE_VERSION, Id, log, log_err, MAX_CLIENT_TIMEOUT};
use aeonetica_engine::{ENGINE_VERSION, Id, log, MAX_CLIENT_TIMEOUT};
use aeonetica_engine::networking::client_packets::{ClientInfo, ClientMessage, ClientPacket};
use aeonetica_engine::networking::server_packets::{ServerMessage, ServerPacket};
use aeonetica_engine::networking::{MOD_DOWNLOAD_CHUNK_SIZE, NetResult, SendMode};
Expand Down Expand Up @@ -94,14 +94,14 @@ impl ClientHandleBox {

#[inline(always)]
pub fn on_event(&mut self, event: &Event) -> bool {
self.handle.on_event(event)
self.handle.event(event)
}
}

type LoadingModList = Rc<RefCell<HashMap<String, Rc<RefCell<LoadingMod>>>>>;

impl ClientRuntime {
pub fn create(client_id: Id, addr: &str, server_addr: &str, store: &mut DataStore) -> Result<Self, Error>{
pub fn create(client_id: Id, addr: &str, server_addr: &str, store: &mut DataStore) -> ErrorResult<Self>{
let nc = NetworkClient::start(addr, server_addr).map_err(|e| {
e.log_exit();
}).unwrap();
Expand All @@ -127,8 +127,8 @@ impl ClientRuntime {
message: ClientMessage::KeepAlive,
});
let _ = timeout_socket.send(data.as_slice()).map_err(|e|{
let e: Error = e.into();
log_err!("{e}");
let e: Box<Error> = e.into();
log!(ERROR, "{e}");
exit(1);
});
std::thread::sleep(Duration::from_millis((MAX_CLIENT_TIMEOUT - 1000) as u64))
Expand All @@ -147,13 +147,13 @@ impl ClientRuntime {
&mut self.handles
}

pub(crate) fn request_response<F: Fn(&mut ClientRuntime, &ServerPacket) + 'static>(&mut self, packet: &ClientPacket, handler: F, mode: SendMode) -> Result<(), Error> {
pub(crate) fn request_response<F: Fn(&mut ClientRuntime, &ServerPacket) + 'static>(&mut self, packet: &ClientPacket, handler: F, mode: SendMode) -> ErrorResult<()> {
self.awaiting_replies.insert(packet.conv_id, Box::new(handler));
self.nc.borrow().send(packet, mode)?;
Ok(())
}

fn register(&mut self) -> Result<LoadingModList, Error>{
fn register(&mut self) -> ErrorResult<LoadingModList>{
let mod_list = Rc::new(RefCell::new(HashMap::new()));
let mod_list_filler = mod_list.clone();
self.request_response(&ClientPacket {
Expand Down Expand Up @@ -209,13 +209,13 @@ impl ClientRuntime {
mod_list_filler.replace(local_mod_list);
}
NetResult::Err(msg) => {
log_err!("server did not accept connection: {msg}");
log!(ERROR, "server did not accept connection: {msg}");
exit(1);
}
}
},
e => {
log_err!("invalid response: {e:?}");
log!(ERROR, "invalid response: {e:?}");
exit(1);
}
}
Expand All @@ -229,7 +229,7 @@ impl ClientRuntime {
Ok(mod_list)
}

fn download_mods(&mut self, mod_list: &LoadingModList) -> Result<(), Error>{
fn download_mods(&mut self, mod_list: &LoadingModList) -> ErrorResult<()>{
log!("downloading {} mod(s)", mod_list.borrow().values().filter(|m| !m.borrow().available).count());
let mut borrowed_ml = mod_list.borrow_mut();
for (name_path, lm) in borrowed_ml.iter_mut() {
Expand All @@ -253,7 +253,7 @@ impl ClientRuntime {
lmb.data.splice(i as usize..(i as usize+data.len()), data.to_owned());
},
e => {
log_err!("invalid response: {e:?}");
log!(ERROR, "invalid response: {e:?}");
exit(1);
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl ClientRuntime {
Ok(())
}

fn enable_mods(&mut self, mod_list: &LoadingModList, store: &mut DataStore) -> Result<(), Error>{
fn enable_mods(&mut self, mod_list: &LoadingModList, store: &mut DataStore) -> ErrorResult<()>{
for (name_path, lm) in mod_list.borrow_mut().iter_mut() {
log!("loading mod {} ...", name_path);
let mut loaded_mod = load_mod(name_path)?;
Expand All @@ -316,15 +316,15 @@ impl ClientRuntime {
Ok(())
}

fn gracefully_abort<E: Into<Error>>(&self, e: E) -> !{
fn gracefully_abort<E: Into<Box<Error>>>(&self, e: E) -> !{
let err = e.into();
err.log();
log_err!("gracefully aborted client");
log!(ERROR, "gracefully aborted client");
exit(1);
}
}

pub(crate) fn load_mod(name_path: &str) -> Result<ClientModBox, Error> {
pub(crate) fn load_mod(name_path: &str) -> ErrorResult<ClientModBox> {
let (path, name) = name_path.split_once(':').unwrap();
let client_lib = unsafe { Library::new(client_lib(path, name))
.map_err(|e| Error::new(ModError(format!("could not load mod: {e}")), Fatality::FATAL, false))? };
Expand Down
1 change: 1 addition & 0 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(let_chains)]
#![feature(result_flattening)]
#![feature(local_key_cell_methods)]

use std::ops::{Deref, DerefMut};
use aeonetica_engine::libloading::Library;
Expand Down
7 changes: 4 additions & 3 deletions client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![feature(let_chains)]
#![feature(result_flattening)]
#![feature(addr_parse_ascii)]
#![feature(local_key_cell_methods)]

use std::net::{IpAddr, SocketAddr};
use std::net::SocketAddr;

use aeonetica_engine::{log, Id, log_err};
use aeonetica_engine::{log, Id};
use client::{client::run, data_store::DataStore, client_runtime::ClientRuntime};

mod defaults {
Expand Down Expand Up @@ -40,7 +41,7 @@ fn main() {
log!("using default arguments:\n\tclient ip: {client_ip}\tserver ip: {server_ip}");
}
_ => {
log_err!("unexpected arguments: {args:?}; use `--help` for help");
log!(ERROR, "unexpected arguments: {args:?}; use `--help` for help");
std::process::exit(2);
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/networking/messaging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cell::{RefCell, RefMut};
use std::cell::RefCell;
use std::rc::Rc;
use aeonetica_engine::{ClientId, EntityId, Id, TypeId};
use aeonetica_engine::nanoserde::{DeBin, SerBin};
Expand All @@ -22,7 +22,7 @@ pub trait ClientHandle: ClientEntity {
fn remove(&mut self, messenger: &mut ClientMessenger, renderer: Nullable<&mut Renderer>, store: &mut DataStore) {}

fn update(&mut self, messenger: &mut ClientMessenger, renderer: &mut Renderer, store: &mut DataStore, delta_time: f64) {}
fn on_event(&mut self, event: &Event) -> bool { false }
fn event(&mut self, event: &Event) -> bool { false }
}

pub struct ClientMessenger {
Expand Down
20 changes: 10 additions & 10 deletions client/src/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::cell::RefCell;
use std::io::{Read, Write};
use std::net::{TcpStream, UdpSocket};
use std::sync::{Arc, Mutex};
use aeonetica_engine::error::{Error, Fatality};
use aeonetica_engine::error::{Error, Fatality, ErrorResult};
use aeonetica_engine::error::builtin::NetworkError;
use aeonetica_engine::{log_err};
use aeonetica_engine::{log};
use aeonetica_engine::nanoserde::{SerBin, DeBin};
use aeonetica_engine::networking::{MAX_PACKET_SIZE, SendMode};
use aeonetica_engine::networking::client_packets::{ClientPacket};
Expand All @@ -20,7 +20,7 @@ pub(crate) struct NetworkClient {
}

impl NetworkClient {
pub(crate) fn start(addr: &str, server: &str) -> Result<Self, Error>{
pub(crate) fn start(addr: &str, server: &str) -> ErrorResult<Self>{
let tcp = TcpStream::connect(server)?;
tcp.set_nonblocking(false).unwrap();
let udp = UdpSocket::bind(addr)?;
Expand All @@ -36,10 +36,10 @@ impl NetworkClient {
match udp_sock.recv_from(&mut buf) {
Ok((len, src)) => match DeBin::deserialize_bin(&buf[..len]) {
Ok(packet) => recv_udp.lock().unwrap().push(packet),
Err(e) => log_err!("invalid server packet from {src}: {e}")
Err(e) => log!(ERROR, "invalid server packet from {src}: {e}")
},
Err(e) => {
log_err!("couldn't recieve a datagram: {}", e);
log!(ERROR, "couldn't recieve a datagram: {}", e);
}
}
}
Expand All @@ -53,7 +53,7 @@ impl NetworkClient {
tcp_sock.read_exact(&mut buffer[..]).unwrap();
match DeBin::deserialize_bin(&buffer[..]) {
Ok(packet) => recv_tcp.lock().unwrap().push(packet),
Err(e) => log_err!("invalid server packet: {e}")
Err(e) => log!(ERROR, "invalid server packet: {e}")
}
}
});
Expand All @@ -70,7 +70,7 @@ impl NetworkClient {
packets
}

pub(crate) fn send(&self, packet: &ClientPacket, mode: SendMode) -> Result<(), Error>{
pub(crate) fn send(&self, packet: &ClientPacket, mode: SendMode) -> ErrorResult<()> {
let data = SerBin::serialize_bin(packet);
match mode {
SendMode::Quick => {
Expand All @@ -79,18 +79,18 @@ impl NetworkClient {
}
let sock = self.udp.try_clone()?;
std::thread::spawn(move || sock.send(&data[..]).map_err(|e| {
let e: Error = e.into();
let e: Box<Error> = e.into();
e.log();
}));
}
SendMode::Safe => {
let mut tcp = self.tcp.borrow_mut();
let _ = tcp.write_all(&(data.len() as u32).to_le_bytes()).map_err(|e| {
let e: Error = e.into();
let e: Box<Error> = e.into();
e.log();
});
let _ = tcp.write_all(&data[..]).map_err(|e| {
let e: Error = e.into();
let e: Box<Error> = e.into();
e.log();
});
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/networking/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::exit;
use aeonetica_engine::error::Error;
use aeonetica_engine::error::ErrorResult;
use aeonetica_engine::log;
use aeonetica_engine::networking::client_packets::{ClientMessage, ClientPacket};
use aeonetica_engine::networking::SendMode;
Expand All @@ -11,7 +11,7 @@ use crate::networking::messaging::ClientMessenger;
use crate::renderer::context::RenderContext;

impl ClientRuntime {
pub(crate) fn handle_queued(&mut self, store: &mut DataStore, context: &mut RenderContext) -> Result<(), Error> {
pub(crate) fn handle_queued(&mut self, store: &mut DataStore, context: &mut RenderContext) -> ErrorResult<()> {
let packets = self.nc.borrow_mut().queued_packets();
packets.into_iter().map(|packet| self.handle_packet(&packet, store, context))
.reduce(|acc, r| {
Expand All @@ -21,7 +21,7 @@ impl ClientRuntime {
}).unwrap_or(Ok(()))
}

pub(crate) fn handle_packet(&mut self, packet: &ServerPacket, store: &mut DataStore, context: &mut RenderContext) -> Result<(), Error>{
pub(crate) fn handle_packet(&mut self, packet: &ServerPacket, store: &mut DataStore, context: &mut RenderContext) -> ErrorResult<()>{
if let Some(handler) = self.awaiting_replies.remove(&packet.conv_id) {
handler(self, packet);
return Ok(())
Expand Down
Loading

0 comments on commit 2a11a4a

Please sign in to comment.