summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-14 00:35:19 +0100
committerubq323 <ubq323@ubq323.website>2024-04-14 00:35:19 +0100
commit6cff8d620cd92f9ddc63c6891b3e669b5294619e (patch)
treed3632c81992fdbf0f8435fa225920122bee29776 /client
parentc95e947d90a02091aef4e63693ce3205fdfba3b6 (diff)
multiple chunks on server and unload not near players. just need client to req chunks now
Diffstat (limited to 'client')
-rw-r--r--client/main.ha25
1 files changed, 19 insertions, 6 deletions
diff --git a/client/main.ha b/client/main.ha
index e720b65..de6b2fd 100644
--- a/client/main.ha
+++ b/client/main.ha
@@ -4,12 +4,11 @@ use math;
use net;
use net::dial;
use drawing;
-use drawing::{pos};
+use drawing::{pos,CHUNKSIZE};
use client::paintui;
use unix::poll;
use packet_reader;
-def CHUNKSIZE = 512;
def NCHUNKS = 16;
def WIN_H: i32 = 480;
@@ -42,13 +41,19 @@ export fn main() void = {
drawing::outline_picture(p);
};
-
// connect to server
const conn = match(dial::dial("tcp","localhost","41460")) {
case let c: net::socket => yield c;
case let err: net::error =>
fmt::fatal("couldn't connect to server:",net::strerror(err));
};
+
+ for (let i = 0; i < 3; i += 1) {
+ packet_reader::send(conn, (
+ i*CHUNKSIZE,i*CHUNKSIZE
+ ):packet_reader::packet_reqchunk)!;
+ };
+
const pollfd: [1]poll::pollfd = [ poll::pollfd {
fd = conn, events=poll::event::POLLIN, revents = 0
}];
@@ -66,7 +71,7 @@ export fn main() void = {
let mouse_pos: pos = (0,0);
let mouse_down = false;
for (!quit) {
- do_movement(&camera_pos);
+ const did_move = do_movement(&camera_pos);
// let nvis = 0;
// for (const pic &.. pictures) {
@@ -95,7 +100,6 @@ export fn main() void = {
case => void;
};
-
match (paintui::tick(&pstate, mouse_pos, mouse_down)) {
case void => yield;
case let op: drawing::op =>
@@ -103,6 +107,10 @@ export fn main() void = {
packet_reader::send(conn, op: packet_reader::packet_drawop)!;
};
+ if (did_move) {
+ packet_reader::send(conn, camera_pos: packet_reader::packet_position)!;
+ };
+
const n = poll::poll(pollfd, poll::NONBLOCK)!;
if (n > 0) {
fmt::println("data available")!;
@@ -155,7 +163,8 @@ fn render_picture(pic: *drawing::picture, surf: *sdl2::SDL_Surface, winsurf: *sd
def SPEED = 17;
def DIAG_SPEED = 12; // thereabouts
-fn do_movement(pos: *pos) void = {
+// returned whether movement happened
+fn do_movement(pos: *pos) bool = {
const kb = sdl2::SDL_GetKeyboardState();
let dx = 0;
let dy = 0;
@@ -164,11 +173,15 @@ fn do_movement(pos: *pos) void = {
if (kb[sdl2::SDL_Scancode::A]) dx -= 1;
if (kb[sdl2::SDL_Scancode::D]) dx += 1;
+ const did_move = dx!=0 || dy!=0;
+
let speed = SPEED;
if (dx != 0 && dy != 0) speed = DIAG_SPEED;
pos.0 += dx * speed;
pos.1 += dy * speed;
+
+ return did_move;
};
fn is_picture_visible(camera_pos: pos, pic_pos: pos) bool = {