summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c27
-rw-r--r--map.c97
-rw-r--r--world.map19
3 files changed, 132 insertions, 11 deletions
diff --git a/main.c b/main.c
index 69ad117..5cf3fc2 100644
--- a/main.c
+++ b/main.c
@@ -116,15 +116,32 @@ kbdproc(void*)
}
}
+enum{ Frameslice = 1000/30 };
void
drawproc(void *arg)
{
Channel *c;
-
- c = arg;
- for(;;){
- send(c, nil);
- sleep(FPS2MS(60));
+ vlong t0, t, dt, tt;
+ int fps;
+
+ c = arg;
+ fps = 0;
+ tt = 0;
+ t0 = nsec();
+ for(;;){
+ send(c, nil);
+ t = nsec();
+ dt = t-t0;
+ fps++;
+ tt += dt;
+ if(tt >= 1e9){
+ fprint(2, "fps %d\n", fps);
+ tt = fps = 0;
+ }
+ dt /= 1e6;
+ if(dt < Frameslice)
+ sleep(Frameslice - dt);
+ t0 = t;
}
}
diff --git a/map.c b/map.c
index 652a934..af90d09 100644
--- a/map.c
+++ b/map.c
@@ -1,10 +1,23 @@
#include <u.h>
#include <libc.h>
+#include <bio.h>
#include "dat.h"
#include "fns.h"
+enum {
+ RN, /* tramontana */
+ RNE, /* greco */
+ RE, /* levante */
+ RSE, /* scirocco */
+ RS, /* ostro */
+ RSW, /* libeccio */
+ RW, /* ponente */
+ RNW, /* maestro */
+ NROOMS
+};
+
typedef struct Entity Entity;
-typedef struct Object Object;
+typedef struct Item Item;
typedef struct Room Room;
struct Entity
@@ -13,18 +26,90 @@ struct Entity
char *desc;
};
-struct Object
+struct Item
{
Entity;
int type;
double weight;
- //Property props;
};
struct Room
{
Entity;
- Object *objects;
- int nobject;
- Room *neighbors[8];
+ Item *items;
+ int nitems;
+ Room *neighbors[NROOMS];
};
+
+
+Room *rooms;
+int nrooms;
+
+void*
+emalloc(ulong n)
+{
+ void *p;
+
+ p = malloc(n);
+ if(p == nil)
+ sysfatal("malloc: %r");
+ memset(p, 0, n);
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
+
+void*
+erealloc(void *p, ulong n)
+{
+ p = realloc(p, n);
+ if(p == nil)
+ sysfatal("realloc: %r");
+ setrealloctag(p, getcallerpc(&n));
+ return p;
+}
+
+int
+readrooms(char *file)
+{
+ Biobuf *bin;
+ Room *r;
+ char *line, k[128], v[128], *p;
+
+ bin = Bopen(file, OREAD);
+ if(bin == nil)
+ sysfatal("Bopen: %r");
+ rooms = erealloc(rooms, ++nrooms*sizeof(Room));
+ r = &rooms[nrooms-1];
+ while((line = Brdline(bin, '\n')) != nil){
+ if(Blinelen(bin) == 1 && *line == '\n'){
+ rooms = erealloc(rooms, ++nrooms+sizeof(Room));
+ r = &rooms[nrooms-1];
+ }
+ while(isspace(*line))
+ line++;
+ p = k;
+ while(isalnum(*line) && p < k + sizeof k - 1)
+ *p++ = *line++;
+ *p = 0;
+ while(isspace(*line))
+ line++;
+ if(*line != '='){
+ werrstr("syntax error: expected '=', got '%c'", *line);
+ return -1;
+ }
+ while(isspace(*line))
+ line++;
+ p = v;
+ while(*line != '\n' && *line != '\0' && p < v + sizeof v - 1)
+ *p++ = *line++;
+ *p = 0;
+
+ if(strcmp(k, "id") == 0)
+ r->id = strtol(v, nil, 10);
+ else if(strcmp(k, "description") == 0)
+ r->desc = strdup(v);
+ else if(strcmp(k, "rooms") == 0){
+
+ }
+ }
+}
diff --git a/world.map b/world.map
new file mode 100644
index 0000000..6da4bf6
--- /dev/null
+++ b/world.map
@@ -0,0 +1,19 @@
+id = 0
+description = The hall of a house.
+rooms = ,,,,1
+
+id = 1
+description = The hallway of a house.
+rooms = 0,3,4,,2
+
+id = 2
+description = The living room.
+rooms = 1
+
+id = 3
+description = The bathroom.
+rooms = ,,,,,1
+
+id = 4
+description = The bedroom.
+rooms = ,,,,,,1