Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / main.c @ 1077

History | View | Annotate | Download (1.56 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

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

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

    
68
        if (optind > 0 && optind < argc)
69
                robot_create(argv[optind]);
70

    
71
        sigset_t set;
72
        //TODO: errors
73
        sigemptyset(&set);
74
        sigaddset(&set, SIGCHLD);
75
        pthread_sigmask(SIG_BLOCK, &set, NULL);
76
        g_thread_init(NULL);
77
        gdk_threads_init();
78
        g_thread_create(robot_event_loop, NULL, TRUE, NULL);
79
        
80
        //TODO: better thread to put this in?
81
        sigemptyset(&set);
82
        sigaddset(&set, SIGCHLD);
83
        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
84
        
85
        gtk_gui_run(argc, argv);
86

    
87
        return 0;
88
}
89