Esempio n. 1
0
static int
load_args(int argc, char* argv[], struct SSettings* psettings)
{
    int c;
    int ret = 1;

    assert(psettings != NULL);

    struct option long_options[] =
    {
        // these options do not set flags
        {"help",    no_argument, NULL, 'h'},
        {"version", no_argument, NULL, 'v'},
        {"simplified-mode", no_argument, NULL, 's'},
        {NULL, 0, NULL, 0}
    };
    
    while (1)
    {
        int option_index = 0;
        c = getopt_long(argc, argv, "s", long_options, &option_index);
        
        if (c == -1) // all options have been processed
        {
            break;
        }
        
        switch (c)
        {
        case 0:
            // If a flag was set, nothing more to do. If not...
            if (long_options[option_index].flag == 0)
            {
                assert(0); // should not get here
            }
            break;
            
        case 'h':
            show_usage();
            
            cleanup_settings(psettings);
            exit(EXIT_SUCCESS);
            break;
            
        case 'v':
            show_version();
            
            cleanup_settings(psettings);
            exit(EXIT_SUCCESS);
            break;
            
        case 's':
            psettings->is_simplified_mode = 1;
            break;
            
        case '?':
            // getopt_long should have already printed an error message.
            ret = 0;
            break;

        default:
            assert(0); // should not get here
            break;
        }
    }
    
    if (ret != 0)
    {
        if (argc != optind + 2)
        {
            // exactly 2 arguments should be still left unprocessed
            print_error(errBadArgCount); 
            ret = 0;
        }
        else 
        {
            // The first non-option argument should be the path to the template file
            // or directory, the second one should be the path of an input file with
            // values.
            psettings->tpl_path = mist_path_absolute(argv[optind]);
            if (psettings->tpl_path == NULL)
            {
                print_error(errAbsTplPathFail);
                cleanup_settings(psettings);
                exit(EXIT_FAILURE);
            }
            
            ++optind; // to the next argument
            
            psettings->val_path = mist_path_absolute(argv[optind]);
            if (psettings->val_path == NULL)
            {
                print_error(errAbsValPathFail);
                cleanup_settings(psettings);
                exit(EXIT_FAILURE);
            }
        }
    }
    return ret;
}
Esempio n. 2
0
File: main.c Progetto: Df458/Halberd
int main(int argc, char** argv)
{
    if(!glfwInit()) {
        error("Failed to intialize GLFW.");
        return 1;
    }

    GLFWwindow* win;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    win = glfwCreateWindow(800, 600, "Halberd", NULL, NULL);
    if(!win) {
        error("Unable to create window.");
        return 1;
    }
    glfwSetFramebufferSizeCallback(win, sizeCallback);
    glfwMakeContextCurrent(win);

	glewExperimental = 1;
	if(glewInit() != GLEW_OK) {
        error("glewInit() failed.");
        glfwDestroyWindow(win);
        return 1;
    }
    glGetError(); // Because GLEW is silly. <http://stackoverflow.com/questions/20034615/why-does-glewinit-result-in-gl-invalid-enum-after-making-some-calls-to-glfwwin>
    GLuint VAO; // FIXME: Stupid Hack. <http://stackoverflow.com/questions/13403807/glvertexattribpointer-raising-gl-invalid-operation>
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    init_graphics();
    update_camera(800, 600);
    init_input(win);
    init_player(0, 0);
    init_ui();
    init_settings();

    /*init_maps();*/
    // TODO: Figure out the correct way to start up
    /*get_tileset_id("Plains.png");*/
    /*load_maps("test");*/

    float delta = 0;
    glfwSetTime(0);
    do {
        delta = glfwGetTime();
        glfwSetTime(0);
        glfwPollEvents();

        if(!ui_present())
            update_player(delta);
        update_actors(delta);
        update_ui(delta);
        update_input_states(delta);

        render_game();

        glfwSwapBuffers(win);
    } while(!glfwWindowShouldClose(win) && get_input_state(4) != 2);

    destroy_player_actor();
    destroy_actors();
    /*destroy_maps();*/
    destroy_ui();
    destroy_graphics();
    cleanup_settings();

    glfwDestroyWindow(win);
    glfwTerminate();
    return 0;
}
Esempio n. 3
0
File: rqd.c Progetto: hyper/rqd
//-----------------------------------------------------------------------------
// Main... process command line parameters, and then setup our listening 
// sockets and event loop.
int main(int argc, char **argv) 
{
	system_data_t   sysdata;

///============================================================================
/// Initialization.
///============================================================================

	init_sysdata(&sysdata);
	init_settings(&sysdata);

	get_options(sysdata.settings, argc, argv);
	
	init_maxconns(&sysdata);
	init_daemon(&sysdata);
	init_events(&sysdata);
	init_logging(&sysdata);

	logger(sysdata.logging, 1, "System starting up");

	init_signals(&sysdata);
	init_buffers(&sysdata);
	init_servers(&sysdata);
	init_stats(&sysdata);
	init_risp(&sysdata);
	init_nodes(&sysdata);
	init_msglist(&sysdata);
	init_queues(&sysdata);
	init_controllers(&sysdata);


///============================================================================
/// Main Event Loop.
///============================================================================

	// enter the event loop.
	logger(sysdata.logging, 1, "Starting Event Loop");
	assert(sysdata.evbase);
	event_base_loop(sysdata.evbase, 0);
	logger(sysdata.logging, 1, "Shutdown preparations complete.  Shutting down now.");


///============================================================================
/// Shutdown
///============================================================================

	cleanup_events(&sysdata);
	cleanup_controllers(&sysdata);
	cleanup_queues(&sysdata);
	cleanup_msglist(&sysdata);
	cleanup_nodes(&sysdata);
	cleanup_risp(&sysdata);
	cleanup_stats(&sysdata);
	cleanup_servers(&sysdata);
	cleanup_buffers(&sysdata);
	cleanup_signals(&sysdata);
	
	logger(sysdata.logging, 1, "Shutdown complete.\n");

	cleanup_logging(&sysdata);
	cleanup_daemon(&sysdata);
	cleanup_maxconns(&sysdata);
	cleanup_settings(&sysdata);
	cleanup_sysdata(&sysdata);
	
	// good-bye.
	return 0;
}