Project

General

Profile

Revision 1068

Added replay functionality and command line arguments

-l <filename> log simulation to file [currently make sure file does not
exist, overwriting of files not handled well]

-p <filename> run a log file rather than simulation

-w <filename> load in world file

View differences:

main.c
12 12
#include <gtk/gtk.h>
13 13
#include <glib.h>
14 14
#include <signal.h>
15
#include <unistd.h>
15 16

  
16 17
#include "gtk_gui.h"
17 18
#include "robot.h"
18 19
#include "world.h"
20
#include "logger.h"
21
#include "player.h"
19 22

  
23

  
24
extern char *optarg;
25
extern int optind, optopt;
26

  
20 27
int main(int argc, char** argv)
21 28
{
22 29
	if (robots_initialize())
23 30
		return -1;
24 31

  
25
	if(argc<=1){
32
	if(argc - optind < 0){
26 33
		printf("Usage: simulator <robot execetuable>\n");
27 34
		exit(-1);
35
	}        
36

  
37
	int c;
38
    char worldLoadedFlag = 0;
39

  
40
	while((c = getopt(argc, argv, ":l:p:w:")) != -1)
41
	{
42
		switch(c)
43
		{
44
			case 'l':
45
				setLogFile(optarg);
46
				break;
47
			case 'p':
48
				setLogFile(optarg);
49
				playLog(argc, argv);
50
				return 0;
51
				break;
52
			case 'w':
53
				load_world(optarg, 100);
54
				worldLoadedFlag = 1;
55
				break;
56
			case ':':
57
				fprintf(stderr, "Argument requires file name\n");
58
				break;
59
			case '?':
60
				fprintf(stderr, "Unknown argument\n");
61
				break;
62
		}
28 63
	}
29 64

  
30
	load_world("../test/world.txt", 100);
65
	if(!worldLoadedFlag)
66
		load_world("../test/world.txt", 100);
31 67

  
32 68

  
33
	robot_create(argv[1]);
34
	robot_create(argv[1]);
35
	robot_create(argv[1]);
36
	robot_create(argv[1]);
37
	robot_create(argv[1]);
38
	robot_create(argv[1]);
39
	robot_create(argv[1]);
40
	robot_create(argv[1]);
41
	robot_create(argv[1]);
42
	robot_create(argv[1]);
43
	robot_create(argv[1]);
44
	robot_create(argv[1]);
45
	robot_create(argv[1]);
46
	robot_create(argv[1]);
47
	robot_create(argv[1]);
48
	robot_create(argv[1]);
49
	robot_create(argv[1]);
50
	robot_create(argv[1]);
51
	robot_create(argv[1]);
52
	robot_create(argv[1]);
69
	robot_create(argv[optind]);
70
	robot_create(argv[optind]);
71
	robot_create(argv[optind]);
72
	robot_create(argv[optind]);
73
	robot_create(argv[optind]);
74
	robot_create(argv[optind]);
75
	robot_create(argv[optind]);
76
	robot_create(argv[optind]);
77
	robot_create(argv[optind]);
78
	robot_create(argv[optind]);
79
	robot_create(argv[optind]);
80
	robot_create(argv[optind]);
81
	robot_create(argv[optind]);
82
	robot_create(argv[optind]);
83
	robot_create(argv[optind]);
84
	robot_create(argv[optind]);
85
	robot_create(argv[optind]);
86
	robot_create(argv[optind]);
87
	robot_create(argv[optind]);
88
	robot_create(argv[optind]);
53 89

  
54 90

  
55 91
	sigset_t set;

Also available in: Unified diff