void ReplaceColorCommand::onExecute(Context* context) { Site site = context->activeSite(); ReplaceColorFilterWrapper filter(site.layer()); filter.setFrom(get_config_color(ConfigSection, "Color1", ColorBar::instance()->getFgColor())); filter.setTo(get_config_color(ConfigSection, "Color2", ColorBar::instance()->getBgColor())); filter.setTolerance(get_config_int(ConfigSection, "Tolerance", 0)); FilterManagerImpl filterMgr(context, &filter); filterMgr.setTarget(TARGET_RED_CHANNEL | TARGET_GREEN_CHANNEL | TARGET_BLUE_CHANNEL | TARGET_GRAY_CHANNEL | TARGET_ALPHA_CHANNEL); ReplaceColorWindow window(filter, filterMgr); if (window.doModal()) { set_config_color(ConfigSection, "From", filter.getFrom()); set_config_color(ConfigSection, "To", filter.getTo()); set_config_int(ConfigSection, "Tolerance", filter.getTolerance()); } }
ArilouTrapper::ArilouTrapper(Vector2 opos, double shipAngle, ShipData *shipData, unsigned int code) : Ship(opos, shipAngle, shipData, code) { STACKTRACE; weapon_sample -= 1; regenrateFrames = 400; regenerating = FALSE; rechargeAmount = get_config_int("Ship", "rechargeAmount", 0); drainDelay = get_config_int("Trap", "drainDelay", 0); drainAmount = get_config_int("Trap", "drainAmount", 0); trapTurn = get_config_float("Trap", "trapTurn", 0); trapInitialVelocity = get_config_float("Trap", "initialVelocity", 0); weaponRange = scale_range(get_config_float("Weapon", "Range", 0)); trapAccel = get_config_float("Trap", "Accel", 0); weaponVelocity = scale_velocity(get_config_float("Weapon", "Velocity", 0)); weaponDamage = get_config_int("Weapon", "Damage", 0); weaponArmour = get_config_int("Weapon", "Armour", 0); weaponDuration = get_config_int("Weapon", "Duration", 0); quasiVelocity = scale_velocity(get_config_float("Ship","quasiVelocity", 0)); normalRechargeAmount = recharge_amount; cloak = FALSE; cloak_frame = 0; }
void gui_init(void) { int x,y,n; /* Loop counters */ char ini_colours[256]; /* For reading in colour values from the ini */ char **ini_colvals; /* The array of ini colour values */ int argc; /* The number of ini colour values */ /* We need the mouse, so we'll init that */ install_mouse(); /* Read the desired width & height from the ini file */ GUI_SCREEN_W = get_config_int("[gui]","width",640); GUI_SCREEN_H = get_config_int("[gui]","height",480); /* Set the graphics mode */ set_gfx_mode(GFX_AUTODETECT,GUI_SCREEN_W,GUI_SCREEN_H,0,0); clear(screen); /* Create the back-buffer */ gui_buffer = create_bitmap(GUI_SCREEN_W, GUI_SCREEN_H); /* Create the mouse pointer bitmap */ gui_mouse = create_bitmap(11,19); /* Read in the colours from the ini file */ damp_gfx_palette[GUI_COLOUR_BACKGROUND].r = damp_gfx_palette[GUI_COLOUR_BACKGROUND].g = damp_gfx_palette[GUI_COLOUR_BACKGROUND].b = 32; damp_gfx_palette[GUI_COLOUR_SHADOW].r = damp_gfx_palette[GUI_COLOUR_SHADOW].g = damp_gfx_palette[GUI_COLOUR_SHADOW].b = 0; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].r = damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].g = damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].b = 63; damp_gfx_palette[GUI_COLOUR_WINDOW].r = 63; damp_gfx_palette[GUI_COLOUR_WINDOW].g = damp_gfx_palette[GUI_COLOUR_WINDOW].b = 0; sprintf(ini_colours,get_config_string("[gui]","colours","gui_c_default")); ini_colvals = get_config_argv(ini_colours,"background",&argc); damp_gfx_palette[GUI_COLOUR_BACKGROUND].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_BACKGROUND].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_BACKGROUND].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"titlebar",&argc); damp_gfx_palette[GUI_COLOUR_WINDOW].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_WINDOW].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_WINDOW].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"highlight",&argc); damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"shadow",&argc); damp_gfx_palette[GUI_COLOUR_SHADOW].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_SHADOW].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_SHADOW].b = atoi(ini_colvals[2]) / 4; set_palette(damp_gfx_palette); /* Initialise the variables */ gui_num_windows = 0; gui_window_dragging = -1; gui_titlebar_height = text_height(font)+4; gui_border_size = 4; /* Initialise the mouse pointer */ clear(gui_mouse); n=0; for(y=0;y<19;y++) for(x=0;x<11;x++) { if(gui_mouse_data[n] == 0) putpixel(gui_mouse,x,y,0); else if(gui_mouse_data[n] == 1) putpixel(gui_mouse,x,y,GUI_COLOUR_SHADOW); else putpixel(gui_mouse,x,y,GUI_COLOUR_HIGHLIGHT); n++; } }
/* be_midi_init: * Initializes the BeOS MIDI driver. */ extern "C" int be_midi_init(int input, int voices) { char tmp[256], tmp2[128], tmp3[128] = EMPTY_STRING; char *sound = uconvert_ascii("sound", tmp); int mode, freq, quality, reverb; synth_mode sm = B_BIG_SYNTH; interpolation_mode im = B_2_POINT_INTERPOLATION; char *reverb_name[] = { "no", "closet", "garage", "ballroom", "cavern", "dungeon" }; if (input) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Input is not supported")); return -1; } _be_midisynth = new BMidiSynth(); if (!_be_midisynth) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory")); return -1; } /* Checks if instruments are available */ mode = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_quality", tmp), 1), 1); if (mode) sm = B_BIG_SYNTH; else sm = B_LITTLE_SYNTH; if ((be_synth->LoadSynthData(sm) != B_OK) || (!be_synth->IsLoaded())) { delete _be_midisynth; _be_midisynth = NULL; ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not load MIDI instruments data file")); return -1; } /* Sets up synthetizer and loads instruments */ _be_midisynth->EnableInput(true, true); /* Prevents other apps from changing instruments on the fly */ _be_midisynth->FlushInstrumentCache(true); /* Reverberation is cool */ reverb = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_reverb", tmp), 0), 5); if (reverb) { be_synth->SetReverb((reverb_mode)reverb); be_synth->EnableReverb(true); } else be_synth->EnableReverb(false); /* Sets sampling rate and sample interpolation method */ freq = get_config_int(sound, uconvert_ascii("be_midi_freq", tmp), 22050); quality = CLAMP(0, get_config_int(sound, uconvert_ascii("be_midi_interpolation", tmp), 1), 2); be_synth->SetSamplingRate(freq); switch (quality) { case 0: im = B_DROP_SAMPLE; break; case 1: im = B_2_POINT_INTERPOLATION; do_uconvert("fast", U_ASCII, tmp3, U_CURRENT, sizeof(tmp3)); break; case 2: im = B_LINEAR_INTERPOLATION; do_uconvert("linear", U_ASCII, tmp3, U_CURRENT, sizeof(tmp3)); break; } be_synth->SetInterpolation(im); /* Sets up driver description */ uszprintf(be_midi_driver_desc, sizeof(be_midi_driver_desc), uconvert_ascii("BeOS %s quality synth, %s %d kHz, %s reverberation", tmp), uconvert_ascii(mode ? "high" : "low", tmp2), tmp3, (be_synth->SamplingRate() / 1000), reverb_name[reverb]); midi_beos.desc = be_midi_driver_desc; return 0; }
int main(int argc, char **argv) { network_mysqld_table *table; /* read the command-line options */ GOptionContext *option_ctx; GOptionGroup *option_grp; GError *gerr = NULL; int i; int exit_code = 0; int print_version = 0; int daemon_mode = 0; int start_proxy = 1; const gchar *check_str = NULL; gchar *partition_info_host = NULL; gchar *partition_info_db = NULL; gchar *db_user = NULL; gchar *db_passwd = NULL; gchar *config_file = NULL; gchar *log_file = NULL; gchar *max_conn_pool = NULL; int log_all_queries = 0; int log_debug_msgs = 0; int log_raw_data = 0; GOptionEntry admin_entries[] = { { "admin-address", 'a', 0, G_OPTION_ARG_STRING, NULL, "listening address:port of internal admin-server (default: :4041)", "<host:port>"}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; GOptionEntry proxy_entries[] = { { "proxy-address", 'p', 0, G_OPTION_ARG_STRING, NULL, "listening address:port of the proxy-server (default: :4040)", "<host:port>"}, { "partition-info-host", 'h', 0, G_OPTION_ARG_STRING, NULL, "host name of table partition info (default: not set)", "<host>"}, { "partition-info-database", 'd', 0, G_OPTION_ARG_STRING, NULL, "database name of table partition info (default: not set)", "<database>"}, { "db-user", 'u', 0, G_OPTION_ARG_STRING, NULL, "db user for connecting to the proxy and database partititons (default: not set)", "<userid>"}, { "db-user-password", 'P', 0, G_OPTION_ARG_STRING, NULL, "db user password for connecting to the proxy and database partititons (default: not set)", "password"}, { "proxy-skip-profiling", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, NULL, "disables profiling of queries (default: enabled)", NULL}, { "proxy-fix-bug-25371", 0, 0, G_OPTION_ARG_NONE, NULL, "fix bug #25371 (mysqld > 5.1.12) for older libmysql versions", NULL}, { "proxy-lua-script", 0, 0, G_OPTION_ARG_STRING, NULL, "filename of the lua script (default: not set)", "<file>"}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; GOptionEntry main_entries[] = { { "version", 'V', 0, G_OPTION_ARG_NONE, NULL, "Show version", NULL}, { "daemon", 'D', 0, G_OPTION_ARG_NONE, NULL, "Start in daemon-mode", NULL}, { "pid-file", 0, 0, G_OPTION_ARG_STRING, NULL, "PID file in case we are started as daemon", "<file>"}, { "config-file", 'c', 0, G_OPTION_ARG_STRING, NULL, "configuration file (default is ./xxfs_dbproxy.conf)", "<file>"}, { "log-file", 'l', 0, G_OPTION_ARG_STRING, NULL, "log file (default is not set, using syslog)", "<file>"}, { "max-conn-pool-size", 'm', 0, G_OPTION_ARG_STRING, NULL, "max backend connections for each shard(default: 50)", "<number>"}, { "log-all-queries", 'L', 0, G_OPTION_ARG_NONE, NULL, "Log all queries(default: disabled)", NULL}, { "log-debug-messages", 'g', 0, G_OPTION_ARG_NONE, NULL, "Log debug messages(default: disabled)", NULL}, { "log-raw-data", 'r', 0, G_OPTION_ARG_NONE, NULL, "Log raw data sent/recved(default: disabled)", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; if (!GLIB_CHECK_VERSION(2, 6, 0)) { log_error("the glib header are too old, need at least 2.6.0, got: %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); } check_str = glib_check_version(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); if (check_str) { log_error("%s, got: lib=%d.%d.%d, headers=%d.%d.%d", check_str, glib_major_version, glib_minor_version, glib_micro_version, GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); } srv = network_mysqld_init(); srv->config.network_type = NETWORK_TYPE_PROXY; /* doesn't matter anymore */ srv->config.proxy.fix_bug_25371 = 0; /** double ERR packet on AUTH failures */ srv->config.proxy.profiling = 1; srv->config.proxy.log_debug_messages = 1; set_debug_msg_logging(true); i = 0; admin_entries[i++].arg_data = &(srv->config.admin.address); i = 0; proxy_entries[i++].arg_data = &(srv->config.proxy.address); proxy_entries[i++].arg_data = &partition_info_host; proxy_entries[i++].arg_data = &partition_info_db; proxy_entries[i++].arg_data = &db_user; proxy_entries[i++].arg_data = &db_passwd; proxy_entries[i++].arg_data = &(srv->config.proxy.profiling); proxy_entries[i++].arg_data = &(srv->config.proxy.fix_bug_25371); proxy_entries[i++].arg_data = &(srv->config.proxy.lua_script); i = 0; main_entries[i++].arg_data = &(print_version); main_entries[i++].arg_data = &(daemon_mode); main_entries[i++].arg_data = &(srv->config.pid_file); main_entries[i++].arg_data = &config_file; main_entries[i++].arg_data = &log_file; main_entries[i++].arg_data = &max_conn_pool; main_entries[i++].arg_data = &log_all_queries; main_entries[i++].arg_data = &log_debug_msgs; main_entries[i++].arg_data = &log_raw_data; option_ctx = g_option_context_new("- SpockProxy"); g_option_context_add_main_entries(option_ctx, main_entries, GETTEXT_PACKAGE); option_grp = g_option_group_new("admin", "admin module", "Show options for the admin-module", NULL, NULL); g_option_group_add_entries(option_grp, admin_entries); g_option_context_add_group(option_ctx, option_grp); option_grp = g_option_group_new("proxy", "proxy-module", "Show options for the proxy-module", NULL, NULL); g_option_group_add_entries(option_grp, proxy_entries); g_option_context_add_group(option_ctx, option_grp); if (FALSE == g_option_context_parse(option_ctx, &argc, &argv, &gerr)) { log_error("%s", gerr->message); g_error_free(gerr); return -1; } g_option_context_free(option_ctx); if (config_file && config_file[0] != '\0') load_config_file(config_file); else load_config_file("xxfs_dbproxy.conf"); add_config_string("PARTITION_INFO_HOST", partition_info_host); add_config_string("PARTITION_INFO_DB", partition_info_db); add_config_string("DB_USER", db_user); add_config_string("DB_PASSWD", db_passwd); add_config_string("LOGFILE", log_file); add_config_string("MAX_CONN_POOL_SIZE", max_conn_pool); add_config_string("LOG_ALL_QUERIES", log_all_queries ? "1" : "0"); add_config_string("LOG_DEBUG_MSG", log_debug_msgs ? "1" : "0"); add_config_string("LOG_RAW_DATA", log_raw_data ? "1" : "0"); if (srv->config.admin.address == NULL) srv->config.admin.address = g_strdup(get_config_string("ADMIN_ADDRESS")); if (srv->config.proxy.address == NULL) srv->config.proxy.address = g_strdup(get_config_string("PROXY_ADDRESS")); srv->config.proxy.profiling = get_config_int("SKIP_PROFILING", srv->config.proxy.profiling); srv->config.proxy.fix_bug_25371 = get_config_int("FIX_BUG_25371", srv->config.proxy.fix_bug_25371); if (srv->config.proxy.lua_script == NULL) srv->config.proxy.lua_script = get_config_string("LUA_SCRIPT"); srv->config.proxy.log_debug_messages = get_config_int("LOG_DEBUG_MSG", srv->config.proxy.log_debug_messages); set_debug_msg_logging(srv->config.proxy.log_debug_messages); print_version = get_config_int("PRINT_PROXY_VERSION", print_version); daemon_mode = get_config_int("DAEMON_MODE", daemon_mode); if (srv->config.pid_file == NULL) srv->config.pid_file = get_config_string("PID_FILE"); #if defined(HAVE_LUA_H) && defined(LIBDIR) /** * if the LUA_PATH is not set, set a good default */ if (!g_getenv("LUA_PATH")) { g_setenv("LUA_PATH", LUA_PATHSEP LUA_PATHSEP LIBDIR "/?.lua", 1); } #endif if (print_version) { printf("%s, build time: %s %s\r\n", PACKAGE_STRING, __DATE__, __TIME__); return 0; } log_info("%s, build time: %s %s\r\n", PACKAGE_STRING, __DATE__, __TIME__); if(database_lookup_load() <0) exit(0); if (start_proxy) { if (!srv->config.proxy.address) srv->config.proxy.address = g_strdup(":4040"); if (!srv->config.proxy.backend_addresses) { srv->config.proxy.backend_addresses = g_new0(char *, 2); srv->config.proxy.backend_addresses[0] = g_strdup("127.0.0.1:3306"); } }
int main(int argc, const char *const *argv) /* I'm const-crazy! */ { DUH *duh; /* Encapsulates the music file. */ AL_DUH_PLAYER *dp; /* Holds the current playback state. */ /* Initialise Allegro */ if (allegro_init()) return EXIT_FAILURE; /* Check that we have one argument (plus the executable name). */ if (argc != 2) usage(argv[0]); /* Tell Allegro where to find configuration data. This means you can * put any settings for Allegro in dumb.ini. See Allegro's * documentation for more information. */ set_config_file("dumb.ini"); /* Initialise Allegro's keyboard input. */ if (install_keyboard()) { allegro_message("Failed to initialise keyboard driver!\n"); return EXIT_FAILURE; } /* This function call is appropriate for a program that will play one * sample or one audio stream at a time. If you have sound effects * too, you may want to increase the parameter. See Allegro's * documentation for details on what the parameter means. Note that * newer versions of Allegro act as if set_volume_per_voice() was * called with parameter 1 initially, while older versions behave as * if -1 was passed, so you should call the function if you want * consistent behaviour. */ set_volume_per_voice(0); /* Initialise Allegro's sound output system. */ if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) { allegro_message("Failed to initialise sound driver!\n%s\n", allegro_error); return EXIT_FAILURE; } /* dumb_exit() is a function defined by DUMB. This operation arranges * for dumb_exit() to be called last thing before the program exits. * dumb_exit() does a bit of cleaning up for you. atexit() is * declared in stdlib.h. */ atexit(&dumb_exit); /* DUMB defines its own wrappers for file input. There is a struct * called DUMBFILE that holds function pointers for the various file * operations needed by DUMB. You can decide whether to use stdio * FILE objects, Allegro's PACKFILEs or something else entirely. No * wrapper is installed initially, so you must call this or * dumb_register_stdfiles() or set up your own before trying to load * modules by file name. (If you are using another method, such as * loading an Allegro datafile with modules embedded in it, then DUMB * never opens a file by file name so this doesn't apply.) */ dumb_register_packfiles(); /* Load the module file into a DUH object. Quick and dirty: try the * loader for each format until one succeeds. Note that 15-sample * mods have no identifying features, so dumb_load_mod() may succeed * on files that aren't mods at all. We therefore try that one last. */ duh = dumb_load_it(argv[1]); if (!duh) { duh = dumb_load_xm(argv[1]); if (!duh) { duh = dumb_load_s3m(argv[1]); if (!duh) { duh = dumb_load_mod(argv[1]); if (!duh) { allegro_message("Failed to load %s!\n", argv[1]); return EXIT_FAILURE; } } } } /* Read the quality values from the config file we told Allegro to * use. You may want to hardcode these or provide a more elaborate * interface via which the user can control them. */ dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 4); dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 128); /* If we're not in DOS, show a window and register our close hook * function. */ # ifndef ALLEGRO_DOS { const char *fn = get_filename(argv[1]); gfx_half_width = strlen(fn); if (gfx_half_width < 22) gfx_half_width = 22; gfx_half_width = (gfx_half_width + 2) * 4; /* set_window_title() is not const-correct (yet). */ set_window_title((char *)"DUMB Music Player"); if (set_gfx_mode(GFX_DUMB_MODE, gfx_half_width*2, 80, 0, 0) == 0) { acquire_screen(); textout_centre(screen, font, fn, gfx_half_width, 20, 14); textout_centre(screen, font, "Press any key to exit.", gfx_half_width, 52, 11); release_screen(); } else gfx_half_width = 0; } /* Silly check to get around the fact that someone stupidly removed * an old function from Allegro instead of deprecating it. The old * function was put back a version later, but we may as well use the * new one if it's there! */ # if ALLEGRO_VERSION*10000 + ALLEGRO_SUB_VERSION*100 + ALLEGRO_WIP_VERSION >= 40105 set_close_button_callback(&closehook); # else set_window_close_hook(&closehook); # endif # endif /* We want to continue running if the user switches to another * application. */ set_display_switch_mode(SWITCH_BACKGROUND); /* We have the music loaded, but it isn't playing yet. This starts it * playing. We construct a second object, the AL_DUH_PLAYER, to * represent the playing music. This means you can play the music * twice at the same time should you want to! * * Specify the number of channels (2 for stereo), which 'signal' to * play (always 0 for modules), the volume (1.0f for default), the * buffer size (4096 generally works well) and the sampling frequency * (ideally match the final output frequency Allegro is using). An * Allegro audio stream will be started. */ dp = al_start_duh(duh, 2, 0, 1.0f, get_config_int("sound", "buffer_size", 4096), get_config_int("sound", "sound_freq", 44100)); /* Register our callback functions so that they are called when the * music loops or stops. See docs/howto.txt for more information. * There is no threading issue: DUMB will only process playback * in al_poll_duh(), which we call below. */ { DUH_SIGRENDERER *sr = al_duh_get_sigrenderer(dp); DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(sr); dumb_it_set_loop_callback(itsr, &loop_callback, NULL); dumb_it_set_xm_speed_zero_callback(itsr, &xm_speed_zero_callback, NULL); } /* Main loop. */ for (;;) { /* Check for keys in the buffer. If we get one, discard it * and exit the main loop. */ if (keypressed()) { readkey(); break; } /* Poll the music. We exit the loop if al_poll_duh() has * returned nonzero (music finished) or the window has been * closed. al_poll_duh() might return nonzero if you have set * up a callback that tells the music to stop. */ if (al_poll_duh(dp) || closed) break; /* Give other threads a look-in, or allow the processor to * sleep for a bit. YIELD() is defined further up in this * file. */ YIELD(); } /* Remove the audio stream and deallocate the memory being used for * the playback state. We set dp to NULL to emphasise that the object * has gone. */ al_stop_duh(dp); dp = NULL; /* Free the DUH object containing the actual music data. */ unload_duh(duh); duh = NULL; /* All done! */ return EXIT_SUCCESS; }
void init_config(void) { set_config_file("lacew.cfg"); char miscstring [40]; char wstring [40]; char itstring [40]; int i; options.sound_init = get_config_int("Options", "Sound_init", 1); options.sound_mode = get_config_int("Options", "Sound_mode", SOUNDMODE_STEREO); options.run_vsync = get_config_int("Options", "Run_vsync", 0); options.sound_volume = get_config_int("Options", "Sound_volume", 100); options.ambience_volume = get_config_int("Options", "Ambience_volume", 100); options.windowed = get_config_int("Options", "Windowed", 0); int p1_keys_default[NO_CMDS] = {KEY_8_PAD, KEY_4_PAD, KEY_6_PAD, KEY_0_PAD, KEY_ENTER_PAD, KEY_2_PAD, KEY_1_PAD, KEY_3_PAD, KEY_PLUS_PAD, KEY_SLASH_PAD}; for (i = 0; i < NO_CMDS; i ++) { strcpy(wstring, "Player1Keys"); strcpy(miscstring, "Key"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); player[0].keys [i] = get_config_int(wstring, miscstring, p1_keys_default[i]); } int p2_keys_default[NO_CMDS] = {KEY_W, KEY_A, KEY_D, KEY_Q, KEY_TAB, KEY_S, KEY_Z, KEY_X, KEY_E, KEY_1}; for (i = 0; i < NO_CMDS; i ++) { strcpy(wstring, "Player2Keys"); strcpy(miscstring, "Key"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); player[1].keys [i] = get_config_int(wstring, miscstring, p2_keys_default[i]); } struct score_list single_hs_default[NO_SCORES] = {{30000, SHIP_LACEWING, 11, "Jub-Jub"}, {20000, SHIP_HOOKWORM, 10, "Slurpy"}, {15000, SHIP_AETHER, 9, "Antlion"}, {12000, SHIP_CAPYBARA, 8, "Schnorkel"}, {10000, SHIP_LACEWING, 8, "Legit"}, {9000, SHIP_PORKUPINE, 7, "Asdfgh"}, {8000, SHIP_CAPYBARA, 6, "Nemelex"}, {7000, SHIP_TORTFEASOR, 6, "Hi there"}, {6000, SHIP_DESPOT, 6, "Hello"}, {5000, SHIP_HOOKWORM, 5, "Quirp"}, {4000, SHIP_LENTIL, 5, "Hi there"}, {3000, SHIP_LACEWING, 4, "Kikubaaqudgha"}, {2000, SHIP_PRONG, 3, "Qwerty"}, {1000, SHIP_LACEWING, 2, "Capt Pork"}, {700, SHIP_LACEWING, 1, "Capt Pork"}}; for (i = 0; i < NO_SCORES; i ++) { strcpy(wstring, "Highscores_single"); strcpy(miscstring, "Score"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_single[i].score = get_config_int(wstring, miscstring, single_hs_default[i].score); strcpy(miscstring, "Level"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_single[i].level = get_config_int(wstring, miscstring, single_hs_default[i].level); strcpy(miscstring, "Ship"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_single[i].ship = get_config_int(wstring, miscstring, single_hs_default[i].ship); strcpy(miscstring, "Name"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); strcpy(hs_single[i].name, get_config_string(wstring, miscstring, single_hs_default[i].name)); } struct score_list coop_hs_default[NO_SCORES] = {{27265, SHIP_LACEWING, 9, "CaptainP"}, {25920, SHIP_CAPYBARA, 10, "CaptainP"}, {10160, SHIP_AETHER, 5, "CaptainP"}, {8650, SHIP_AETHER, 6, "Captain Squid"}, {1735, SHIP_PRONG, 3, "CaptainP"}, {610, SHIP_DESPOT, 1, "CaptainP"}, {600, SHIP_CAPYBARA, 2, "CaptainP"}, {120, SHIP_DESPOT, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "CaptainP"}, {100, SHIP_LACEWING, 1, "Capt Pork"}}; for (i = 0; i < NO_SCORES; i ++) { strcpy(wstring, "Highscores_Coop"); strcpy(miscstring, "Score"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_coop[i].score = get_config_int(wstring, miscstring, coop_hs_default[i].score); strcpy(miscstring, "Level"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_coop[i].level = get_config_int(wstring, miscstring, coop_hs_default[i].level); strcpy(miscstring, "Ship"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); hs_coop[i].ship = get_config_int(wstring, miscstring, coop_hs_default[i].ship); strcpy(miscstring, "Name"); strcpy(itstring, ""); //strcat(miscstring, itoa(i, itstring, 10)); sprintf(itstring, "%d", i); strcat(miscstring, itstring); strcpy(hs_coop[i].name, get_config_string(wstring, miscstring, coop_hs_default[i].name)); } }
bool ack_h(connection_t *c, const char *request) { if(c->protocol_minor == 1) return upgrade_h(c, request); char hisport[MAX_STRING_SIZE]; char *hisaddress; int weight, mtu; uint32_t options; node_t *n; bool choice; if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &weight, &options) != 3) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ACK", c->name, c->hostname); return false; } /* Check if we already have a node_t for him */ n = lookup_node(c->name); if(!n) { n = new_node(); n->name = xstrdup(c->name); node_add(n); } else { if(n->connection) { /* Oh dear, we already have a connection to this node. */ logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Established a second connection with %s (%s), closing old connection", n->connection->name, n->connection->hostname); if(n->connection->outgoing) { if(c->outgoing) logger(DEBUG_ALWAYS, LOG_WARNING, "Two outgoing connections to the same node!"); else c->outgoing = n->connection->outgoing; n->connection->outgoing = NULL; } terminate_connection(n->connection, false); /* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */ graph(); } } n->connection = c; c->node = n; if(!(c->options & options & OPTION_PMTU_DISCOVERY)) { c->options &= ~OPTION_PMTU_DISCOVERY; options &= ~OPTION_PMTU_DISCOVERY; } c->options |= options; if(get_config_int(lookup_config(c->config_tree, "PMTU"), &mtu) && mtu < n->mtu) n->mtu = mtu; if(get_config_int(lookup_config(config_tree, "PMTU"), &mtu) && mtu < n->mtu) n->mtu = mtu; if(get_config_bool(lookup_config(c->config_tree, "ClampMSS"), &choice)) { if(choice) c->options |= OPTION_CLAMP_MSS; else c->options &= ~OPTION_CLAMP_MSS; } /* Activate this connection */ c->allow_request = ALL; logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection with %s (%s) activated", c->name, c->hostname); /* Send him everything we know */ send_everything(c); /* Create an edge_t for this connection */ c->edge = new_edge(); c->edge->from = myself; c->edge->to = n; sockaddr2str(&c->address, &hisaddress, NULL); c->edge->address = str2sockaddr(hisaddress, hisport); free(hisaddress); sockaddr_t local_sa; socklen_t local_salen = sizeof local_sa; if (getsockname(c->socket, &local_sa.sa, &local_salen) < 0) logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name); else { char *local_address; sockaddr2str(&local_sa, &local_address, NULL); c->edge->local_address = str2sockaddr(local_address, myport); free(local_address); } c->edge->weight = (weight + c->estimated_weight) / 2; c->edge->connection = c; c->edge->options = c->options; edge_add(c->edge); /* Notify everyone of the new edge */ if(tunnelserver) send_add_edge(c, c->edge); else send_add_edge(everyone, c->edge); /* Run MST and SSSP algorithms */ graph(); return true; }
/* install_mouse: * Installs the Allegro mouse handler. You must do this before using any * other mouse functions. Return -1 if it can't find a mouse driver, * otherwise the number of buttons on the mouse. */ int install_mouse(void) { _DRIVER_INFO *driver_list; int num_buttons = -1; int config_num_buttons; AL_CONST char *emulate; char tmp1[64], tmp2[64]; int i; if (mouse_driver) return 0; LOCK_VARIABLE(mouse_driver); LOCK_VARIABLE(mousedrv_none); LOCK_VARIABLE(mouse_x); LOCK_VARIABLE(mouse_y); LOCK_VARIABLE(mouse_z); LOCK_VARIABLE(mouse_w); LOCK_VARIABLE(mouse_b); LOCK_VARIABLE(mouse_pos); LOCK_VARIABLE(_mouse_x); LOCK_VARIABLE(_mouse_y); LOCK_VARIABLE(_mouse_z); LOCK_VARIABLE(_mouse_w); LOCK_VARIABLE(_mouse_b); LOCK_VARIABLE(_mouse_on); LOCK_VARIABLE(mon); LOCK_VARIABLE(emulate_three); LOCK_VARIABLE(freeze_mouse_flag); LOCK_VARIABLE(mouse_callback); LOCK_VARIABLE(mouse_x_focus); LOCK_VARIABLE(mouse_y_focus); LOCK_VARIABLE(mouse_sprite); LOCK_VARIABLE(_mouse_pointer); LOCK_VARIABLE(_mouse_screen); LOCK_VARIABLE(mx); LOCK_VARIABLE(my); LOCK_VARIABLE(ms); LOCK_VARIABLE(mtemp); LOCK_VARIABLE(mouse_polled); LOCK_VARIABLE(mouse_semaphore); LOCK_VARIABLE(cursors); LOCK_FUNCTION(draw_mouse_doublebuffer); LOCK_FUNCTION(draw_mouse); LOCK_FUNCTION(update_mouse); LOCK_FUNCTION(mouse_move); LOCK_FUNCTION(poll_mouse); LOCK_FUNCTION(mouse_needs_poll); LOCK_FUNCTION(_handle_mouse_input); /* Construct mouse pointers */ if (!default_cursors[MOUSE_CURSOR_ARROW]) default_cursors[MOUSE_CURSOR_ARROW] = create_mouse_pointer(mouse_arrow_data); if (!default_cursors[MOUSE_CURSOR_BUSY]) default_cursors[MOUSE_CURSOR_BUSY] = create_mouse_pointer(mouse_busy_data); if (!default_cursors[MOUSE_CURSOR_QUESTION]) default_cursors[MOUSE_CURSOR_QUESTION] = create_mouse_pointer(mouse_arrow_data); if (!default_cursors[MOUSE_CURSOR_EDIT]) default_cursors[MOUSE_CURSOR_EDIT] = create_mouse_pointer(mouse_arrow_data); cursors[MOUSE_CURSOR_ARROW] = default_cursors[MOUSE_CURSOR_ARROW]; cursors[MOUSE_CURSOR_BUSY] = default_cursors[MOUSE_CURSOR_BUSY]; cursors[MOUSE_CURSOR_QUESTION] = default_cursors[MOUSE_CURSOR_QUESTION]; cursors[MOUSE_CURSOR_EDIT] = default_cursors[MOUSE_CURSOR_EDIT]; if (system_driver->mouse_drivers) driver_list = system_driver->mouse_drivers(); else driver_list = _mouse_driver_list; if (_mouse_type == MOUSEDRV_AUTODETECT) _mouse_type = get_config_id(uconvert_ascii("mouse", tmp1), uconvert_ascii("mouse", tmp2), MOUSEDRV_AUTODETECT); if (_mouse_type != MOUSEDRV_AUTODETECT) { for (i=0; driver_list[i].driver; i++) { if (driver_list[i].id == _mouse_type) { mouse_driver = driver_list[i].driver; break; } } } if (mouse_driver) { mouse_driver->name = mouse_driver->desc = get_config_text(mouse_driver->ascii_name); num_buttons = mouse_driver->init(); } else { for (i=0; num_buttons<0; i++) { if (!driver_list[i].driver) break; mouse_driver = driver_list[i].driver; mouse_driver->name = mouse_driver->desc = get_config_text(mouse_driver->ascii_name); num_buttons = mouse_driver->init(); } } if (num_buttons < 0) { mouse_driver = NULL; return -1; } config_num_buttons = get_config_int(uconvert_ascii("mouse", tmp1), uconvert_ascii("num_buttons", tmp2), -1); emulate = get_config_string(uconvert_ascii("mouse", tmp1), uconvert_ascii("emulate_three", tmp2), NULL); /* clamp config_num_buttons to zero/positive values */ if (config_num_buttons >= 0) num_buttons = config_num_buttons; if ((emulate) && ((i = ugetc(emulate)) != 0)) { if ((i == 'y') || (i == 'Y') || (i == '1')) emulate_three = TRUE; else emulate_three = FALSE; } else { emulate_three = FALSE; } mouse_polled = (mouse_driver->poll) ? TRUE : FALSE; _mouse_installed = TRUE; disable_hardware_cursor(); set_mouse_etc(); _add_exit_func(remove_mouse, "remove_mouse"); if (mouse_driver->timer_poll) install_int(mouse_move, 10); return num_buttons; }
/* x_get_keyboard_mapping: * Generate a mapping from X11 keycodes to Allegro KEY_* codes. We have * two goals: Every keypress should be mapped to a distinct Allegro KEY_* * code. And we want the KEY_* codes to match the pressed * key to some extent. To do the latter, the X11 KeySyms produced by a key * are examined. If a match is found in the table above, the mapping is * added to the mapping table. If no known KeySym is found for a key (or * the same KeySym is found for more keys) - the remaining keys are * distributed arbitrarily to the remaining KEY_* codes. * * In a future version, this could be simplified by mapping *all* the X11 * KeySyms to KEY_* codes. */ void _xwin_get_keyboard_mapping(void) { int i; int count; int missing = 0; memset(used, 0, sizeof used); memset(_xwin.keycode_to_scancode, 0, sizeof _xwin.keycode_to_scancode); XLOCK(); XDisplayKeycodes(_xwin.display, &min_keycode, &max_keycode); count = 1 + max_keycode - min_keycode; if (keysyms) { XFree(keysyms); } keysyms = XGetKeyboardMapping(_xwin.display, min_keycode, count, &sym_per_key); TRACE (PREFIX_I "%i keys, %i symbols per key.\n", count, sym_per_key); missing = 0; for (i = min_keycode; i <= max_keycode; i++) { KeySym sym = keysyms[sym_per_key * (i - min_keycode)]; KeySym sym2 = keysyms[sym_per_key * (i - min_keycode) + 1]; char *sym_str, *sym2_str; int allegro_key = 0; sym_str = XKeysymToString(sym); sym2_str = XKeysymToString(sym2); TRACE (PREFIX_I "key [%i: %s %s]", i, sym_str ? sym_str : "NULL", sym2_str ? sym2_str : "NULL"); /* Hack for French keyboards, to correctly map KEY_0 to KEY_9. */ if (sym2 >= XK_0 && sym2 <= XK_9) { allegro_key = find_allegro_key(sym2); } if (!allegro_key) { if (sym != NoSymbol) { allegro_key = find_allegro_key(sym); if (allegro_key == 0) { missing++; TRACE (" defering.\n"); } } else { /* No KeySym for this key - ignore it. */ _xwin.keycode_to_scancode[i] = -1; TRACE (" not assigned.\n"); } } if (allegro_key) { if (used[allegro_key]) { TRACE(" *double*"); } _xwin.keycode_to_scancode[i] = allegro_key; key_names[allegro_key] = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]); used[allegro_key] = 1; TRACE(" assigned to %i.\n", allegro_key); } } if (missing) { /* The keys still not assigned are just assigned arbitrarily now. */ for (i = min_keycode; i <= max_keycode; i++) { if (_xwin.keycode_to_scancode[i] == 0) { find_unknown_key_assignment(i); } } } if (xmodmap) XFreeModifiermap(xmodmap); xmodmap = XGetModifierMapping(_xwin.display); for (i = 0; i < 8; i++) { int j; TRACE (PREFIX_I "Modifier %d:", i + 1); for (j = 0; j < xmodmap->max_keypermod; j++) { KeySym sym = XKeycodeToKeysym(_xwin.display, xmodmap->modifiermap[i * xmodmap->max_keypermod + j], 0); char *sym_str = XKeysymToString(sym); TRACE(" %s", sym_str ? sym_str : "NULL"); } TRACE("\n"); } /* The [xkeymap] section can be useful, e.g. if trying to play a * game which has X and Y hardcoded as KEY_X and KEY_Y to mean * left/right movement, but on the X11 keyboard X and Y are far apart. * For normal use, a user never should have to touch [xkeymap] anymore * though, and proper written programs will not hardcode such mappings. */ { char *section, *option_format; char option[128], tmp1[128], tmp2[128]; section = uconvert_ascii("xkeymap", tmp1); option_format = uconvert_ascii("keycode%d", tmp2); for (i = min_keycode; i <= max_keycode; i++) { int scancode; uszprintf(option, sizeof(option), option_format, i); scancode = get_config_int(section, option, -1); if (scancode > 0) { _xwin.keycode_to_scancode[i] = scancode; TRACE(PREFIX_I "User override: KeySym %i assigned to %i.\n", i, scancode); } } } XUNLOCK(); }
void Level::loadCore(int level) { set_config_file("core.ini"); char section[256]; sprintf(section,"level%02d",level); zoom2x = get_config_int(section,"zoom2x",-1); zoom2y = get_config_int(section,"zoom2y",-1); zoom5x = get_config_int(section,"zoom5x",-1); zoom5y = get_config_int(section,"zoom5y",-1); zoom10x = get_config_int(section,"zoom10x",-1); zoom10y = get_config_int(section,"zoom10y",-1); pad2x1 = get_config_int(section,"pad2x1",-1); pad2x2 = get_config_int(section,"pad2x2",-1); pad2y = get_config_int(section,"pad2y",-1); pad5x1 = get_config_int(section,"pad5x1",-1); pad5x2 = get_config_int(section,"pad5x2",-1); pad5y = get_config_int(section,"pad5y",-1); pad10x1 = get_config_int(section,"pad10x1",-1); pad10x2 = get_config_int(section,"pad10x2",-1); pad10y = get_config_int(section,"pad10y",-1); label2x = get_config_int(section,"label2x",-1); label2y = get_config_int(section,"label2y",-1); label5x = get_config_int(section,"label5x",-1); label5y = get_config_int(section,"label5y",-1); label10x = get_config_int(section,"label10x",-1); label10y = get_config_int(section,"label10y",-1); brandx = get_config_int(section,"brandx",-1); brandy = get_config_int(section,"brandy",-1); const char *tmp = get_config_string(section,"name","name not specified"); sprintf(name,tmp); levelNumber = level; }
/* Self-explanatory. */ void init_at_startup(void) { LOCK_FUNCTION (framecount); LOCK_FUNCTION (tickover); LOCK_VARIABLE (ticked); LOCK_VARIABLE (frames_per_second); LOCK_VARIABLE (framecounter); LOCK_VARIABLE (turns_per_second); LOCK_VARIABLE (turncounter); install_int (framecount, 1000); install_int (tickover, 20); set_color_depth(8); int randseed = get_config_int("Misc", "Seed", 0); srand(randseed); options.windowed = get_config_int("Misc", "Windowed", 0); int windowed; switch(options.windowed) { default: case 1: windowed = GFX_AUTODETECT_WINDOWED; break; case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break; } // windowed = GFX_AUTODETECT_WINDOWED; // windowed = GFX_AUTODETECT_FULLSCREEN; // if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 640x480 display mode\n%s\n", allegro_error); exit(1); } init_trig(); prepare_display(); init_sound(); /* player[0].ckey [CKEY_UP] = KEY_UP; player[0].ckey [CKEY_DOWN] = KEY_DOWN; player[0].ckey [CKEY_LEFT] = KEY_LEFT; player[0].ckey [CKEY_RIGHT] = KEY_RIGHT; player[0].ckey [CKEY_FIRE1] = KEY_Z; player[0].ckey [CKEY_FIRE2] = KEY_X; player[0].ckey [CKEY_FIRE3] = KEY_C; */ player[0].ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP); player[0].ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN); player[0].ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT); player[0].ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT); player[0].ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z); player[0].ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X); options.joy_stick = get_config_int("Misc", "joy_stick", 0); options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70); options.init_joystick = get_config_int("Misc", "joy_init", 1); options.joystick = 0; options.key_or_joy = 0; // don't put in initfile! options.sfx_volume = get_config_int("Misc", "sfx_volume", 70); options.ambience_volume = get_config_int("Misc", "ambience_volume", 100); options.run_vsync = get_config_int("Misc", "run_vsync", 0); // set_config_int("Misc", "Tourist", 3); // set_config_int("Misc", "joy_stick", 0); if (options.init_joystick) init_joystick(); if (options.joystick == 1) // set in init_joystick { options.joy_button [0] = get_config_int("Misc", "joy_button_1", 0); if (options.joy_button [0] > joy[0].num_buttons) options.joy_button [0] = joy[0].num_buttons - 1; options.joy_button [1] = get_config_int("Misc", "joy_button_2", 1); if (options.joy_button [1] > joy[0].num_buttons) options.joy_button [1] = joy[0].num_buttons - 1; options.joy_button [2] = get_config_int("Misc", "joy_button_engine", 3); if (options.joy_button [2] > joy[0].num_buttons) options.joy_button [2] = joy[0].num_buttons - 1; options.joy_button [3] = get_config_int("Misc", "joy_button_brake", 2); if (options.joy_button [3] > joy[0].num_buttons) options.joy_button [3] = joy[0].num_buttons - 1; } ticked = 0; }
void LoadSavegame() { set_config_file("Resources/Save.cfg"); get_config_int("Savegame","FireH",FireH); get_config_int("Savegame","ThunderH",ThunderH); get_config_int("Savegame","WindH",WindH); get_config_int("Savegame","FreezeH",FreezeH); get_config_int("Savegame","FireB",FireB); get_config_int("Savegame","ThunderB",ThunderB); get_config_int("Savegame","WindB",WindB); get_config_int("Savegame","FreezeB",FreezeB); get_config_int("Savegame","FireS",FireS); get_config_int("Savegame","ThunderS",ThunderS); get_config_int("Savegame","WindS",WindS); get_config_int("Savegame","FreezeS",FreezeS); get_config_int("Savegame","FireM",FireM); get_config_int("Savegame","ThunderM",ThunderM); get_config_int("Savegame","WindM",WindM); get_config_int("Savegame","FreezeM",FreezeM); get_config_int("Savegame","FireW",FireW); get_config_int("Savegame","ThunderW",ThunderW); get_config_int("Savegame","WindW",WindW); get_config_int("Savegame","FreezeW",FreezeW); }
/*! \brief Parse allegro file kq.cfg * * This is like parse_setup(), but using Allegro format files * * \author PH * \date 20030831 */ static void parse_allegro_setup (void) { const char *cfg = kqres (SETTINGS_DIR, "kq.cfg"); if (!exists (cfg)) { /* config file does not exist. Fall back to setup.cfg */ /* Transitional code */ parse_jb_setup (); push_config_state (); set_config_file (cfg); set_config_int (NULL, "skip_intro", skip_intro); set_config_int (NULL, "windowed", windowed); set_config_int (NULL, "stretch_view", stretch_view); set_config_int (NULL, "show_frate", show_frate); set_config_int (NULL, "is_sound", is_sound); set_config_int (NULL, "use_joy", use_joy); set_config_int (NULL, "slow_computer", slow_computer); set_config_int (NULL, "kup", kup); set_config_int (NULL, "kdown", kdown); set_config_int (NULL, "kleft", kleft); set_config_int (NULL, "kright", kright); set_config_int (NULL, "kesc", kesc); set_config_int (NULL, "kalt", kalt); set_config_int (NULL, "kctrl", kctrl); set_config_int (NULL, "kenter", kenter); #ifdef DEBUGMODE set_config_int (NULL, "debugging", debugging); #endif pop_config_state (); return; } push_config_state (); set_config_file (cfg); /* NB. JB's config file uses intro=yes --> skip_intro=0 */ skip_intro = get_config_int (NULL, "skip_intro", 0); #ifdef __DJGPP__ /* In DJGPP, it's always non-windowed non-stretched (DOS-era stuff!) */ windowed = 0; stretch_view = 0; #else windowed = get_config_int (NULL, "windowed", 1); stretch_view = get_config_int (NULL, "stretch_view", 1); #endif wait_retrace = get_config_int (NULL, "wait_retrace", 1); show_frate = get_config_int (NULL, "show_frate", 0); is_sound = get_config_int (NULL, "is_sound", 1); use_joy = get_config_int (NULL, "use_joy", 0); slow_computer = get_config_int (NULL, "slow_computer", 0); cpu_usage = get_config_int (NULL, "cpu_usage", 2); #ifdef KQ_CHEATS cheat = get_config_int (NULL, "cheat", 0); no_random_encounters = get_config_int (NULL, "no_random_encounters", 0); no_monsters = get_config_int (NULL, "no_monsters", 0); every_hit_999 = get_config_int (NULL, "every_hit_999", 0); #endif #ifdef DEBUGMODE debugging = get_config_int (NULL, "debugging", 0); #endif kup = get_config_int (NULL, "kup", KEY_UP); kdown = get_config_int (NULL, "kdown", KEY_DOWN); kleft = get_config_int (NULL, "kleft", KEY_LEFT); kright = get_config_int (NULL, "kright", KEY_RIGHT); kesc = get_config_int (NULL, "kesc", KEY_ESC); kalt = get_config_int (NULL, "kalt", KEY_ALT); kctrl = get_config_int (NULL, "kctrl", KEY_LCONTROL); kenter = get_config_int (NULL, "kenter", KEY_ENTER); pop_config_state (); }
/* Configure node_t myself and set up the local sockets (listen only) */ static bool setup_myself(void) { config_t *cfg; subnet_t *subnet; char *name, *hostname, *mode, *afname, *cipher, *digest, *type; char *fname = NULL; char *address = NULL; char *proxy = NULL; char *space; char *envp[5] = {NULL}; struct addrinfo *ai, *aip, hint = {0}; bool choice; int i, err; int replaywin_int; bool port_specified = false; myself = new_node(); myself->connection = new_connection(); myself->hostname = xstrdup("MYSELF"); myself->connection->hostname = xstrdup("MYSELF"); myself->connection->options = 0; myself->connection->protocol_version = PROT_CURRENT; if(!(name = get_name())) { logger(LOG_ERR, "Name for tinc daemon required!"); return false; } /* Read tinc.conf and our own host config file */ myself->name = name; myself->connection->name = xstrdup(name); xasprintf(&fname, "%s/hosts/%s", confbase, name); read_config_options(config_tree, name); read_config_file(config_tree, fname); free(fname); if(!read_rsa_private_key()) return false; if(!get_config_string(lookup_config(config_tree, "Port"), &myport)) myport = xstrdup("655"); else port_specified = true; /* Ensure myport is numeric */ if(!atoi(myport)) { struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM); sockaddr_t sa; if(!ai || !ai->ai_addr) return false; free(myport); memcpy(&sa, ai->ai_addr, ai->ai_addrlen); sockaddr2str(&sa, NULL, &myport); } get_config_string(lookup_config(config_tree, "Proxy"), &proxy); if(proxy) { if((space = strchr(proxy, ' '))) *space++ = 0; if(!strcasecmp(proxy, "none")) { proxytype = PROXY_NONE; } else if(!strcasecmp(proxy, "socks4")) { proxytype = PROXY_SOCKS4; } else if(!strcasecmp(proxy, "socks4a")) { proxytype = PROXY_SOCKS4A; } else if(!strcasecmp(proxy, "socks5")) { proxytype = PROXY_SOCKS5; } else if(!strcasecmp(proxy, "http")) { proxytype = PROXY_HTTP; } else if(!strcasecmp(proxy, "exec")) { proxytype = PROXY_EXEC; } else { logger(LOG_ERR, "Unknown proxy type %s!", proxy); return false; } switch(proxytype) { case PROXY_NONE: default: break; case PROXY_EXEC: if(!space || !*space) { logger(LOG_ERR, "Argument expected for proxy type exec!"); return false; } proxyhost = xstrdup(space); break; case PROXY_SOCKS4: case PROXY_SOCKS4A: case PROXY_SOCKS5: case PROXY_HTTP: proxyhost = space; if(space && (space = strchr(space, ' '))) *space++ = 0, proxyport = space; if(space && (space = strchr(space, ' '))) *space++ = 0, proxyuser = space; if(space && (space = strchr(space, ' '))) *space++ = 0, proxypass = space; if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) { logger(LOG_ERR, "Host and port argument expected for proxy!"); return false; } proxyhost = xstrdup(proxyhost); proxyport = xstrdup(proxyport); if(proxyuser && *proxyuser) proxyuser = xstrdup(proxyuser); if(proxypass && *proxypass) proxypass = xstrdup(proxypass); break; } free(proxy); } /* Read in all the subnets specified in the host configuration file */ cfg = lookup_config(config_tree, "Subnet"); while(cfg) { if(!get_config_subnet(cfg, &subnet)) return false; subnet_add(myself, subnet); cfg = lookup_config_next(config_tree, cfg); } /* Check some options */ if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice) myself->options |= OPTION_INDIRECT; if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice) myself->options |= OPTION_TCPONLY; if(myself->options & OPTION_TCPONLY) myself->options |= OPTION_INDIRECT; get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets); get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver); get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery); strictsubnets |= tunnelserver; if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) { if(!strcasecmp(mode, "router")) routing_mode = RMODE_ROUTER; else if(!strcasecmp(mode, "switch")) routing_mode = RMODE_SWITCH; else if(!strcasecmp(mode, "hub")) routing_mode = RMODE_HUB; else { logger(LOG_ERR, "Invalid routing mode!"); return false; } free(mode); } if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) { if(!strcasecmp(mode, "off")) forwarding_mode = FMODE_OFF; else if(!strcasecmp(mode, "internal")) forwarding_mode = FMODE_INTERNAL; else if(!strcasecmp(mode, "kernel")) forwarding_mode = FMODE_KERNEL; else { logger(LOG_ERR, "Invalid forwarding mode!"); return false; } free(mode); } choice = true; get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice); if(choice) myself->options |= OPTION_PMTU_DISCOVERY; choice = true; get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice); if(choice) myself->options |= OPTION_CLAMP_MSS; get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance); get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl); if(get_config_string(lookup_config(config_tree, "Broadcast"), &mode)) { if(!strcasecmp(mode, "no")) broadcast_mode = BMODE_NONE; else if(!strcasecmp(mode, "yes") || !strcasecmp(mode, "mst")) broadcast_mode = BMODE_MST; else if(!strcasecmp(mode, "direct")) broadcast_mode = BMODE_DIRECT; else { logger(LOG_ERR, "Invalid broadcast mode!"); return false; } free(mode); } #if !defined(SOL_IP) || !defined(IP_TOS) if(priorityinheritance) logger(LOG_WARNING, "%s not supported on this platform", "PriorityInheritance"); #endif if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire)) macexpire = 600; if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) { if(maxtimeout <= 0) { logger(LOG_ERR, "Bogus maximum timeout!"); return false; } } else maxtimeout = 900; if(get_config_int(lookup_config(config_tree, "UDPRcvBuf"), &udp_rcvbuf)) { if(udp_rcvbuf <= 0) { logger(LOG_ERR, "UDPRcvBuf cannot be negative!"); return false; } } if(get_config_int(lookup_config(config_tree, "UDPSndBuf"), &udp_sndbuf)) { if(udp_sndbuf <= 0) { logger(LOG_ERR, "UDPSndBuf cannot be negative!"); return false; } } if(get_config_int(lookup_config(config_tree, "ReplayWindow"), &replaywin_int)) { if(replaywin_int < 0) { logger(LOG_ERR, "ReplayWindow cannot be negative!"); return false; } replaywin = (unsigned)replaywin_int; } if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) { if(!strcasecmp(afname, "IPv4")) addressfamily = AF_INET; else if(!strcasecmp(afname, "IPv6")) addressfamily = AF_INET6; else if(!strcasecmp(afname, "any")) addressfamily = AF_UNSPEC; else { logger(LOG_ERR, "Invalid address family!"); return false; } free(afname); } get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames); /* Generate packet encryption key */ if(get_config_string (lookup_config(config_tree, "Cipher"), &cipher)) { if(!strcasecmp(cipher, "none")) { myself->incipher = NULL; } else { myself->incipher = EVP_get_cipherbyname(cipher); if(!myself->incipher) { logger(LOG_ERR, "Unrecognized cipher type!"); return false; } } } else myself->incipher = EVP_bf_cbc(); if(myself->incipher) myself->inkeylength = myself->incipher->key_len + myself->incipher->iv_len; else myself->inkeylength = 1; myself->connection->outcipher = EVP_bf_ofb(); if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime)) keylifetime = 3600; keyexpires = now + keylifetime; /* Check if we want to use message authentication codes... */ if(get_config_string(lookup_config(config_tree, "Digest"), &digest)) { if(!strcasecmp(digest, "none")) { myself->indigest = NULL; } else { myself->indigest = EVP_get_digestbyname(digest); if(!myself->indigest) { logger(LOG_ERR, "Unrecognized digest type!"); return false; } } } else myself->indigest = EVP_sha1(); myself->connection->outdigest = EVP_sha1(); if(get_config_int(lookup_config(config_tree, "MACLength"), &myself->inmaclength)) { if(myself->indigest) { if(myself->inmaclength > myself->indigest->md_size) { logger(LOG_ERR, "MAC length exceeds size of digest!"); return false; } else if(myself->inmaclength < 0) { logger(LOG_ERR, "Bogus MAC length!"); return false; } } } else myself->inmaclength = 4; myself->connection->outmaclength = 0; /* Compression */ if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) { if(myself->incompression < 0 || myself->incompression > 11) { logger(LOG_ERR, "Bogus compression level!"); return false; } } else myself->incompression = 0; myself->connection->outcompression = 0; /* Done */ myself->nexthop = myself; myself->via = myself; myself->status.reachable = true; node_add(myself); graph(); if(strictsubnets) load_all_subnets(); /* Open device */ devops = os_devops; if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) { if(!strcasecmp(type, "dummy")) devops = dummy_devops; else if(!strcasecmp(type, "raw_socket")) devops = raw_socket_devops; else if(!strcasecmp(type, "multicast")) devops = multicast_devops; #ifdef ENABLE_UML else if(!strcasecmp(type, "uml")) devops = uml_devops; #endif #ifdef ENABLE_VDE else if(!strcasecmp(type, "vde")) devops = vde_devops; #endif } if(!devops.setup()) return false; /* Run tinc-up script to further initialize the tap interface */ xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); xasprintf(&envp[1], "DEVICE=%s", device ? : ""); xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); xasprintf(&envp[3], "NAME=%s", myself->name); execute_script("tinc-up", envp); for(i = 0; i < 4; i++) free(envp[i]); /* Run subnet-up scripts for our own subnets */ subnet_update(myself, NULL, true); /* Open sockets */ if(!do_detach && getenv("LISTEN_FDS")) { sockaddr_t sa; socklen_t salen; listen_sockets = atoi(getenv("LISTEN_FDS")); #ifdef HAVE_UNSETENV unsetenv("LISTEN_FDS"); #endif if(listen_sockets > MAXSOCKETS) { logger(LOG_ERR, "Too many listening sockets"); return false; } for(i = 0; i < listen_sockets; i++) { salen = sizeof sa; if(getsockname(i + 3, &sa.sa, &salen) < 0) { logger(LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno)); return false; } listen_socket[i].tcp = i + 3; #ifdef FD_CLOEXEC fcntl(i + 3, F_SETFD, FD_CLOEXEC); #endif listen_socket[i].udp = setup_vpn_in_socket(&sa); if(listen_socket[i].udp < 0) return false; ifdebug(CONNECTIONS) { hostname = sockaddr2hostname(&sa); logger(LOG_NOTICE, "Listening on %s", hostname); free(hostname); } memcpy(&listen_socket[i].sa, &sa, salen); } } else {
int main() { BITMAP *backbuffer = NULL, *mysha; int count = 0; int old_time = 0, old_time2 = 0; int depth; int i; int use_alleg = 0; allegro_init(); install_keyboard(); install_timer(); set_config_file("examples.cfg"); depth = get_config_int("examples", "depth", 16); set_color_depth(depth); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(16); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(15); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { allegro_message("Unable to set 640x480 screen mode!\n"); return -1; } } } } mysha = load_bitmap("mysha.pcx", NULL); if (!mysha) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n"); return -2; } backbuffer = create_bitmap(SCREEN_W, SCREEN_H); if (!backbuffer) { destroy_bitmap(mysha); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Not enough memory to create backbuffer.\n"); return -3; } LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H); for (i = 0; i < 4; i++) { fade[i].x = (SCREEN_W/2) * (i & 1); fade[i].y = (SCREEN_H/2) * (i & 2) >> 1; fade[i].fact = rand() & 255; fade[i].dir = (rand() & 1) ? 1 : -1; fade[i].src = create_sub_bitmap(backbuffer, fade[i].x, fade[i].y, SCREEN_W/2, SCREEN_H/2); fade[i].color = makecol((i & 1) * 255, ((i & 2) >> 1) * 255, 0); } install_int(the_timer, 1); old_time = chrono; while (!key[KEY_ESC]) { if (use_alleg) { stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H); } textprintf(backbuffer, font, 0, 0, makecol(255, 255, 255), "%s %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using FBlend", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono); if (use_alleg) { drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); for (i = 0; i < 4; i++) { set_trans_blender(0, 0, 0, 255 - fade[i].fact); rectfill(fade[i].src, 0, 0, fade[i].src->w - 1, fade[i].src->h - 1, fade[i].color); } drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } else { for (i = 0; i < 4; i++) { fblend_fade_to_color(fade[i].src, screen, fade[i].x, fade[i].y, fade[i].color, fade[i].fact); } } if (key[KEY_SPACE]) { use_alleg = !use_alleg; key[KEY_SPACE] = 0; chrono = 0; count = 0; old_time = 0; old_time2 = 0; } count++; old_time2 = chrono; /* Draw the buffer */ if (use_alleg) { blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } for (i = 0; i < 4; i++) { fade[i].fact += fade[i].dir; if (fade[i].fact >= 255 || fade[i].fact <= 0) fade[i].dir = -fade[i].dir; fade[i].fact = MID(0, fade[i].fact, 255); } } for (i = 0; i < 4; i++) { destroy_bitmap(fade[i].src); } destroy_bitmap(backbuffer); destroy_bitmap(mysha); return 0; }
/** * Shows the "New Sprite" dialog. */ void NewFileCommand::onExecute(Context* context) { JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box; int imgtype, w, h, bg, ncolors; char buf[1024]; Color bg_table[] = { Color::fromMask(), Color::fromRgb(0, 0, 0), Color::fromRgb(255, 255, 255), Color::fromRgb(255, 0, 255), app_get_colorbar()->getBgColor() }; // Load the window widget FramePtr window(load_widget("new_sprite.xml", "new_sprite")); get_widgets(window, "width", &width, "height", &height, "radio1", &radio1, "radio2", &radio2, "radio3", &radio3, "colors", &colors, "ok_button", &ok, "bg_box", &bg_box, NULL); // Default values: Indexed, 320x240, Background color imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED); imgtype = MID(IMAGE_RGB, imgtype, IMAGE_INDEXED); w = get_config_int("NewSprite", "Width", 320); h = get_config_int("NewSprite", "Height", 240); bg = get_config_int("NewSprite", "Background", 4); // Default = Background color ncolors = get_config_int("NewSprite", "Colors", 256); width->setTextf("%d", MAX(1, w)); height->setTextf("%d", MAX(1, h)); colors->setTextf("%d", MID(2, ncolors, 256)); // Select image-type switch (imgtype) { case IMAGE_RGB: radio1->setSelected(true); break; case IMAGE_GRAYSCALE: radio2->setSelected(true); break; case IMAGE_INDEXED: radio3->setSelected(true); break; } // Select background color jlistbox_select_index(bg_box, bg); // Open the window window->open_window_fg(); if (window->get_killer() == ok) { bool ok = false; // Get the options if (radio1->isSelected()) imgtype = IMAGE_RGB; else if (radio2->isSelected()) imgtype = IMAGE_GRAYSCALE; else if (radio3->isSelected()) imgtype = IMAGE_INDEXED; w = width->getTextInt(); h = height->getTextInt(); ncolors = colors->getTextInt(); bg = jlistbox_get_selected_index(bg_box); w = MID(1, w, 9999); h = MID(1, h, 9999); ncolors = MID(2, ncolors, 256); // Select the color Color color = Color::fromMask(); if (bg >= 0 && bg <= 4) { color = bg_table[bg]; ok = true; } if (ok) { // Save the configuration set_config_int("NewSprite", "Type", imgtype); set_config_int("NewSprite", "Width", w); set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Background", bg); // Create the new sprite ASSERT(imgtype == IMAGE_RGB || imgtype == IMAGE_GRAYSCALE || imgtype == IMAGE_INDEXED); ASSERT(w >= 1 && w <= 9999); ASSERT(h >= 1 && h <= 9999); UniquePtr<Document> document( Document::createBasicDocument(imgtype, w, h, (imgtype == IMAGE_INDEXED ? ncolors: 256))); Sprite* sprite(document->getSprite()); get_default_palette()->copyColorsTo(sprite->getCurrentPalette()); usprintf(buf, "Sprite-%04d", ++_sprite_counter); document->setFilename(buf); // If the background color isn't transparent, we have to // convert the `Layer 1' in a `Background' if (color.getType() != Color::MaskType) { Sprite* sprite = document->getSprite(); ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); static_cast<LayerImage*>(sprite->getCurrentLayer())->configureAsBackground(); image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, imgtype)); } // Show the sprite to the user context->addDocument(document); // Release the document as it is already owned by the context. // And put the document in a reliable editor. set_document_in_more_reliable_editor(document.release()); } } }
CPlayer::CPlayer(int x,int y,char *key_bindings_file,int solid) { set_config_file(key_bindings_file); key_left = get_config_int(NULL,"LEFT",0); key_right = get_config_int(NULL,"RIGHT",0); key_fire = get_config_int(NULL,"FIRE",0); this->x = x; this->y = y; set_config_file(DEFAULT_PLAYER_CONFIG_FILE); bonus_frequency = default_bonus_frequency = get_config_int(NULL,"bonus_rate",5); more_bonuses_modifier = get_config_int(NULL,"more_bonuses_modifier",1); more_bonuses_duration = get_config_int(NULL,"more_bonuses_duration",10); move_speed = default_move_speed = get_config_int(NULL,"pad_speed",100); speed_modifier = get_config_int(NULL,"player_speed_modifier",5); set_color_conversion(COLORCONV_TOTAL); model = load_bitmap("/home/valo/Projects/breakin/graphics/batata.bmp",NULL); width = model->w; height = model->h; score = 0; last_scored = -30; bonus_points = 0; solid_walls = solid; immortal_time = get_config_int(NULL,"immortal_time",10); penetrating = false; penetration_time = get_config_int(NULL,"penetration_duration",10); ball_speed = default_ball_speed = get_config_int(NULL,"ball_speed",5); ball_speed_modifier = get_config_int(NULL,"ball_speed_modifier",10); fast_hit_max_time = get_config_float(NULL,"fast_hit_max_time",0.5); status_font1 = alfont_load_font(STATUS_FONT1_FILENAME); status_font2 = alfont_load_font(STATUS_FONT2_FILENAME); alfont_set_font_size(status_font1,50); alfont_set_font_size(status_font2,20); }
TeronBuilder::TeronBuilder( Vector2 opos, double shipAngle, ShipData *shipData, unsigned int code ): Ship( opos, shipAngle, shipData, code ) { STACKTRACE; collect_step = 0; collecting = NULL; collectRange = scale_range( get_config_float( "Extra", "CollectRange", 0 )); asteroid_value = get_config_int("Extra", "AsteroidValue", 0); drone_cost = get_config_int("Drone", "Cost", 0); drone_asteroid_value = get_config_int("Drone", "AsteroidValue", 0); drone_crew_max = get_config_int("Drone", "CrewMax", 0); drone_batt_max = get_config_int("Drone", "BattMax", 0); drone_recharge_amount = get_config_int("Drone", "RechargeAmount", 0); drone_recharge_rate = scale_frames(get_config_float("Drone", "RechargeRate", 0)); drone_weapon_drain = get_config_int("Drone", "WeaponDrain", 0); drone_weapon_rate = scale_frames(get_config_float("Drone", "WeaponRate", 0)); drone_special_drain = get_config_int("Drone", "SpecialDrain", 0); drone_special_rate = scale_frames(get_config_float("Drone", "SpecialRate", 0)); double drone_raw_hotspot_rate = get_config_float("Drone", "HotspotRate", 0); drone_hotspot_rate = scale_frames(drone_raw_hotspot_rate); drone_turn_rate = scale_turning(get_config_float("Drone", "TurnRate", 0)); drone_speed_max = scale_velocity(get_config_float("Drone", "SpeedMax", 0)); drone_accel_rate = scale_acceleration(get_config_float("Drone", "AccelRate", 0), drone_raw_hotspot_rate); drone_mass = get_config_int("Drone", "Mass", 0); droneWeaponRange = scale_range( get_config_float( "Drone", "WeaponRange", 0 )); fighter_cost = get_config_int("Fighter", "Cost", 0); fighter_crew_max = get_config_int("Fighter", "CrewMax", 0); fighter_batt_max = get_config_int("Fighter", "BattMax", 0); fighter_recharge_amount = get_config_int("Fighter", "RechargeAmount", 0); fighter_recharge_rate = scale_frames(get_config_float("Fighter", "RechargeRate", 0)); fighter_weapon_drain = get_config_int("Fighter", "WeaponDrain", 0); fighter_weapon_rate = scale_frames(get_config_float("Fighter", "WeaponRate", 0)); fighter_special_drain = get_config_int("Fighter", "SpecialDrain", 0); fighter_special_rate = scale_frames(get_config_float("Fighter", "SpecialRate", 0)); double fighter_raw_hotspot_rate = get_config_float("Fighter", "HotspotRate", 0); fighter_hotspot_rate = scale_frames(fighter_raw_hotspot_rate); fighter_turn_rate = scale_turning(get_config_float("Fighter", "TurnRate", 0)); fighter_speed_max = scale_velocity(get_config_float("Fighter", "SpeedMax", 0)); fighter_accel_rate = scale_acceleration(get_config_float("Fighter", "AccelRate", 0), fighter_raw_hotspot_rate); fighter_mass = get_config_int("Fighter", "Mass", 0); fighterWeaponRange = scale_range( get_config_float( "Fighter", "WeaponRange", 0 )); fighterWeaponVelocity = scale_velocity( get_config_float( "Fighter", "WeaponVelocity", 0 )); fighterWeaponDamage = get_config_int( "Fighter", "WeaponDamage", 0 ); fighterWeaponArmour = get_config_int( "Fighter", "WeaponArmour", 0 ); turret_cost = get_config_int("Turret", "Cost", 0); turret_crew_max = get_config_int("Turret", "CrewMax", 0); turret_batt_max = get_config_int("Turret", "BattMax", 0); turret_recharge_amount = get_config_int("Turret", "RechargeAmount", 0); turret_recharge_rate = scale_frames(get_config_float("Turret", "RechargeRate", 0)); turret_weapon_drain = get_config_int("Turret", "WeaponDrain", 0); turret_weapon_rate = scale_frames(get_config_float("Turret", "WeaponRate", 0)); turret_special_drain = get_config_int("Turret", "SpecialDrain", 0); turret_special_rate = scale_frames(get_config_float("Turret", "SpecialRate", 0)); turret_turn_rate = scale_turning(get_config_float("Turret", "TurnRate", 0)); turret_mass = get_config_int("Turret", "Mass", 0); turretWeaponRange = scale_range( get_config_float( "Turret", "WeaponRange", 0 )); turretWeaponVelocity = scale_velocity( get_config_float( "Turret", "WeaponVelocity", 0 )); turretWeaponDamage = get_config_int( "Turret", "WeaponDamage", 0 ); turretWeaponArmour = get_config_int( "Turret", "WeaponArmour", 0 ); attached_turret_recharge_amount = get_config_int("TurretAttached", "RechargeAmount", 0); attached_turret_recharge_rate = scale_frames(get_config_float("TurretAttached", "RechargeRate", 0)); attached_turret_weapon_drain = get_config_int("TurretAttached", "WeaponDrain", 0); attached_turret_weapon_rate = scale_frames(get_config_float("TurretAttached", "WeaponRate", 0)); attached_turret_special_drain = get_config_int("TurretAttached", "SpecialDrain", 0); attached_turret_special_rate = scale_frames(get_config_float("TurretAttached", "SpecialRate", 0)); attached_turret_turn_rate = scale_turning(get_config_float("TurretAttached", "TurnRate", 0)); attachedTurretWeaponRange = scale_range( get_config_float( "TurretAttached", "WeaponRange", 0 )); attachedTurretWeaponVelocity = scale_velocity( get_config_float( "TurretAttached", "WeaponVelocity", 0 )); attachedTurretWeaponDamage = get_config_int( "TurretAttached", "WeaponDamage", 0 ); attachedTurretWeaponArmour = get_config_int( "TurretAttached", "WeaponArmour", 0 ); dock[0].dist = 25; dock[0].dir = 75 * ANGLE_RATIO; dock[0].angle = 80 * ANGLE_RATIO; dock[0].avail = true; dock[1].dist = 25; dock[1].dir = 115 * ANGLE_RATIO; dock[1].angle = 90 * ANGLE_RATIO; dock[1].avail = true; dock[2].dist = 25; dock[2].dir = 245 * ANGLE_RATIO; dock[2].angle = 270 * ANGLE_RATIO; dock[2].avail = true; dock[3].dist = 25; dock[3].dir = 295 * ANGLE_RATIO; dock[3].angle = 270 * ANGLE_RATIO; dock[3].avail = true; int i; for ( i = 0; i < 4; ++i ) dock[i].dist *= 2; sprintf( option[option_build_drone].phrase, "Initiate Drone Construction" ); sprintf( option[option_build_turret].phrase, "Initiate Turret Construction" ); sprintf( option[option_build_fighter].phrase, "Initiate Fighter Construction" ); sprintf( option[option_order_assist_building].phrase, "Order Drone to Assist Building" ); sprintf( option[option_order_collect_resources].phrase, "Order Drone to Collect Resources" ); sprintf( option[option_order_return_to_dock].phrase, "Order Drone to Return to Dock" ); current_option = option_order_return_to_dock; current_drone = NULL; selection_sprite_index = 0; selection_sprite_step = 0; select_all = false; selectRange = scale_range( get_config_float( "Extra", "Range", 0 )); select_all = true; current_option = option_order_collect_resources; }
/** * Shows the "New Sprite" dialog. */ void NewFileCommand::onExecute(Context* context) { PixelFormat format; int w, h, bg, ncolors = get_default_palette()->size(); char buf[1024]; app::Color bg_table[] = { app::Color::fromMask(), app::Color::fromRgb(0, 0, 0), app::Color::fromRgb(255, 255, 255), app::Color::fromRgb(255, 0, 255) }; // Load the window widget app::gen::NewSprite window; // Default values: Indexed, 320x240, Background color format = static_cast<PixelFormat>(get_config_int("NewSprite", "Type", IMAGE_INDEXED)); // Invalid format in config file. if (format != IMAGE_RGB && format != IMAGE_INDEXED && format != IMAGE_GRAYSCALE) { format = IMAGE_INDEXED; } w = get_config_int("NewSprite", "Width", 320); h = get_config_int("NewSprite", "Height", 240); bg = get_config_int("NewSprite", "Background", 1); // Default = Black if (bg == 4) // Convert old default (Background color) to new default (Black) bg = 1; bg = MID(0, bg, 3); // If the clipboard contains an image, we can show the size of the // clipboard as default image size. gfx::Size clipboardSize; if (clipboard::get_image_size(clipboardSize)) { w = clipboardSize.w; h = clipboardSize.h; } window.width()->setTextf("%d", MAX(1, w)); window.height()->setTextf("%d", MAX(1, h)); // Select image-type switch (format) { case IMAGE_RGB: window.rgbMode()->setSelected(true); break; case IMAGE_GRAYSCALE: window.grayscaleMode()->setSelected(true); break; case IMAGE_INDEXED: window.indexedMode()->setSelected(true); break; } // Select background color window.bgBox()->selectIndex(bg); // Open the window window.openWindowInForeground(); if (window.getKiller() == window.okButton()) { bool ok = false; // Get the options if (window.rgbMode()->isSelected()) format = IMAGE_RGB; else if (window.grayscaleMode()->isSelected()) format = IMAGE_GRAYSCALE; else if (window.indexedMode()->isSelected()) format = IMAGE_INDEXED; w = window.width()->getTextInt(); h = window.height()->getTextInt(); bg = window.bgBox()->getSelectedIndex(); w = MID(1, w, 65535); h = MID(1, h, 65535); // Select the color app::Color color = app::Color::fromMask(); if (bg >= 0 && bg <= 3) { color = bg_table[bg]; ok = true; } if (ok) { // Save the configuration set_config_int("NewSprite", "Type", format); set_config_int("NewSprite", "Width", w); set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Background", bg); // Create the new sprite ASSERT(format == IMAGE_RGB || format == IMAGE_GRAYSCALE || format == IMAGE_INDEXED); ASSERT(w > 0 && h > 0); base::UniquePtr<Sprite> sprite(Sprite::createBasicSprite(format, w, h, ncolors)); if (sprite->pixelFormat() != IMAGE_GRAYSCALE) get_default_palette()->copyColorsTo(sprite->palette(frame_t(0))); // If the background color isn't transparent, we have to // convert the `Layer 1' in a `Background' if (color.getType() != app::Color::MaskType) { Layer* layer = sprite->folder()->getFirstLayer(); if (layer && layer->isImage()) { LayerImage* layerImage = static_cast<LayerImage*>(layer); layerImage->configureAsBackground(); Image* image = layerImage->cel(frame_t(0))->image(); doc::clear_image(image, color_utils::color_for_target(color, ColorTarget( ColorTarget::BackgroundLayer, sprite->pixelFormat(), sprite->transparentColor()))); } } // Show the sprite to the user base::UniquePtr<Document> doc(new Document(sprite)); sprite.release(); sprintf(buf, "Sprite-%04d", ++_sprite_counter); doc->setFilename(buf); doc->setContext(context); doc.release(); } } }
/** \ingroup settings * * Loads the settings from the current config file, in the * section [OpenGL]. * Note that this function will not clear any settings currently * set, but will add them up, as if each of the setting were set * manually. * * \sa allegro_gl_save_settings() */ void allegro_gl_load_settings() { int set; char *section = "OpenGL"; set = get_config_int(section, "allegro_format", -1); if (set != -1) allegro_gl_set(AGL_ALLEGRO_FORMAT, set); set = get_config_int(section, "red_depth", -1); if (set != -1) allegro_gl_set(AGL_RED_DEPTH, set); set = get_config_int(section, "green_depth", -1); if (set != -1) allegro_gl_set(AGL_GREEN_DEPTH, set); set = get_config_int(section, "blue_depth", -1); if (set != -1) allegro_gl_set(AGL_BLUE_DEPTH, set); set = get_config_int(section, "alpha_depth", -1); if (set != -1) allegro_gl_set(AGL_ALPHA_DEPTH, set); set = get_config_int(section, "color_depth", -1); if (set != -1) allegro_gl_set(AGL_COLOR_DEPTH, set); set = get_config_int(section, "accum_red_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_RED_DEPTH, set); set = get_config_int(section, "accum_green_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_GREEN_DEPTH, set); set = get_config_int(section, "accum_blue_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_BLUE_DEPTH, set); set = get_config_int(section, "accum_alpha_depth", -1); if (set != -1) allegro_gl_set(AGL_ACC_ALPHA_DEPTH, set); set = get_config_int(section, "double_buffer", -1); if (set != -1) allegro_gl_set(AGL_DOUBLEBUFFER, set); set = get_config_int(section, "stereo_display", -1); if (set != -1) allegro_gl_set(AGL_STEREO, set); set = get_config_int(section, "aux_buffers", -1); if (set != -1) allegro_gl_set(AGL_AUX_BUFFERS, set); set = get_config_int(section, "z_depth", -1); if (set != -1) allegro_gl_set(AGL_Z_DEPTH, set); set = get_config_int(section, "stencil_depth", -1); if (set != -1) allegro_gl_set(AGL_STENCIL_DEPTH, set); set = get_config_int(section, "window_x", -1); if (set != -1) allegro_gl_set(AGL_WINDOW_X, set); set = get_config_int(section, "window_y", -1); if (set != -1) allegro_gl_set(AGL_WINDOW_Y, set); set = get_config_int(section, "fullscreen", -1); if (set != -1) allegro_gl_set(AGL_FULLSCREEN, set); set = get_config_int(section, "windowed", -1); if (set != -1) allegro_gl_set(AGL_WINDOWED, set); set = get_config_int(section, "video_memory_policy", -1); if (set != -1) allegro_gl_set(AGL_VIDEO_MEMORY_POLICY, set); set = get_config_int(section, "sample_buffers", -1); if (set != -1) allegro_gl_set(AGL_SAMPLE_BUFFERS, set); set = get_config_int(section, "samples", -1); if (set != -1) allegro_gl_set(AGL_SAMPLES, set); set = get_config_int(section, "float_color", -1); if (set != -1) allegro_gl_set(AGL_FLOAT_COLOR, set); set = get_config_int(section, "float_depth", -1); if (set != -1) allegro_gl_set(AGL_FLOAT_Z, set); agl_parse_section(AGL_REQUIRE, section, "require"); agl_parse_section(AGL_SUGGEST, section, "suggest"); }
/* jack_init: * JACK init routine. */ static int jack_init(int input, int voices) { const char **ports; char tmp[128]; if (!jack_detect(input)) return -1; jack_bufsize = get_config_int("sound", "jack_buffer_size", jack_bufsize); if (jack_bufsize == -1) jack_bufsize = jack_get_buffer_size (jack_client); /* Those are already read in from the config file by Allegro. */ jack_16bit = (_sound_bits == 16 ? 1 : 0); jack_stereo = (_sound_stereo ? 1 : 0); /* Let Allegro mix in its native unsigned format. */ jack_signed = 0; jack_set_process_callback (jack_client, jack_process, NULL); output_left = jack_port_register (jack_client, jack_stereo ? "left" : "mono", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (jack_stereo) output_right = jack_port_register (jack_client, "right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); jack_rate = jack_get_sample_rate (jack_client); jack_buffer = _AL_MALLOC_ATOMIC(jack_bufsize * (1 + jack_16bit) * (1 + jack_stereo)); if (!jack_buffer) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text( "Cannot allocate audio buffer")); jack_exit (input); return -1; } digi_jack.voices = voices; if (_mixer_init(jack_bufsize * (1 + jack_stereo), jack_rate, jack_stereo, jack_16bit, &digi_jack.voices)) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text( "Cannot init software mixer")); jack_exit (input); return -1; } _mix_some_samples((uintptr_t) jack_buffer, 0, jack_signed); if (jack_activate (jack_client)) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text( "Cannot activate Jack client")); jack_exit (input); return 1; } /* Try to connect the ports. Failure to connect is not critical, since with * JACK, users may connect/disconnect ports anytime, without Allegro caring. */ if ((ports = jack_get_ports (jack_client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { TRACE (PREFIX_I "Cannot find any physical playback ports"); } if (ports) { if (ports[0]) { if (jack_connect (jack_client, jack_port_name (output_left), ports[0]) == 0) TRACE (PREFIX_I "Connected left playback port to %s", ports[0]); } if (jack_stereo && ports[1]) { if (jack_connect (jack_client, jack_port_name (output_right), ports[1]) == 0) TRACE (PREFIX_I "Connected right playback port to %s", ports[1]); } _AL_FREE (ports); } uszprintf(jack_desc, sizeof(jack_desc), get_config_text ("Jack, client '%s': %d bits, %s, %d bps, %s"), jack_client_name, jack_16bit ? 16 : 8, uconvert_ascii((jack_signed ? "signed" : "unsigned"), tmp), jack_rate, uconvert_ascii((jack_stereo ? "stereo" : "mono"), tmp)); return 0; }
void options_menu() { show_mouse(screen); DIALOG options_dialog[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */ {d_bitmap_proc, 0, 0,SCREEN_W,SCREEN_H,0,255, 0, 0, 0, 0, title_back}, {d_gamespeed_proc, 20, 10, 0, 0, 0, 0, 0,D_SELECTED, 0, 0, const_cast<char *>("gamespeed")}, {d_slider_proc, 300, 20, 30, 440, 0, 255, 0, 0, 255, get_config_int("MINER","BPS", 32) - 32, NULL, (void *)speedslider_callback}, {d_mapsize_proc, 20, 60, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("mapsize")}, {d_slider_proc, 300, 20, 30, 440, 0, 255, 0,D_HIDDEN, 80, get_config_int("MINER","MAP_SIZE",20) - 20, NULL, (void *)mapsizeslider_callback}, {d_sound_proc, 20, 110, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("sound")}, {d_slider_proc, 300, 40, 30, 300, 0, 255, 0,D_HIDDEN, 6, (int)log2(get_config_int("MINER","NR_OF_VOICES",0) + 1), NULL, (void *)soundslider_callback}, {d_text_proc, 300, 10, 200, 30, 0, 255, 0,D_HIDDEN, 0, 0, const_cast<char *>("Nr of simultaneous sounds")}, {d_number_proc, 330, 20, 0, 0, 0, 0, 0, 0, 3, get_config_int("MINER","BPS", 32), NULL}, {d_number_proc, 330, 20, 0, 0, 0, 0, 0,D_HIDDEN, 3, get_config_int("MINER","MAP_SIZE",20) , NULL}, {d_number_proc, 330, 40, 0, 0, 0, 0, 0,D_HIDDEN, 2, get_config_int("MINER","NR_OF_VOICES",1), NULL}, {d_back_proc, 20, 160, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("exit menu")}, {NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL} }; the_options_dialog = options_dialog; // ugly, but I found it easier to initialise the dialog // within the function, where all BITMAPS's are loaded etc. PALETTE options_palette; for (int i=0;i < 256;i++) { options_palette[i].r = game_palette[i].g; options_palette[i].g = game_palette[i].b; options_palette[i].b = game_palette[i].r; } set_dialog_color(options_dialog, bestfit_color(options_palette,0,0,0), bestfit_color(options_palette,63,63,63)); DIALOG_PLAYER *p = init_dialog(options_dialog, 1); broadcast_dialog_message(MSG_DRAW, 0); // update_dialog(p); if (fade_speed) { fade_from(desktop_palette,options_palette,fade_speed); } else { set_palette(options_palette); } while(update_dialog(p)); shutdown_dialog(p); set_config_int("MINER","BPS", options_dialog[SPEED_SLIDER].d2 + 32); set_config_int("MINER","MAP_SIZE", options_dialog[MAPSIZE_SLIDER].d2 + 20); set_config_int("MINER","NR_OF_VOICES", (1<<options_dialog[SOUND_SLIDER].d2)); show_mouse(NULL); reinit(); return; }
int main() { BITMAP *mysha = NULL, *buffer = NULL; PARTICLE *particle[NUM_PARTICLES]; int old_time = 0, old_time2 = 0; int i; int count = 0; int use_alleg = FALSE; int depth = 16; allegro_init(); install_keyboard(); install_timer(); set_config_file("examples.cfg"); depth = get_config_int("examples", "depth", 16); set_color_depth(depth); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(16); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(15); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { allegro_message("Unable to set 640x480 screen mode!\n"); return -1; } } } } mysha = load_bitmap("mysha.pcx", NULL); if (!mysha) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n"); return -2; } TRACE("Got here!\n"); for (i = 0; i < NUM_PARTICLES; i++) particle[i] = NULL; TRACE("Still here!\n"); for (i = 0; i < NUM_PARTICLES; i++) { int j; int r, g, b; TRACE("Going for particle: %i\n", i); particle[i] = malloc(sizeof(PARTICLE)); if (!particle[i]) { TRACE("Out of memory while creating particle!\n"); goto Error; } TRACE("Clearing particle\n"); memset(particle[i], 0, sizeof(PARTICLE)); TRACE("Creating bitmap\n"); particle[i]->bmp = create_bitmap(64, 64); if (!particle[i]->bmp) { TRACE("Out of memory while creating particle bitmap!\n"); goto Error; } TRACE("Clearing bitmap\n"); clear(particle[i]->bmp); TRACE("Setting up coordinates\n"); particle[i]->x = rand() % SCREEN_W; particle[i]->y = rand() % SCREEN_H; particle[i]->vx = rand() % 10 - 5; particle[i]->vy = rand() % 10 - 5; particle[i]->a = rand() & 255; particle[i]->a_dir = 1; TRACE("Setting up colors\n"); hsv_to_rgb(rand() % 360, 1, 1, &r, &g, &b); TRACE("Drawing circles\n"); for (j = 1; j < 31; j++) { circle(particle[i]->bmp, 31, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1))); circle(particle[i]->bmp, 32, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1))); } } LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); buffer = create_bitmap(SCREEN_W, SCREEN_H); if (!buffer) { TRACE("Out of memory while creating back buffer!\n"); goto Error; } clear(buffer); TRACE("Starting...\n"); install_int(the_timer, 1); old_time = chrono; text_mode(0); do { int chrono2; /* Tile mysha over the screen */ #ifndef COMPARE_WITH_ALLEGRO blit(mysha, buffer, 0, 0, 0, 0, mysha->w, mysha->h); blit(mysha, buffer, 0, 0, 320, 0, mysha->w, mysha->h); blit(mysha, buffer, 0, 0, 0, 200, mysha->w, mysha->h); blit(mysha, buffer, 0, 0, 320, 200, mysha->w, mysha->h); blit(mysha, buffer, 0, 0, 0, 400, mysha->w, mysha->h); blit(mysha, buffer, 0, 0, 320, 400, mysha->w, mysha->h); #endif if (use_alleg) { for (i = 0; i < NUM_PARTICLES; i++) { set_difference_blender(0, 0, 0, particle[i]->a); draw_trans_sprite(buffer, particle[i]->bmp, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2); } } else { for (i = 0; i < NUM_PARTICLES; i++) fblend_sub(particle[i]->bmp, buffer, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2, particle[i]->a); } if (key[KEY_SPACE]) { use_alleg = !use_alleg; key[KEY_SPACE] = 0; chrono = 0; count = 0; old_time = 0; old_time2 = 0; } count++; #ifdef COMPARE_WITH_ALLEGRO textprintf(screen, font, 0, 0, makecol(255, 255, 255), "%s %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono); #else textprintf(buffer, font, 0, 0, makecol(255, 255, 255), "%s %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono); #endif old_time2 = chrono; #ifndef COMPARE_WITH_ALLEGRO /* Draw the buffer */ blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); #endif chrono2 = chrono / 40; for (i = old_time/40; i < chrono2; i++) { int j; for (j = 0; j < NUM_PARTICLES; j++) { particle[j]->x += particle[j]->vx; particle[j]->y += particle[j]->vy; if (particle[j]->x <= 0 || particle[j]->x >= SCREEN_W) particle[j]->vx = -particle[j]->vx; if (particle[j]->y <= 0 || particle[j]->y >= SCREEN_H) particle[j]->vy = -particle[j]->vy; if (particle[j]->a <= 0 || particle[j]->a >= 256) particle[j]->a_dir = -particle[j]->a_dir; particle[j]->a += particle[j]->a_dir; } } old_time = chrono; } while (!key[KEY_ESC]); Error: TRACE("Shutting down.\n"); if (mysha) destroy_bitmap(mysha); if (buffer) destroy_bitmap(buffer); for (i = 0; i < NUM_PARTICLES; i++) { if (particle[i]) { if (particle[i]->bmp) destroy_bitmap(particle[i]->bmp); free(particle[i]); } } set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); return 0; } END_OF_MAIN();
static void load_gui_config(int& w, int& h, bool& maximized) { w = get_config_int("GfxMode", "Width", 0); h = get_config_int("GfxMode", "Height", 0); maximized = get_config_bool("GfxMode", "Maximized", false); }
// called only from ReadINIFileInfo for reading in the information from the // ini file and storing it globally static BOOL ReadFromDriverIniFile(void) { char * pBuffer = NULL; char Buffer[255]; int i, k; int argc; char ** argv; pBuffer = get_config_string("General", "Description", "None"); if (strcmp(pBuffer, "None") == 0) { DisplayError("Can't load .ini driver!"); return FALSE; } strncpy(GameDescription, pBuffer, MAX_GAME_DESCRIPTION); GameDescription[MAX_GAME_DESCRIPTION -1] = 0; if ((NumGfxBanks = get_config_int("Layout", "GfxDecodes", 0)) == 0) { DisplayError("INI file error 'GfxDecodes'"); return FALSE; } // if this fail the orientation will be 0 - which is OK. Orientation = get_config_int("Layout", "Orientation", 0); GfxBanks = malloc(NumGfxBanks * sizeof(SPRITE_PALETTE)); if (GfxBanks == NULL) { DisplayError("GfxBanks malloc failed"); return FALSE; } GfxBankExtraInfo = malloc(NumGfxBanks * sizeof(GFXBANKEXTRA)); if (GfxBankExtraInfo == NULL) { free(GfxBanks); DisplayError("GfxBanksExtra malloc failed"); return FALSE; } for (i = 0; i < NumGfxBanks; i++) { char GfxBank[10]; sprintf(GfxBank, "Decode%d", i+1); // read staight forward stuff from INI file GfxBanks[i].sprite_w = get_config_int(GfxBank, "width", -1); GfxBanks[i].sprite_h = get_config_int(GfxBank, "height", -1); GfxBanks[i].n_total = get_config_int(GfxBank, "total", -1); GfxBanks[i].first_sprite = 0; // set the position to the default GfxBankExtraInfo[i].planes = get_config_int(GfxBank, "planes", -1); GfxBankExtraInfo[i].startaddress = get_config_int(GfxBank, "start", -1); GfxBankExtraInfo[i].charincrement = get_config_int(GfxBank, "charincrement", -1); // did any fail? if ((GfxBanks[i].sprite_w == -1) || (GfxBanks[i].sprite_h == -1) || (GfxBanks[i].n_total == -1) || (GfxBankExtraInfo[i].planes == -1) || (GfxBankExtraInfo[i].startaddress == -1) || (GfxBankExtraInfo[i].charincrement == -1)) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt"); return FALSE; } // read plane offsets and store in array argv = get_config_argv(GfxBank, "planeoffsets", &argc); // sanity check if (argc != GfxBankExtraInfo[i].planes) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - planeoffsets"); return FALSE; } // copy planeoffsets in to array for (k = 0; k < argc; k++) GfxBankExtraInfo[i].planeoffsets[k] = atol(argv[k]); // read xoffsets and store in array get_config_int_array(GfxBank, "xoffsets", GfxBankExtraInfo[i].xoffset, &argc); // sanity check if (argc != GfxBanks[i].sprite_w) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - xoffsets"); return FALSE; } // read yoffsets and store in array get_config_int_array(GfxBank, "yoffsets", GfxBankExtraInfo[i].yoffset, &argc); // sanity check if (argc != GfxBanks[i].sprite_h) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - yoffsets"); return FALSE; } } // calculate the number of graphics roms NumGfxRoms = 0; do { NumGfxRoms++; sprintf(Buffer, "Rom%d", NumGfxRoms); pBuffer = get_config_string("GraphicsRoms", Buffer, "None"); } while (strcmp(pBuffer, "None") != 0); NumGfxRoms --; // is the ini file corrupt? if (NumGfxRoms == 0) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - graphicsroms"); return FALSE; } // allocate memory for appropriate number of structures; GfxRoms = malloc(NumGfxRoms * sizeof(GFXROM)); if (GfxRoms == NULL) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("GfxRoms malloc failed"); return FALSE; } // read the information in to the array for (i = 0; i < NumGfxRoms; i ++) { // read rom info and store in array sprintf(Buffer, "Rom%d", i+1); argv = get_config_argv("GraphicsRoms", Buffer, &argc); // sanity check if (argc != 3) // loadaddress,size,name { free(GfxBanks); free(GfxBankExtraInfo); free(GfxRoms); DisplayError("INI file corrupt - %s", Buffer); return FALSE; } // copy info in to array GfxRoms[i].LoadAddress = atol(argv[0]); GfxRoms[i].Size = atol(argv[1]); GfxRoms[i].Alternate = FALSE; // detect for Alternate byte loading flag if ((GfxRoms[i].Size & ALTERNATE_ROMS_DETECT) == ALTERNATE_ROMS_DETECT) { GfxRoms[i].Size &= ALTERNATE_ROMS_SIZE; GfxRoms[i].Alternate = TRUE; } strncpy(GfxRoms[i].ROMName, argv[2], MAX_ROM_NAME); GfxRoms[i].ROMName[MAX_ROM_NAME -1] = 0; } // finally read in the colour palettes or set defaults if none // exist if (ReadColourPalettes() == FALSE) { // free any allocated colour palettes for (i = 0; i < MAX_COL_PLANES; i++) { if (ColPalettes[i] != NULL) { free(ColPalettes[i]); ColPalettes[i] = NULL; NumColPalettes[i] = 0; } } free(GfxBanks); free(GfxBankExtraInfo); free(GfxRoms); return FALSE; } return TRUE; }
void inicia_allegro() { int profundidade, res; allegro_init(); install_timer(); install_keyboard(); clear_keybuf(); install_mouse(); set_uformat(U_ASCII); // Habilita acentuação em ALGUMAS FONTES /*profundidade = desktop_color_depth(); if (profundidade == 0) profundidade = 32; set_color_depth(profundidade);*/ //roda configuracao de um arquivo set_config_file("config.txt"); profundidade = get_config_int("Inicializacao", "colordepth",32); int v = GetVersion() & 65535; float versao = (v%256) + (v/256)/10.; /*if (versao<=5.1) //5.1 = XP, 6.0 = Vista, 6.1 Win7 profundidade=16; else profundidade=32;*/ set_color_depth(profundidade); //padrao é 32 bits, no XP é 16 volume=get_config_int("Inicializacao", "volume", 128); //usa as config de volume do arquivo exibirFPS=get_config_int("Inicializacao", "exibirFps", 0); #define GFX_BWINDOWSCREEN_ACCEL AL_ID('B','W','S','A') #define GFX_BWINDOWSCREEN AL_ID('B','W','S',' ') AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen_accel); AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen); vSync = get_config_int("Inicializacao", "vsync",0); resolucaoX = get_config_int("Inicializacao", "resolucaox",800); resolucaoY = get_config_int("Inicializacao", "resolucaoy",600); //Fullscreen //res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN & GFX_BWINDOWSCREEN_ACCEL, resolucaoX, resolucaoY, 0, 0); //Janela res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, resolucaoX, resolucaoY, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)) { allegro_message("Sound Error: %s", allegro_error); } //inicializa o metodo de atualizacao initialize_screen_updating(get_config_int("Inicializacao", "updatemethod", UPDATE_TRIPLE_BUFFER)); set_window_title("Snake Criado por Arthur Assuncao"); //nome da Janela set_display_switch_mode(SWITCH_BACKGROUND); //roda o allegro em segundo plano //Botao fechar LOCK_FUNCTION(BotaoFechar); set_close_button_callback(BotaoFechar); //Contador de frames // Faz o lock das variaveis usadas pela funcao de timer e da propria funcao LOCK_VARIABLE(fps); LOCK_VARIABLE(contFrames); LOCK_FUNCTION(funcFPS); //chama a funcao funcFPS install_int_ex(funcFPS,BPS_TO_TIMER(MAXFPS)); //Frames por segundo, 60FPS //chama a funcao funcTempo LOCK_VARIABLE(contTempo); LOCK_FUNCTION(funcTempo); install_int(funcTempo, 1000); //Timer "ticks" a cada mil milisegundos, ou seja, 1 segundo /* adicione outras iniciacoes aqui */ }
void parse_INIfile_raw () { # if 0 //LUDO: TO_BE_DONE ! #ifdef MSDOS char x; #endif Log ("Looking in %s\n", config_file); read_joy_mapping (); strcpy (initial_path, get_config_string ("main", "rom_dir", ".")); if ((initial_path[0]) && (initial_path[strlen (initial_path) - 1] != '/') && (initial_path[strlen (initial_path) - 1] != '\\')) strcat (initial_path, "/"); // rom_dir setting Log ("Setting initial path to %s\n", initial_path); #if defined(ALLEGRO) strcpy (skin_filename, get_config_string ("main", "skin", "skin_h~1.bmp")); // skin filename to look for Log ("Skin filename set to %s\n", skin_filename); #endif current_config = get_config_int ("main", "config", 0); // choose input config Log ("Setting joypad config number to %d\n", current_config); language = min (get_config_int ("main", "language", 0), NB_LANG - 1); // language setting Log ("Setting language to %d\n", language); #if defined(ALLEGRO) vmode = get_config_int ("main", "vmode", 0); // video mode setting Log ("Setting video mode to %d\n", vmode); static_refresh = get_config_int ("main", "static_refresh", 0); // file selector refreshment Log ("Setting static refresh to %d\n", static_refresh); #endif smode = get_config_int ("main", "smode", -1); // sound mode setting Log ("Setting sound mode to %d\n", smode); use_eagle = get_config_int ("main", "eagle", 0); // do we use EAGLE ? Log ("Setting eagle mode to %d\n", use_eagle); use_scanline = get_config_int ("main", "scanline", 0); // do we use EAGLE ? Log ("Setting scanline mode to %d\n", use_scanline); option.want_snd_freq = get_config_int ("main", "snd_freq", 22050); // frequency of the sound generator Log ("Setting default frequency to %d\n", option.want_snd_freq); #if defined(WIN32) sbuf_size = get_config_int ("main", "buffer_size", 1024); #elif defined(LINUX) sbuf_size = get_config_int ("main", "buffer_size", 512); #else sbuf_size = get_config_int ("main", "buffer_size", 256); #endif // size of the sound buffer Log ("Setting sound buffer size to %d bytes\n", sbuf_size); gamepad_driver = get_config_int ("main", "joy_type", -1); Log ("Setting joy type to %d\n", gamepad_driver); sound_driver = get_config_int ("main", "sound_driver", 1); Log ("Setting sound driver to %d\n", sound_driver); #if defined(ALLEGRO) zip_support_in_fs = get_config_int ("main", "zip_support", 1); Log ("Setting zip support in File Selector to %d\n", zip_support_in_fs); #endif synchro = get_config_int ("main", "limit_fps", 0); Log ("Setting fps limitation to %d\n", synchro); option.want_fullscreen = get_config_int ("main", "start_fullscreen", 0); Log ("Setting start in fullscreen mode to %d\n", option.want_fullscreen); option.want_fullscreen_aspect = get_config_int ("main", "use_fullscreen_aspect", 0); Log ("Setting fullscreen aspect to %d\n", option.want_fullscreen_aspect); option.want_hardware_scaling = get_config_int ("main", "use_overlay", 0); Log ("Setting hardware scaling to %d\n", option.want_hardware_scaling); option.want_stereo = get_config_int ("main", "stereo_sound", 0); Log ("Setting stereo sound to %d\n", option.want_stereo); option.window_size = get_config_int ("main", "window_size", 1); Log ("Setting window size to %d\n", option.window_size); option.fullscreen_width = get_config_int ("main", "fullscreen_width", 640); Log ("Setting preferred fullscreen width to %d\n", option.fullscreen_width); option.fullscreen_height = get_config_int ("main", "fullscreen_height", 480); Log ("Setting preferred fullscreen height to %d\n", option.fullscreen_height); option.wanted_hardware_format = get_config_int ("main", "hardware_format", 0); Log ("Setting wanted hardware format to %x\n", option.wanted_hardware_format); #ifdef MSDOS x = get_config_int ("main", "cd_driver", 0); if (x) { osd_cd_driver = aspi_driver; Log ("Setting cd driver to ASPI\n"); } else { osd_cd_driver = mscdex_driver; Log ("Setting cd driver to MSCDEX\n"); } #endif minimum_bios_hooking = get_config_int ("main", "minimum_bios_hooking", 0); Log ("Minimum Bios hooking set to %d\n", minimum_bios_hooking); strcpy (cdsystem_path, get_config_string ("main", "cdsystem_path", "")); Log ("CD system path set to %d\n", cdsystem_path); strcpy (ISO_filename, get_config_string ("main", "cd_path", "")); Log ("CD path set to %s\n", ISO_filename); option.want_arcade_card_emulation = get_config_int ("main", "arcade_card", 1); Log ("Arcade card emulation set to %d\n", option.want_arcade_card_emulation); option.want_supergraphx_emulation = get_config_int ("main", "supergraphx", 1); Log ("SuperGraphX emulation set to %d\n", option.want_supergraphx_emulation); option.want_television_size_emulation = get_config_int ("main", "tv_size", 0); Log ("Limiting graphics size to emulate tv output set to %d\n", option.want_television_size_emulation); Log ("End of parsing INI file\n\n"); # endif }
/* Self-explanatory. */ void init_at_startup(void) { LOCK_FUNCTION (framecount); LOCK_FUNCTION (tickover); LOCK_VARIABLE (ticked); LOCK_VARIABLE (frames_per_second); LOCK_VARIABLE (framecounter); LOCK_VARIABLE (turns_per_second); LOCK_VARIABLE (turncounter); install_int (framecount, 1000); install_int (tickover, 20); set_color_depth(8); int randseed = get_config_int("Misc", "Seed", 0); srand(randseed); options.windowed = get_config_int("Misc", "Windowed", 0); int windowed; switch(options.windowed) { default: case 1: windowed = GFX_AUTODETECT_WINDOWED; break; case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break; } // windowed = GFX_AUTODETECT_WINDOWED; // windowed = GFX_AUTODETECT_FULLSCREEN; // if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) // if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0) if (set_gfx_mode(windowed, 800, 600, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 800x600 256 colour display mode. Sorry!\n%s\n", allegro_error); exit(1); } init_trig(); prepare_display(); init_sound(); /* PP.ckey [CKEY_UP] = KEY_UP; PP.ckey [CKEY_DOWN] = KEY_DOWN; PP.ckey [CKEY_LEFT] = KEY_LEFT; PP.ckey [CKEY_RIGHT] = KEY_RIGHT; PP.ckey [CKEY_FIRE1] = KEY_Z; PP.ckey [CKEY_FIRE2] = KEY_X; PP.ckey [CKEY_FIRE3] = KEY_C; */ int p = 0; init_joystick(); player[0].control = get_config_int("misc", "player1_control", CONTROL_KEY_A); player[1].control = get_config_int("misc", "player2_control", CONTROL_KEY_B); // if a particular joystick isn't available, default to keyboard controls. // note that this doesn't set the config values for (p = 0; p < 2; p ++) { if (options.joystick_available [0] == 0 && PP.control == CONTROL_JOY_A) { PP.control = CONTROL_KEY_A; if (PP.control == CONTROL_KEY_A) PP.control = CONTROL_KEY_B; } if (options.joystick_available [1] == 0 && PP.control == CONTROL_JOY_B) { PP.control = CONTROL_KEY_A; if (PP.control == CONTROL_KEY_A) PP.control = CONTROL_KEY_B; } } options.ckey [0] [CKEY_UP] = get_config_int("Misc", "key1_up", KEY_8_PAD); options.ckey [0] [CKEY_DOWN] = get_config_int("Misc", "key1_down", KEY_2_PAD); options.ckey [0] [CKEY_LEFT] = get_config_int("Misc", "key1_left", KEY_4_PAD); options.ckey [0] [CKEY_RIGHT] = get_config_int("Misc", "key1_right", KEY_6_PAD); options.ckey [0] [CKEY_LEFT2] = get_config_int("Misc", "key1_left2", KEY_1_PAD); options.ckey [0] [CKEY_RIGHT2] = get_config_int("Misc", "key1_right2", KEY_3_PAD); options.ckey [0] [CKEY_FIRE1] = get_config_int("Misc", "key1_fire1", KEY_Z); options.ckey [0] [CKEY_FIRE2] = get_config_int("Misc", "key1_fire2", KEY_X); options.ckey [0] [CKEY_FIRE3] = get_config_int("Misc", "key1_fire3", KEY_C); options.ckey [0] [CKEY_FIRE4] = get_config_int("Misc", "key1_fire4", KEY_V); options.ckey [0] [CKEY_COMMAND] = get_config_int("Misc", "key1_command", KEY_A); options.ckey [1] [CKEY_UP] = get_config_int("Misc", "key2_up", KEY_UP); options.ckey [1] [CKEY_DOWN] = get_config_int("Misc", "key2_down", KEY_DOWN); options.ckey [1] [CKEY_LEFT] = get_config_int("Misc", "key2_left", KEY_LEFT); options.ckey [1] [CKEY_RIGHT] = get_config_int("Misc", "key2_right", KEY_RIGHT); options.ckey [1] [CKEY_LEFT2] = get_config_int("Misc", "key2_left2", KEY_J); options.ckey [1] [CKEY_RIGHT2] = get_config_int("Misc", "key2_right2", KEY_K); options.ckey [1] [CKEY_FIRE1] = get_config_int("Misc", "key2_fire1", KEY_T); options.ckey [1] [CKEY_FIRE2] = get_config_int("Misc", "key2_fire2", KEY_Y); options.ckey [1] [CKEY_FIRE3] = get_config_int("Misc", "key2_fire3", KEY_U); options.ckey [1] [CKEY_FIRE4] = get_config_int("Misc", "key2_fire4", KEY_I); options.ckey [1] [CKEY_COMMAND] = get_config_int("Misc", "key2_command", KEY_O); /* PP.ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP); PP.ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN); PP.ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT); PP.ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT); PP.ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z); PP.ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X); PP.ckey [CKEY_FIRE3] = get_config_int("Misc", "key_fire3", KEY_C); PP.ckey [CKEY_FIRE4] = get_config_int("Misc", "key_fire4", KEY_V); */ /* player[1].ckey [CKEY_UP] = get_config_int("MiscP2", "key_up", KEY_UP); player[1].ckey [CKEY_DOWN] = get_config_int("MiscP2", "key_down", KEY_DOWN); player[1].ckey [CKEY_LEFT] = get_config_int("MiscP2", "key_left", KEY_LEFT); player[1].ckey [CKEY_RIGHT] = get_config_int("MiscP2", "key_right", KEY_RIGHT); player[1].ckey [CKEY_LEFT2] = get_config_int("MiscP2", "key_left2", KEY_K); player[1].ckey [CKEY_RIGHT2] = get_config_int("MiscP2", "key_right2", KEY_L); player[1].ckey [CKEY_FIRE1] = get_config_int("MiscP2", "key_fire1", KEY_0_PAD); player[1].ckey [CKEY_FIRE2] = get_config_int("MiscP2", "key_fire2", KEY_P); player[1].ckey [CKEY_FIRE3] = get_config_int("MiscP2", "key_fire3", KEY_O); player[1].ckey [CKEY_FIRE4] = get_config_int("MiscP2", "key_fire4", KEY_I); options.joy_stick = get_config_int("Misc", "joy_stick", 0); options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70); options.init_joystick = get_config_int("Misc", "joy_init", 1);*/ // options.joystick = 0; // options.key_or_joy = 0; // don't put in initfile! options.sfx_volume = get_config_int("Misc", "sfx_volume", 70); options.ambience_volume = get_config_int("Misc", "ambience_volume", 100); options.run_vsync = get_config_int("Misc", "run_vsync", 0); options.fix_camera_angle = get_config_int("Misc", "fix_camera_angle", 0); options.joystick_dual = get_config_int("Misc", "joystick_dual", 1); // set_config_int("Misc", "Tourist", 3); // set_config_int("Misc", "joy_stick", 0); // if (options.init_joystick) // if (options.joystick == 1) // set in init_joystick { options.joy_button [0] [0] = get_config_int("Misc", "joy1_button_1", 0); if (options.joy_button [0] [0] > joy[0].num_buttons) options.joy_button [0] [0] = joy[0].num_buttons - 1; options.joy_button [0] [1] = get_config_int("Misc", "joy1_button_2", 1); if (options.joy_button [0] [1] > joy[0].num_buttons) options.joy_button [0] [1] = joy[0].num_buttons - 1; options.joy_button [0] [2] = get_config_int("Misc", "joy1_button_3", 2); if (options.joy_button [0] [2] > joy[0].num_buttons) options.joy_button [0] [2] = joy[0].num_buttons - 1; options.joy_button [0] [3] = get_config_int("Misc", "joy1_button_4", 4); if (options.joy_button [0] [3] > joy[0].num_buttons) options.joy_button [0] [3] = joy[0].num_buttons - 1; options.joy_button [0] [4] = get_config_int("Misc", "joy1_button_5", 5); if (options.joy_button [0] [4] > joy[0].num_buttons) options.joy_button [0] [4] = joy[0].num_buttons - 1; options.joy_button [0] [5] = get_config_int("Misc", "joy1_button_6", 6); if (options.joy_button [0] [5] > joy[0].num_buttons) options.joy_button [0] [5] = joy[0].num_buttons - 1; options.joy_button [1] [0] = get_config_int("Misc", "joy2_button_1", 0); if (options.joy_button [1] [0] > joy[0].num_buttons) options.joy_button [1] [0] = joy[0].num_buttons - 1; options.joy_button [1] [1] = get_config_int("Misc", "joy2_button_2", 1); if (options.joy_button [1] [1] > joy[0].num_buttons) options.joy_button [1] [1] = joy[0].num_buttons - 1; options.joy_button [1] [2] = get_config_int("Misc", "joy2_button_3", 2); if (options.joy_button [1] [2] > joy[0].num_buttons) options.joy_button [1] [2] = joy[0].num_buttons - 1; options.joy_button [1] [3] = get_config_int("Misc", "joy2_button_4", 4); if (options.joy_button [1] [3] > joy[0].num_buttons) options.joy_button [1] [3] = joy[0].num_buttons - 1; options.joy_button [1] [4] = get_config_int("Misc", "joy2_button_5", 5); if (options.joy_button [1] [4] > joy[0].num_buttons) options.joy_button [1] [4] = joy[0].num_buttons - 1; options.joy_button [1] [5] = get_config_int("Misc", "joy2_button_6", 6); if (options.joy_button [1] [5] > joy[0].num_buttons) options.joy_button [1] [5] = joy[0].num_buttons - 1; } ticked = 0; arena.players = 1; // NOTE: it's assumed in a few places that if there's just one player, it's player[0]. }
void ShipData::load() { STACKTRACE; int i, index = 0, count; if (status != LOADED_NONE) return; data = tw_load_datafile(file); if (!data) tw_error("Error loading '%s'", file); set_config_data((char *)(data[index].dat), data[index].size); int num_panel_bitmaps = get_config_int("Objects", "PanelBitmaps", 0); index++; // load ship panel if (num_panel_bitmaps < 2) tw_error("Too few ship panel bitmaps"); spritePanel = new SpaceSprite(&data[index], num_panel_bitmaps, SpaceSprite::IRREGULAR); index += num_panel_bitmaps; // load ship sprites spriteShip = load_sprite("ShipSprites", data, &index); // load weapon sprites spriteWeapon = load_sprite("WeaponSprites", data, &index); // load weapon explosion sprites spriteWeaponExplosion = load_sprite("WeaponExplosion", data, &index); // load special ability sprites spriteSpecial = load_sprite("SpecialSprites", data, &index); // load special ability explosion sprites spriteSpecialExplosion = load_sprite("SpecialExplosion", data, &index); // load extra sprites spriteExtra = load_sprite("ExtraSprites", data, &index); // load extra explosion sprites spriteExtraExplosion = load_sprite("ExtraExplosion", data, &index); //load optional super-extra sprites i = 0; more_sprites = NULL; while (true) { char buffy[512]; sprintf(buffy, "ExtraExtraSprites%d", i); if (get_config_int("Objects", buffy, -1) == -1) break; more_sprites = (SpaceSprite**) realloc(more_sprites, (i+1) * sizeof(SpaceSprite*)); more_sprites[i] = load_sprite(buffy, data, &index); i += 1; } num_more_sprites = i; // initialize ship victory ditty const char* victoryDittyStr = get_config_string("Objects", "VictoryDitty", "VOIDDITTY_WAV"); int victoryIdx = datafile_victoryditty_index(victoryDittyStr); if (victoryIdx < 0) { tw_error("Unable to load victory ditty: %a", victoryDittyStr); } moduleVictory = (Music *)(victoryditty_datafile[victoryIdx].dat); // load weapon samples count = get_config_int("Objects", "WeaponSamples", 0); num_weapon_samples = count; if (count > 0) { sampleWeapon = new SAMPLE*[count]; for(i = 0; i < count; i++) { sampleWeapon[i] = (SAMPLE *)(data[index].dat); index++; } } else sampleWeapon = NULL; // load special ability samples count = get_config_int("Objects", "SpecialSamples", 0); num_special_samples = count; if (count > 0) { sampleSpecial = new SAMPLE*[count]; for(i = 0; i < count; i++) { sampleSpecial[i] = (SAMPLE *)(data[index].dat); index++; } } else sampleSpecial = NULL; // load extra samples count = get_config_int("Objects", "ExtraSamples", 0); num_extra_samples = count; if (count > 0) { sampleExtra = new SAMPLE*[count]; for(i = 0; i < count; i++) { sampleExtra[i] = (SAMPLE *)(data[index].dat); index++; } } else sampleExtra = NULL; status = LOADED_FULL; return; }