示例#1
0
文件: shex.cpp 项目: alexkh/shex
void Shex::loop() {
	SDL_Event e;
	bool quit = false;
	while(1) {
		// process events:
		while(SDL_WaitEvent(&e) != 0) {
			if(e.type == SDL_QUIT) {
				quit = true;
			}
			if(e.type == SDL_WINDOWEVENT &&
			(e.window.event ==SDL_WINDOWEVENT_RESIZED ||
			e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
				winw = e.window.data1;
				winh = e.window.data2;
				set_viewport();
			}
			if(e.type == SDL_MOUSEWHEEL) {
				if(e.wheel.y < 0) {
					doffset += 16;
				} else {
					if(doffset < 16) {
						doffset = 0;
					} else {
						doffset -= 16;
					}
				}
				load_data_file();
//				std::cout << e.wheel.y << std::endl;
			}
			if(e.type == SDL_KEYDOWN) {
				switch(e.key.keysym.sym) {
				case SDLK_HOME:
					doffset = 0;
					load_data_file();
					break;
				case SDLK_END:
					doffset = (dfsize - dfsize % 16);
					load_data_file();
					break;
				case SDLK_PAGEUP:
					doffset = (doffset < 400)? 0:
							doffset - 400;
					load_data_file();
					break;
				case SDLK_PAGEDOWN:
					doffset += 400;
					load_data_file();
					break;
				}
			}
			if(quit) break;
			draw();
		}
		if(quit) break;
	}
	SDL_GL_DeleteContext(glcontext);
	SDL_Quit();
}
示例#2
0
void
on_fileselect_ok                       (GtkButton       *button,
                                        gpointer         user_data)
{
    GtkWidget *filesel, *window3D, *save_procedure;
    gint what;
    gchar *filename;
    v5d_info *info;
    int hires;
    filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
    filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));

    what =  GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(filesel), "OpenWhat"));

    window3D = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(filesel), "window3D"));

    if(window3D==NULL) {
        fprintf(stderr,"Could not find window3D widget\n");
        exit ;
    }
    info = (v5d_info *) lookup_widget(window3D,"v5d_info");
    switch(what) {
    case DATA_FILE:
        load_data_file(window3D,filename);
        break;
    case TOPO_FILE:
        hires = vis5d_graphics_mode(info->v5d_display_context,VIS5D_HIRESTOPO,VIS5D_GET);
        vis5d_init_topo(info->v5d_display_context,filename,hires);
        vis5d_load_topo_and_map(info->v5d_display_context);
        break;
    case MAP_FILE:
        vis5d_init_map(info->v5d_display_context,filename);
        vis5d_load_topo_and_map(info->v5d_display_context);
        break;
    case PROCEDURE_FILE:
        if(info->ProcedureDialog)
            gtk_widget_destroy(info->ProcedureDialog);
        info->ProcedureDialog = new_ProcedureDialog(info, filename);
        gtk_window_set_transient_for(GTK_WINDOW(info->ProcedureDialog),GTK_WINDOW(window3D));
        break;
    case SAVE_PROCEDURE_FILE:
        if(! info->ProcedureDialog) {
            printf("Error: ProcedureDialog not defined\n");
            return;
        }
        save_procedure = lookup_widget(info->ProcedureDialog, "saveProcedure");
        on_saveProcedure_activate(GTK_MENU_ITEM(save_procedure), filename);
        break;
    default:
        g_print("open what ? %d\n",what);
    }

    gtk_widget_hide (filesel);
    /* This is the only window that should accept input */
    gtk_grab_remove(filesel);

}
示例#3
0
文件: flood.c 项目: kimhunter/flood
/*
** If we have a payload file name, we try to load the payload
** from that file. The file may be a Flood data file or it may
** contain raw payload data.
** If that crashes or if we only have a payload size, we create
** a (\0) byte filled payload of that (or of  DEFAULTPAYLOADSIZE)
** size. If we have neither a payload file name nor a payload size,
** we use an empty payload.
*/
int
create_payload( JOB_DATA *job_data )
{
    int ret;


    /*
    ** We have a payload file name, so we try to
    ** suck our payload from that file.
    */
    if ( job_data->datafile ) {

        ret = load_data_file( job_data );

        switch ( ret ) {

        case DF_FLOODDF:
            ret = build_payload_from_template( job_data );
            break;

        case DF_RAWDF:
            ret = load_raw_payload_from_file( job_data );
            break;

        case DF_ERROR:
            ret = -1;
            break;

        default:
            break;

        } /* switch */


        /*
        ** Got it.
        */
        if ( ret != -1 )
            return ret;

    } /* if */

    /*
    ** No payload file or trouble reading it...
    */
    return create_byte_filled_payload( job_data, 0 );

} /* create_payload */
示例#4
0
文件: shex.cpp 项目: alexkh/shex
int Shex::init_gl() {
	// enable smooth shading
	glShadeModel(GL_SMOOTH);
	// set the background red
	glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
	// depth buffer setup
	glClearDepth(1.0f);
	// enable depth testing
	glEnable(GL_DEPTH_TEST);
	// the type of depth test to do
	glDepthFunc(GL_LEQUAL);
	// really nice perspective calculations
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glGenTextures(8, tex);
	// load font:
	{
		int x, y, n;
		unsigned char *data = stbi_load(
			"/usr/share/shex/font.png", &x, &y, &n, 1);
		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, tex[1]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, x, y, 0,
			GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
						GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
						GL_NEAREST);
	}
	// load shaders:
	GLuint vshader = compile_shader(
		"/usr/share/shex/texbox.glsl", GL_VERTEX_SHADER);
	GLuint linen_shader = compile_shader(
		"/usr/share/shex/linen.glsl", GL_FRAGMENT_SHADER);
	sp_linen = build_sprogram(vshader, linen_shader);

	// load the data file at the beginning:
	if(load_data_file()) {
		std::cerr << "There was an error loading file " << datafname
			<< std::endl;
		return 1;
	}

	return 0;
}
bool setup_test(size_t object_size) {
    file_data = load_data_file(BENCHMARK_FORMAT_MESSAGEPACK, object_size, &file_size);
    if (!file_data)
        return false;
	return true;
}
示例#6
0
int
main(int argc, char *argv[])
{
	int r;

	char *data_file = NULL;
	char *save_file = NULL;

	int screen_width = DEFAULT_SCREEN_WIDTH;
	int screen_height = DEFAULT_SCREEN_HEIGHT;
	int fullscreen = 0;
	int game_map = 1;
	int map_generator = 0;
	int preserve_map_bugs = 0;

	int log_level = DEFAULT_LOG_LEVEL;

	int opt;
	while (1) {
		opt = getopt(argc, argv, "d:fg:hl:m:pr:t:");
		if (opt < 0) break;

		switch (opt) {
		case 'd':
		{
			int d = atoi(optarg);
			if (d >= 0 && d < LOG_LEVEL_MAX) {
				log_level = d;
			}
		}
			break;
		case 'f':
			fullscreen = 1;
			break;
		case 'g':
			data_file = malloc(strlen(optarg)+1);
			if (data_file == NULL) exit(EXIT_FAILURE);
			strcpy(data_file, optarg);
			break;
		case 'h':
			fprintf(stdout, HELP, argv[0]);
			exit(EXIT_SUCCESS);
			break;
		case 'l':
			save_file = malloc(strlen(optarg)+1);
			if (save_file == NULL) exit(EXIT_FAILURE);
			strcpy(save_file, optarg);
			break;
		case 'm':
			game_map = atoi(optarg);
			break;
		case 'p':
			preserve_map_bugs = 1;
			break;
		case 'r':
		{
			char *hstr = strchr(optarg, 'x');
			if (hstr == NULL) {
				fprintf(stderr, USAGE, argv[0]);
				exit(EXIT_FAILURE);
			}
			screen_width = atoi(optarg);
			screen_height = atoi(hstr+1);
		}
			break;
		case 't':
			map_generator = atoi(optarg);
			break;
		default:
			fprintf(stderr, USAGE, argv[0]);
			exit(EXIT_FAILURE);
			break;
		}
	}

	/* Set up logging */
	log_set_file(stdout);
	log_set_level(log_level);

	LOGI("main", "freeserf %s", FREESERF_VERSION);

	r = load_data_file(data_file);
	if (r < 0) {
		LOGE("main", "Could not load game data.");
		exit(EXIT_FAILURE);
	}

	free(data_file);

	gfx_data_fixup();

	LOGI("main", "SDL init...");

	r = sdl_init();
	if (r < 0) exit(EXIT_FAILURE);

	/* TODO move to right place */
	midi_play_track(MIDI_TRACK_0);
	audio_set_volume(75);

	/*gfx_set_palette(DATA_PALETTE_INTRO);*/
	gfx_set_palette(DATA_PALETTE_GAME);

	LOGI("main", "SDL resolution %ix%i...", screen_width, screen_height);

	r = sdl_set_resolution(screen_width, screen_height, fullscreen);
	if (r < 0) exit(EXIT_FAILURE);

	game.mission_level = game_map - 1; /* set game map */
	game.map_generator = map_generator;
	game.map_preserve_bugs = preserve_map_bugs;

	/* Init globals */
	allocate_global_memory();
	player_interface_init();

	/* Initialize global lookup tables */
	init_spiral_pattern();

	game_init();

	/* Either load a save game if specified or
	   start a new game. */
	if (save_file != NULL) {
		int r = game_load_save_game(save_file);
		if (r < 0) exit(EXIT_FAILURE);
		free(save_file);
	} else {
		game_load_random_map();
	}

	/* Move viewport to initial position */
	viewport_move_to_map_pos(&interface.viewport, interface.map_cursor_pos);

	/* Start game loop */
	game_loop();

	LOGI("main", "Cleaning up...");

	/* Clean up */
	audio_cleanup();
	sdl_deinit();
	gfx_unload();

	return EXIT_SUCCESS;
}
示例#7
0
int main(int argc, char **argv)
{
	void *data = NULL, *data2 = NULL;
	unsigned sz, sz2;
	usb_handle *usb = NULL;
	int once = 1;
	int fastboot_mode = 0;
	char proctype[8];

	if ((argc < 2) || (argc > 3)) {
		usage();
		return 0;
	}

	if ((argv[1][0] == '-') &&
		(((argv[1][1] == 'f') || ((argv[1][1] == 'F'))) ||
		((argv[1][1] == 'm') || ((argv[1][1] == 'M'))))) {

		for (;;) {
			usb = usb_open(match_omap_bootloader);
			if (usb) {
				strcpy(proctype, usb_boot_read_chip_info(usb));
				if (!memcmp(proctype, "EMU", 3)) {
					if (argc == 3)
						data = load_data_file(argv[2],
							sz);
					else
						data = load_data_file(NULL, sz);
#ifdef EMBED_IBOOT_HS
					if (!data) {
						fprintf(stderr, "using built-in"
						" HS iboot of size %d-KB\n",
							iboot_hs_size/1024);

						data = iboot_hs_data;
						sz = iboot_hs_size;
					}
#endif
				} else {
					fprintf(stderr, "using built-in GP "
						"iboot of size %d-KB\n",
							iboot_gp_size/1024);
					data = iboot_gp_data;
					sz = iboot_gp_size;
				}

				if (!data)
					return -1;

#ifdef TWO_STAGE_OMAPBOOT
				fprintf(stderr, "using built-in sboot of size \
						%d-KB\n", sboot_size/1024);
				data2 = sboot_data;
				sz2 = sboot_size;

				if (data2 == 0) {
					usage();

					/* free up memory */
					if (data)
						free(data);

					return -1;
				}
				fastboot_mode = ((argv[1][1]) - 30) |
								USER_RQ_MASK;
				printf("fastboot_mode = %08x\n", fastboot_mode);
#endif
				break;
			}
			if (once) {
				once = 0;
				fprintf(stderr, "waiting for device...\n");
			}
			usleep(250);
		}

		once = 1;
#ifndef TWO_STAGE_OMAPBOOT
		fastboot_mode = 1;
		data2 = 0;
		sz2 = 0;
#endif
	} else {
		if (argc < 3) {
示例#8
0
int
main(int argc, char *argv[])
{
	int r;

	char *data_file = NULL;
	char *save_file = NULL;

	int map_generator = 0;


	log_set_file(stdout);

	init_config_data();

	//- read config data
	int screen_width = get_config_int(CONFIG_SCREEN_WIDTH, DEFAULT_SCREEN_WIDTH);
	int screen_height = get_config_int(CONFIG_SCREEN_HEIGHT, DEFAULT_SCREEN_HEIGHT);
	int fullscreen = get_config_bool(CONFIG_FULLSCREEN, 0);
	int log_level = get_config_int(CONFIG_LOGGLEVEL, DEFAULT_LOG_LEVEL);
	enum_lng_t language = str_to_lagEnum((char *)get_config_string(CONFIG_LANGUAGE, "EN"));
	int play_midi = get_config_bool(CONFIG_MUSIC, 1);
	int play_SFX = get_config_bool(CONFIG_SFX, 1);
	int volume = get_config_int(CONFIG_VOLUME, 75);

	//- read command line parameters
	int opt;
	while (1) {
		opt = getopt(argc, argv, "d:fg:hl:r:t:s:");
		if (opt < 0) break;

		switch (opt) {
		case 'd':
			{
				int d = atoi(optarg);
				if (d >= 0 && d < LOG_LEVEL_MAX) {
					log_level = d;
				}
			}
			break;
		case 'f':
			fullscreen = 1;
			break;
		case 'g':
			data_file = (char *)malloc(strlen(optarg)+1);
			if (data_file == NULL) exit(EXIT_FAILURE);
			strcpy(data_file, optarg);
			break;
		case 'h':
			fprintf(stdout, HELP, argv[0]);
			exit(EXIT_SUCCESS);
			break;
		case 'l':
			save_file = (char *)malloc(strlen(optarg)+1);
			if (save_file == NULL) exit(EXIT_FAILURE);
			strcpy(save_file, optarg);
			break;
		case 'r':
			{
				char *hstr = strchr(optarg, 'x');
				if (hstr == NULL) {
					fprintf(stderr, USAGE, argv[0]);
					exit(EXIT_FAILURE);
				}
				screen_width = atoi(optarg);
				screen_height = atoi(hstr+1);
			}
			break;
		case 't':
			map_generator = atoi(optarg);
			break;
		case 's':
			{
				char *  tmp_language_str = (char *) malloc(strlen(optarg) + 1);
				if (tmp_language_str != NULL)
				{
					strcpy(tmp_language_str, optarg);
					language = str_to_lagEnum(tmp_language_str);
				}
			}
			break;
		default:
			fprintf(stderr, USAGE, argv[0]);
			exit(EXIT_FAILURE);
			break;
		}
	}

	/* Set up logging */
	log_set_level((log_level_t)log_level);

	LOGI("main", "freeserf %s", FREESERF_VERSION);

	/* load language */
	init_language_data(language);


	r = load_data_file(data_file);
	if (r < 0) {
		LOGE("main", "Could not load game data.");
		exit(EXIT_FAILURE);
	}

	free(data_file);

	gfx_data_fixup();

	LOGI("main", "SDL init...");

	r = sdl_init();
	if (r < 0) exit(EXIT_FAILURE);

	/* TODO move to right place */
	midi_play_track(MIDI_TRACK_0);
	audio_set_volume(volume);

	midi_enable(play_midi);
	sfx_enable(play_SFX);


	/*gfx_set_palette(DATA_PALETTE_INTRO);*/
	gfx_set_palette(DATA_PALETTE_GAME);

	LOGI("main", "SDL resolution %ix%i...", screen_width, screen_height);

	r = sdl_set_resolution(screen_width, screen_height, fullscreen);
	if (r < 0) exit(EXIT_FAILURE);

	game.map_generator = map_generator;

	/* Initialize global lookup tables */
	init_spiral_pattern();

	game_init();

	/* Initialize Missions*/
	init_mission("missions.xml");

	/* Initialize interface */
	interface_init(&interface);
	gui_object_set_size((gui_object_t *)&interface,
			    screen_width, screen_height);
	gui_object_set_displayed((gui_object_t *)&interface, 1);

	/* Either load a save game if specified or
	   start a new game. */
	if (save_file != NULL) {
		int r = game_load_save_game(save_file);
		if (r < 0) exit(EXIT_FAILURE);
		free(save_file);

		interface_set_player(&interface, 0);
	} else {
		int r = game_load_random_map(3, &interface.random);
		if (r < 0) exit(EXIT_FAILURE);

		/* Add default player */
		r = game_add_player(12, 64, 40, 40, 40);
		if (r < 0) exit(EXIT_FAILURE);

		interface_set_player(&interface, r);
	}

	viewport_map_reinit();

	if (save_file != NULL) {
		interface_close_game_init(&interface);
	}

	/* Start game loop */
	game_loop();

	LOGI("main", "Cleaning up...");

	/* Clean up */
	map_deinit();
	viewport_map_deinit();
	audio_cleanup();
	sdl_deinit();
	gfx_unload();
	language_cleanup();
	mission_cleanup();
	config_cleanup();

	return EXIT_SUCCESS;
}