summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/drawing.ha (renamed from drawing.ha)20
-rw-r--r--client/main.ha (renamed from main.ha)1
-rw-r--r--server/main.ha43
3 files changed, 53 insertions, 11 deletions
diff --git a/drawing.ha b/client/drawing.ha
index 5812109..e164d33 100644
--- a/drawing.ha
+++ b/client/drawing.ha
@@ -2,16 +2,16 @@ use sdl2;
use fmt;
// 2d position, x and y
-type pos = (i32, i32);
+export type pos = (i32, i32);
-type drawing_state = struct {
+export type drawing_state = struct {
// is the mouse button held down?
drawing: bool,
pos: pos,
pictures: []picture,
};
-type picture = struct {
+export type picture = struct {
// the surface data as u32s
d: *[*]u32,
w: size,
@@ -27,7 +27,7 @@ type picture = struct {
// Returns array index of the pixel at position pos.
// Bounds check happens in here instead of using a slice type, so
// that it's easier to remove later.
-fn pidx(pic: *picture, pos: pos) size = {
+export fn pidx(pic: *picture, pos: pos) size = {
const (x,y) = pos;
const (xs,ys) = (x:size, y:size);
assert(0 <= x, "x position must not be less than 0");
@@ -38,10 +38,10 @@ fn pidx(pic: *picture, pos: pos) size = {
return xs + pic.w*ys;
};
-fn pic_set(pic: *picture, pos: pos, val: u32) void =
+export fn pic_set(pic: *picture, pos: pos, val: u32) void =
pic.d[pidx(pic,pos)] = val;
-fn picture_from_surface(surf: *sdl2::SDL_Surface, pos: pos) picture = picture {
+export fn picture_from_surface(surf: *sdl2::SDL_Surface, pos: pos) picture = picture {
w = surf.w: size,
h = surf.h: size,
d = (surf.pixels as *opaque: *[*]u32),
@@ -49,11 +49,11 @@ fn picture_from_surface(surf: *sdl2::SDL_Surface, pos: pos) picture = picture {
pos = pos,
};
-fn clear_picture(pic: *picture, color: u32) void = {
+export fn clear_picture(pic: *picture, color: u32) void = {
for (let i = 0z; i < pic.w*pic.h; i+=1) pic.d[i] = color;
};
-fn outline_picture(pic: *picture) void = {
+export fn outline_picture(pic: *picture) void = {
for (let x = 0; x:size < pic.w; x+=1) {
pic_set(pic, (x, 0), 0);
pic_set(pic, (x, pic.h:int-1), 0);
@@ -69,7 +69,7 @@ fn max(a: i32, b: i32) i32 = if (a<b) b else a;
// Draws a circle onto the picture, at given position radius color
// Clips at the boundaries of the picture to avoid overflow.
-fn circle(picture: *picture, c: pos, r: i32, color: u32) void = {
+export fn circle(picture: *picture, c: pos, r: i32, color: u32) void = {
// fmt::printfln("C {} {} {} {:x}",c.0,c.1,r,color)!;
const (cx,cy) = c;
const ymin = max(0, cy-r);
@@ -90,7 +90,7 @@ fn circle(picture: *picture, c: pos, r: i32, color: u32) void = {
};
};
-fn do_drawing(dstate: *drawing_state) void = {
+export fn do_drawing(dstate: *drawing_state) void = {
if (dstate.drawing) for (let i = 0z; i < 4; i+=1) {
const pic = &dstate.pictures[i];
const p = (dstate.pos.0 - pic.pos.0, dstate.pos.1 - pic.pos.1);
diff --git a/main.ha b/client/main.ha
index 09fd30f..ba1736e 100644
--- a/main.ha
+++ b/client/main.ha
@@ -36,7 +36,6 @@ export fn main() void = {
for (let i = 0z; i < 4; i += 1) {
const p = &dstate.pictures[i];
clear_picture(p, 0xffffff);
- outline_picture(p);
};
let quit = false;
diff --git a/server/main.ha b/server/main.ha
new file mode 100644
index 0000000..43bdf34
--- /dev/null
+++ b/server/main.ha
@@ -0,0 +1,43 @@
+use fmt;
+use os;
+use io;
+use fs;
+use errors;
+use drawing::{pos};
+
+// type chunk = struct {
+// fd: io::file,
+// d: []u32,
+// };
+
+// def CHUNKSIZE: size = 512;
+// def CHUNK_LENGTH: size = CHUNKSIZE*CHUNKSIZE*size(u32);
+
+// fn open_chunk_file(chunkpos: pos) (chunk | fs::error) = {
+// const path = fmt::asprintf("c.{}.{}.dat", chunkpos.0, chunkpos.1);
+// defer free(path);
+// const fd = fs::create_file(os::cwd, path,
+// fs::mode::USER_RW | fs::mode::GROUP_RW,
+// fs::flag::RDWR)?;
+// io::trunc(fd, CHUNK_LENGTH)?;
+// const dp = io::mmap(null, CHUNK_LENGTH,
+// io::prot::READ | io::prot::WRITE,
+// io::mflag::SHARED,
+// fd, 0)?;
+// const d = (dp: *[*]u32)[..CHUNKSIZE*CHUNKSIZE];
+// return chunk { fd = fd, d = d };
+// };
+
+export fn main() void = {
+ // match (open_chunk_file((-3,12))) {
+ // case let e: fs::error =>
+ // fmt::fatal(fs::strerror(e));
+ // case let ch: chunk =>
+ // ch.d[0] = 0x12345678;
+ // ch.d[CHUNKSIZE*CHUNKSIZE - 1]=0xdeadbeef;
+ // };
+
+ const t = test2 { a=4, b=5 };
+ thethe(&t);
+
+};