Index: branches/simulator/projects/simulator/simulator/core/world.c
===================================================================
--- branches/simulator/projects/simulator/simulator/core/world.c	(revision 1042)
+++ branches/simulator/projects/simulator/simulator/core/world.c	(revision 1043)
@@ -59,7 +59,9 @@
     point_t p1 = ray->p;
     point_t p2 = {ray->p.x+cos(ray->d),ray->p.y+sin(ray->d)};
 
+#if DEBUG
     printf("(%g,%g) --> (%g,%g) with (%g,%g) --> (%g,%g)\n",p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y);
+#endif
     denom = (p2.y-p1.y)*(p4.x-p3.x)-(p2.x-p1.x)*(p4.y-p3.y);
     if (denom == 0) {
 	return RAY_MISS;
@@ -80,7 +82,9 @@
     xint = p3.x+ua*(p4.x-p3.x);
     yint = p3.y+ua*(p4.y-p3.y);
     dist = sqrt((xint-p1.x)*(xint-p1.x)+(yint-p1.y)*(yint-p1.y));
+#if DEBUG
     printf("Got: %g\n", dist);
+#endif
     return dist;
 
 }
@@ -166,9 +170,11 @@
     p->pts = malloc((argc) * sizeof(point_t));
     p->type = poly_type;
 
+		double *pts = va_arg(ap, double*);
+
     for(i=0;i < argc; i++) {
-	p->pts[i].x = va_arg(ap, double);
-	p->pts[i].y = va_arg(ap, double);
+			p->pts[i].x = pts[2*i];
+			p->pts[i].y = pts[2*i+1];
     }
     obj->id = ID_POLY;
     obj->bbox = NULL;
@@ -243,44 +249,34 @@
     }
 }
 
-
-int starts_with (const char* line, const char* word) {
-  do {
-    line++;
-    word++;
-  }while (*line == *word);
-  if (*word == '\n' || *word == '\0') return 0;
-  return 1;
-}
-
 int load_object (const char* line) {
   char buf[BUF_SIZE];
   int i = 0;
   int j;
   int id;
-  if (starts_with(line,"POLYGON") == 0){
+  if (strstr(line,"POLYGON") == line){
     int num;
     int type;
     double *pts;
     id = ID_POLY;
-    i = strlen("POLYGON")+1;
+    i = strlen("POLYGON") + 1;
 
     sscanf(line+i,"%s",buf);
     num = strtol(buf,NULL,0);
     i += strlen(buf) + 1;
 
-    if (starts_with(line+i,"CONNECTED") == 0){
+    if (strstr(line+i,"CONNECTED") == line+i){
       i += strlen("CONNECTED") + 1;
       type = POLY_CONNECTED;
-    }else if (starts_with(line+i,"DISCONNECTED") == 0){
+    }else if (strstr(line+i,"DISCONNECTED") == line+i){
       i += strlen("DISCONNECTED") + 1;
       type = POLY_DISCONNECTED;
-    }else if (starts_with(line+i,"RECT") == 0){
+    }else if (strstr(line+i,"RECT") == line+i){
       i += strlen("RECT") + 1;
       type = POLY_RECT;
     }else{
       // invalid input
-	fprintf(stderr,"Invalid input for POLYGON\n");
+			fprintf(stderr,"Invalid input for POLYGON\n");
       return -1;
     }
 
@@ -291,27 +287,42 @@
     for (j = 0;j < num;j++){
       pts[2*j] = strtod(c1,&c2);
       pts[2*j+1] = strtod(c2,&c1);
+#if DEBUG
       printf("%lf %lf\n",pts[2*j],pts[2*j+1]);
+#endif
     }
 
     create(id,num,type,pts);
     free(pts);
-  }
+  }else if (strstr(line,"CIRCLE") == line){
+		id = ID_CIRCLE;
+		i = strlen("CIRCLE") + 1;
+		//TODO
+	}else if (strstr(line,"RECTANGLE") == line){
+		id = ID_RECTANGLE;
+		i = strlen("RECTANGLE") + 1;
+		//TODO
+	}else{
+		//Invalid input
+#if DEBUG
+		fprintf(stderr,"Invalid object: %s",line);
+#endif
+	}
   return 0;
 }
 
-int load_world (const char* filename) {
+int load_world (const char* filename,int max_objs) {
   FILE* fin;
   char buf[BUF_SIZE];
   bbox_t bbox = {0,0,0,0};
   if ((fin = fopen(filename,"r"))==NULL){
     // open file failed
-	perror("Fail to open file");
+		perror("Fail to open file");
     return -1;
   }
   if (fgets(buf,512,fin) != NULL){
     sscanf(buf,"WORLD %lf %lf %lf %lf",&bbox.p1.x,&bbox.p1.y,&bbox.p2.x,&bbox.p2.y);
-    init_world(MAX_OBJS, bbox);
+    init_world(max_objs, bbox);
     while (fgets(buf,512,fin) != NULL){
       load_object(buf);
     }
Index: branches/simulator/projects/simulator/simulator/core/world.h
===================================================================
--- branches/simulator/projects/simulator/simulator/core/world.h	(revision 1042)
+++ branches/simulator/projects/simulator/simulator/core/world.h	(revision 1043)
@@ -32,7 +32,6 @@
 						  (b).p2.y);}
 #define PRAY(v) {printf("(%g,%g), %g\n", (v).p.x, (v).p.y,(v).d);}
 
-#define MAX_OBJS 100
 #define BUF_SIZE 512
 
 typedef struct {
@@ -96,9 +95,8 @@
 /* WORLD 0 0 512 512
  * POLYGON 3 CONNECTED 1 2 3 4 5 6
  */   
-int load_world (const char* filename);
+int load_world (const char* filename, int max_objs);
 int load_object (const char* line);
-int starts_with (const char* line, const char* word);
 
 #endif
 
