root / branches / simulator / projects / simulator / simulator / core / main.c @ 1128
History | View | Annotate | Download (1.66 KB)
1 |
/**
|
---|---|
2 |
* @file main.c
|
3 |
* @author Colony Project
|
4 |
* @brief Initializes the program.
|
5 |
*
|
6 |
* Contains only the main function, which
|
7 |
* initializes the program.
|
8 |
**/
|
9 |
|
10 |
#include <stdlib.h> |
11 |
#include <stdio.h> |
12 |
#include <gtk/gtk.h> |
13 |
#include <glib.h> |
14 |
#include <signal.h> |
15 |
#include <unistd.h> |
16 |
|
17 |
#include "gtk_gui.h" |
18 |
#include "robot.h" |
19 |
#include "world.h" |
20 |
#include "logger.h" |
21 |
#include "player.h" |
22 |
|
23 |
|
24 |
extern char *optarg; |
25 |
extern int optind, optopt; |
26 |
|
27 |
int main(int argc, char** argv) |
28 |
{ |
29 |
if (robots_initialize())
|
30 |
return -1; |
31 |
|
32 |
int c;
|
33 |
char worldLoadedFlag = 0; |
34 |
char *worldFile = NULL; |
35 |
|
36 |
while((c = getopt(argc, argv, ":p:w:l:")) != -1) |
37 |
{ |
38 |
switch(c)
|
39 |
{ |
40 |
case 'l': |
41 |
//What about when -w not set...
|
42 |
setWriteFile(optarg, worldFile); |
43 |
break;
|
44 |
case 'p': |
45 |
setReadFile(optarg, &worldFile); |
46 |
playLog(argc, argv); |
47 |
return 0; |
48 |
break;
|
49 |
case 'w': |
50 |
load_world(optarg, 100);
|
51 |
worldFile = optarg; |
52 |
worldLoadedFlag = 1;
|
53 |
break;
|
54 |
case ':': |
55 |
fprintf(stderr, "Argument requires file name\n");
|
56 |
break;
|
57 |
case '?': |
58 |
fprintf(stderr, "Unknown argument\n");
|
59 |
break;
|
60 |
} |
61 |
} |
62 |
|
63 |
if(argc - optind < 0){ |
64 |
printf("Usage: simulator <robot execetuable>\n");
|
65 |
exit(-1);
|
66 |
} |
67 |
|
68 |
if(!worldLoadedFlag)
|
69 |
load_world("../test/world.txt", 100); |
70 |
|
71 |
if (optind > 0 && optind < argc) |
72 |
robot_create(argv[optind]); |
73 |
|
74 |
sigset_t set; |
75 |
//TODO: errors
|
76 |
sigemptyset(&set); |
77 |
sigaddset(&set, SIGCHLD); |
78 |
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
79 |
g_thread_init(NULL);
|
80 |
gdk_threads_init(); |
81 |
g_thread_create(robot_event_loop, NULL, TRUE, NULL); |
82 |
|
83 |
//TODO: better thread to put this in?
|
84 |
sigemptyset(&set); |
85 |
sigaddset(&set, SIGCHLD); |
86 |
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
87 |
|
88 |
gtk_gui_run(argc, argv); |
89 |
|
90 |
return 0; |
91 |
} |
92 |
|