Index: branches/simulator/projects/simulator/simulator/core/world.c
===================================================================
--- branches/simulator/projects/simulator/simulator/core/world.c	(revision 1039)
+++ branches/simulator/projects/simulator/simulator/core/world.c	(revision 1040)
@@ -12,7 +12,24 @@
 #include <stdarg.h>
 #include "world.h"
 
+world_t world;
 
+int init_world(int max_objs, bbox_t b)
+{
+    world.max_objs = max_objs;
+    world.cur_objs = 0;
+    world.objs = calloc(max_objs,  sizeof(object_t));
+    world.win = b;
+    //PBBOX(b);
+}
+int destroy_world()
+{
+    int i;
+    for (i = 0; i < world.cur_objs; i++) {
+	destroy(&world.objs[i]);
+    }
+    free(world.objs);
+}
 
 double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj) =
     {
@@ -22,6 +39,13 @@
 {
     create_poly
 };
+int (*destroy_func[NUM_SHAPES])(object_t *obj) = 
+    {
+    destroy_poly
+    };
+
+
+
 double collide_circle(ray_t *ray, object_t *obj)
 {
     return -1;
@@ -57,35 +81,7 @@
     return dist;
 
 }
-double collide_rect(ray_t *ray, object_t *obj) {}
-    /*
-{
-    seg_t s;
-    double min = RAY_MISS, x;
-    rect_t *rect = (rect_t *)obj->props;
 
-    s.p1 = s.p2 = rect->p1;
-    s.p2.y = rect->p2.y;
-    if ((x = collide_seg(ray, (seg_t *)&s)) < min) 
-	min = x;
-
-    s.p1 = rect->p2;
-    if ((x = collide_seg(ray, (seg_t *)&s)) < min) 
-	min = x;
-
-    s.p2 = rect->p1;
-    s.p2.x = rect->p2.x;
-    if ((x = collide_seg(ray, (seg_t *)&s)) < min) 
-	min = x;
-
-    s.p1 = rect->p1;
-    if ((x = collide_seg(ray, (seg_t *)&s)) < min) 
-	min = x;
-
-    return min;
-}
-*/
-
 double collide_poly(ray_t *ray, object_t *obj)
 {
     int i;
@@ -102,7 +98,7 @@
 	    min = x;
 	}
     }
-    if (p->type == POLY_DISCONNECTED) {
+    if (p->type == POLY_CONNECTED) {
 	if ((x = collide_seg(ray,p->pts[i],p->pts[0])) < min)
 	    min = x;
     }
@@ -115,7 +111,7 @@
     {
 	return -1;
     }
-    return collide_func[obj->id](ray, obj);
+    return collide_func[obj->id+ID_OFFSET](ray, obj);
 }
 
 
@@ -122,20 +118,25 @@
 
 object_t *create(int id, ...)
 {
-    object_t *obj;
+    object_t *obj = &(world.objs[world.cur_objs++]);
     va_list args;
 
-    obj = malloc(sizeof(object_t));
-    obj->id = id;
     va_start(args, id);
-    if (create_func[id](obj, args) < 0) {
-	free(obj);
-	obj = NULL;
+    if (create_func[id+ID_OFFSET](obj, args) < 0) {
+	/* Cleanup ? */
     }
     va_end(args);
     return obj;
 }
 
+int destroy(object_t *obj) 
+{
+    if (obj->id == ID_NULL)
+	return 0;
+    destroy_func[obj->id+ID_OFFSET](obj);
+    obj->id = ID_NULL;
+}
+
 /**
  *
  **/
@@ -171,39 +172,33 @@
     int argc = va_arg(ap, int);
 }
 
-void destroy_poly (object_t *obj)
+int destroy_poly (object_t *obj)
 {
     poly_t *p;
-    int i;
-
-    if (obj == NULL)
-	return;
     p =  (poly_t *)obj->props;
     if (p != NULL) free(p->pts);
     free(p);
-    free(obj);
+    return 1;
+}
 
-    for (i = 0; i < p->num_pts; i++)
-    {
+void print_world(void)
+{
+    int i;
+    printf("WORLD: %d object(s) in (%g,%g)->(%g,%g)\n", world.cur_objs, world.win.p1.x,world.win.p1.y,world.win.p2.x,world.win.p2.y);
+    for (i = 0; i < world.cur_objs; i++) {
+	print_object(&world.objs[i]);
     }
-
-
-
-
 }
-
 void print_object(object_t *obj)
 {
-    if (obj == NULL) {
-	printf("No object\n");
-	return;
-    }
     int i;
     poly_t *p;
     switch (obj->id) {
+	case ID_NULL:
+	    printf("\tNULL\n");
 	case ID_POLY:
 	    p = (poly_t *) obj->props;
-	    printf("POLYGON (%d points, %s) { ", p->num_pts, p->type?"connected" : "disconnected");
+	    printf("\tPOLYGON (%d points, %s) { ", p->num_pts, p->type?"connected" : "disconnected");
 	    for (i = 0; i < p->num_pts; i++){
 		printf("(%g, %g) ", p->pts[i].x, p->pts[i].y);
 	    }
Index: branches/simulator/projects/simulator/simulator/core/world.h
===================================================================
--- branches/simulator/projects/simulator/simulator/core/world.h	(revision 1039)
+++ branches/simulator/projects/simulator/simulator/core/world.h	(revision 1040)
@@ -13,10 +13,11 @@
 
 #include <stdarg.h>
 
+#define ID_OFFSET -1
 #define ID_RECTANGLE 3
-#define ID_CIRCLE 1
-
-#define ID_POLY 0
+#define ID_CIRCLE 2
+#define ID_NULL 0
+#define ID_POLY 1
 #define POLY_DISCONNECTED 0
 #define POLY_CONNECTED 1
 #define POLY_RECT 2
@@ -24,6 +25,8 @@
 #define NUM_SHAPES 3
 #define RAY_MISS 1E30
 #define CREATE(id, ...) (create_func[id](__VA_ARGS__))
+#define PBBOX(b) {printf("(%g,%g) --> (%g, %g)\n",(b).p1.x,(b).p1.y,(b).p2.x,\
+						  (b).p2.y);}
 typedef struct {
     double x;
     double y;
@@ -52,9 +55,10 @@
 } object_t;
 
 typedef struct {
-    int num_objs;
+    int max_objs;
+    int cur_objs;
     object_t *objs;
-    bbox_t world;
+    bbox_t win; 
 } world_t;
 
 /* Specific collision functions */
@@ -66,11 +70,17 @@
  *  Must be listed in the same order as IDs */
 extern double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj);
 extern int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap);
+extern int (*destroy_func[NUM_SHAPES])(object_t *obj);
+extern world_t world;
 
-
+int init_world(int num_objs, bbox_t b);
+int destroy_world(void);
 int create_poly(object_t *obj, va_list ap);
+int destroy_poly(object_t *obj);
 object_t *create(int id, ...);
 
-void destroy_poly (object_t *obj);
+void print_world(void);
+void print_object(object_t *obj);
+
 #endif
 
