Statistics
| Revision:

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

History | View | Annotate | Download (2.07 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
        if(argc - optind < 0){
33
                printf("Usage: simulator <robot execetuable>\n");
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
                }
63
        }
64

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

    
68

    
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]);*/
89

    
90

    
91
        sigset_t set;
92
        //TODO: errors
93
        sigemptyset(&set);
94
        sigaddset(&set, SIGCHLD);
95
        pthread_sigmask(SIG_BLOCK, &set, NULL);
96
        g_thread_init(NULL);
97
        gdk_threads_init();
98
        g_thread_create(robot_event_loop, NULL, TRUE, NULL);
99
        
100
        //TODO: better thread to put this in?
101
        sigemptyset(&set);
102
        sigaddset(&set, SIGCHLD);
103
        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
104
        
105
        gtk_gui_run(argc, argv);
106

    
107
        return 0;
108
}
109