本文整理汇总了C++中SCP_vector类的典型用法代码示例。如果您正苦于以下问题:C++ SCP_vector类的具体用法?C++ SCP_vector怎么用?C++ SCP_vector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SCP_vector类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: particle_move_all
void particle_move_all(float frametime)
{
MONITOR_INC( NumParticles, Num_particles );
if ( !Particles_enabled )
return;
if ( Particles.empty() )
return;
for (SCP_vector<particle*>::iterator p = Particles.begin(); p != Particles.end(); )
{
particle* part = *p;
if (part->age == 0.0f) {
part->age = 0.00001f;
} else {
part->age += frametime;
}
bool remove_particle = false;
// if its time expired, remove it
if (part->age > part->max_life) {
// special case, if max_life is 0 then we want it to render at least once
if ( (part->age > frametime) || (part->max_life > 0.0f) ) {
remove_particle = true;
}
}
// if the particle is attached to an object which has become invalid, kill it
if (part->attached_objnum >= 0) {
// if the signature has changed, or it's bogus, kill it
if ( (part->attached_objnum >= MAX_OBJECTS) || (part->attached_sig != Objects[part->attached_objnum].signature) ) {
remove_particle = true;
}
}
if (remove_particle)
{
part->signature = 0;
delete part;
// if we're sitting on the very last particle, popping-back will invalidate the iterator!
if (p + 1 == Particles.end())
{
Particles.pop_back();
break;
}
else
{
*p = Particles.back();
Particles.pop_back();
continue;
}
}
// move as a regular particle
vm_vec_scale_add2( &part->pos, &part->velocity, frametime );
// next particle
++p;
}
}
示例2: StartAutopilot
// ********************************************************************************************
// Engages autopilot
// This does:
// * Control switched from player to AI
// * Time compression to 32x
// * Lock time compression -WMC
// * Tell AI to fly to targeted Nav Point (for all nav-status wings/ships)
// * Sets max waypoint speed to the best-speed of the slowest ship tagged
bool StartAutopilot()
{
// Check for support ship and dismiss it if it is not doing anything.
// If the support ship is doing something then tell the user such.
for ( object *objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) )
{
if ((objp->type == OBJ_SHIP) && !(objp->flags & OF_SHOULD_BE_DEAD))
{
Assertion((objp->instance >= 0) && (objp->instance < MAX_SHIPS),
"objp does not have a valid pointer to a ship. Pointer is %d, which is smaller than 0 or bigger than %d",
objp->instance, MAX_SHIPS);
ship *shipp = &Ships[objp->instance];
if (shipp->team != Player_ship->team)
continue;
Assertion((shipp->ship_info_index >= 0) && (shipp->ship_info_index < MAX_SHIP_CLASSES),
"Ship '%s' does not have a valid pointer to a ship class. Pointer is %d, which is smaller than 0 or bigger than %d",
shipp->ship_name, shipp->ship_info_index, MAX_SHIP_CLASSES);
ship_info *sip = &Ship_info[shipp->ship_info_index];
if ( !(sip->flags & SIF_SUPPORT) )
continue;
// don't deal with dying or departing support ships
if ( shipp->flags & (SF_DYING | SF_DEPARTING) )
continue;
Assert(shipp->ai_index != -1);
ai_info* support_ship_aip = &(Ai_info[Ships[objp->instance].ai_index]);
// is support ship trying to rearm-repair
if ( ai_find_goal_index( support_ship_aip->goals, AI_GOAL_REARM_REPAIR ) == -1 ) {
// no, so tell it to depart
ai_add_ship_goal_player( AIG_TYPE_PLAYER_SHIP, AI_GOAL_WARP, -1, NULL, support_ship_aip );
} else {
// yes
send_autopilot_msgID(NP_MSG_FAIL_SUPPORT_WORKING);
return false;
}
}
}
if (!CanAutopilot())
return false;
AutoPilotEngaged = true;
// find the ship that is "leading" all of the ships when the player starts
// autopilot
// by default the ship that is leading the autopilot session the player's
// wing leader (if the player is the wing leader then it will be the
// player).
// TODO:implement a way to allow a FREDer to say a different ship is leader
Autopilot_flight_leader = get_wing_leader(Player_ship->wingnum);
if ( Autopilot_flight_leader == NULL ) {
// force player to be the leader if he doesn't have a wing
Autopilot_flight_leader = Player_obj;
}
if (The_mission.flags & MISSION_FLAG_USE_AP_CINEMATICS)
LockAPConv = timestamp(); // lock convergence instantly
else
LockAPConv = timestamp(3000); // 3 seconds before we lock convergence
Player_use_ai = 1;
set_time_compression(1);
lock_time_compression(true);
// determine speed cap
int i,j, wcount=1, tc_factor=1;
float speed_cap = 1000000.0; // 1m is a safe starting point
float radius = Player_obj->radius, distance = 0.0f, ftemp;
bool capshipPresent = false;
int capship_counts[3]; // three size classes
capship_counts[0] = 0;
capship_counts[1] = 0;
capship_counts[2] = 0;
int capship_placed[3]; // three size classes
capship_placed[0] = 0;
capship_placed[1] = 0;
capship_placed[2] = 0;
float capship_spreads[3];
capship_spreads[0] = 0.0f;
capship_spreads[1] = 0.0f;
capship_spreads[2] = 0.0f;
SCP_vector<int> capIndexes;
// empty the autopilot wings map
autopilot_wings.clear();
//.........这里部分代码省略.........
示例3: fs2netd_spew_table_checksums
void fs2netd_spew_table_checksums(const char *outfile)
{
char full_name[MAX_PATH_LEN];
FILE *out = NULL;
char description[512] = { 0 };
char filename[65] = { 0 };
size_t offset = 0;
char *p = NULL;
if ( Table_valid_status.empty() ) {
return;
}
cf_create_default_path_string(full_name, sizeof(full_name) - 1, CF_TYPE_ROOT, outfile);
// open the outfile
out = fopen(full_name, "wt");
if (out == NULL) {
return;
}
p = Cmdline_spew_table_crcs;
while (*p && (offset < sizeof(description))) {
if (*p == '"' && offset < sizeof(description)-1) {
description[offset++] = '"';
description[offset++] = '"';
} else {
description[offset++] = *p;
}
p++;
}
// header
fprintf(out, "filename,CRC32,description\r\n");
// do all the checksums
for (SCP_vector<crc_valid_status>::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); ++tvs) {
offset = 0;
p = tvs->name;
while (*p && (offset < sizeof(filename))) {
if (*p == '"' && offset < sizeof(filename)-1) {
filename[offset++] = '"';
filename[offset++] = '"';
} else {
filename[offset++] = *p;
}
p++;
}
if (offset < sizeof(filename)) {
filename[offset] = '\0';
} else {
filename[sizeof(filename)-1] = '\0';
}
fprintf(out, "\"%s\",%u,\"%s\"\r\n", filename, tvs->crc32, description);
}
fflush(out);
fclose(out);
}
示例4: fs2netd_update_valid_tables
int fs2netd_update_valid_tables()
{
int rc;
int hacked = 0;
if ( !Logged_in ) {
return -1;
}
// if there are no tables to check with then bail
if ( Table_valid_status.empty() ) {
return -1;
}
// if we're a standalone, show a dialog saying "validating tables"
if (Game_mode & GM_STANDALONE_SERVER) {
std_create_gen_dialog("Validating tables");
std_gen_set_text("Querying FS2NetD:", 1);
}
do_full_packet = true;
In_process = true;
if (Is_standalone) {
do { rc = fs2netd_update_valid_tables_do(); } while (!rc);
} else {
rc = popup_till_condition(fs2netd_update_valid_tables_do, XSTR("&Cancel", 779), XSTR("Starting table validation", 1592));
}
In_process = false;
Local_timeout = -1;
switch (rc) {
// canceled by popup
case 0:
return -1;
// timed out
case 1: {
if ( !Is_standalone ) {
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Table validation timed out!", 1593));
}
return -1;
}
// no tables
case 2: {
if ( !Is_standalone ) {
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("No tables are available from the server for validation!", 1594));
}
return -1;
}
}
// output the status of table validity to multi.log
for (SCP_vector<crc_valid_status>::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); ++tvs) {
if (tvs->valid) {
ml_printf("FS2NetD Table Check: '%s' -- Valid!", tvs->name);
} else {
ml_printf("FS2NetD Table Check: '%s' -- INVALID (0x%x)!", tvs->name, tvs->crc32);
hacked = 1;
}
}
// if we're a standalone, kill the validate dialog
if (Game_mode & GM_STANDALONE_SERVER) {
std_destroy_gen_dialog();
}
return hacked;
}
示例5: fs2netd_get_valid_missions_do
//.........这里部分代码省略.........
return 1;
}
}
// we should have the CRCs, or there were no missions, so process them
else {
static char **file_names = NULL;
static int idx = 0, count = 0;
bool found = false;
int file_index = 0;
char valid_status = MVALID_STATUS_UNKNOWN;
char full_name[MAX_FILENAME_LEN], wild_card[10];
char val_text[MAX_FILENAME_LEN+15];
uint checksum = 0;
if (file_names == NULL) {
// allocate filename space
file_names = (char**) vm_malloc( sizeof(char*) * 1024, memory::quiet_alloc); // 1024 files should be safe!
if (file_names == NULL) {
Local_timeout = -1;
return 3;
}
memset( wild_card, 0, sizeof(wild_card) );
strcpy_s( wild_card, NOX("*") );
strcat_s( wild_card, FS_MISSION_FILE_EXT );
idx = count = cf_get_file_list(1024, file_names, CF_TYPE_MISSIONS, wild_card);
}
// drop idx first thing
idx--;
// we should be done validating, or just not have nothing to validate
if (idx < 0) {
for (idx = 0; idx < count; idx++) {
if (file_names[idx] != NULL) {
vm_free(file_names[idx]);
file_names[idx] = NULL;
}
}
vm_free(file_names);
file_names = NULL;
idx = count = 0;
Local_timeout = -1;
return 4;
}
// verify all filenames that we know about with their CRCs
// NOTE: that this is done for one file per frame, since this is inside of a popup
memset( full_name, 0, MAX_FILENAME_LEN );
strncpy( full_name, cf_add_ext(file_names[idx], FS_MISSION_FILE_EXT), sizeof(full_name) - 1 );
memset( val_text, 0, sizeof(val_text) );
snprintf( val_text, sizeof(val_text) - 1, "Validating: %s", full_name );
if (Is_standalone) {
if ( std_gen_is_active() ) {
std_gen_set_text(val_text, 1);
}
} else {
popup_change_text(val_text);
}
cf_chksum_long(full_name, &checksum);
// try and find the file
file_index = multi_create_lookup_mission(full_name);
found = false;
if (file_index >= 0) {
for (SCP_vector<file_record>::iterator fr = FS2NetD_file_list.begin(); fr != FS2NetD_file_list.end() && !found; ++fr) {
if ( !stricmp(full_name, fr->name) ) {
if (fr->crc32 == checksum) {
found = true;
valid_status = MVALID_STATUS_VALID;
} else {
valid_status = MVALID_STATUS_INVALID;
}
Multi_create_mission_list[file_index].valid_status = valid_status;
}
}
if (found) {
ml_printf("FS2NetD Mission Validation: %s => Valid!", full_name);
} else {
ml_printf("FS2NetD Mission Validation: %s => INVALID! -- 0x%08x", full_name, checksum);
}
}
}
return 0;
}
示例6: particle_render_all
void particle_render_all()
{
ubyte flags;
float pct_complete;
float alpha;
vertex pos;
vec3d ts, te, temp;
int rotate = 1;
int framenum, cur_frame;
bool render_batch = false;
int tmap_flags = TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT | TMAP_FLAG_SOFT_QUAD;
if ( !Particles_enabled )
return;
MONITOR_INC( NumParticlesRend, Num_particles );
if ( Particles.empty() )
return;
for (SCP_vector<particle*>::iterator p = Particles.begin(); p != Particles.end(); ++p) {
particle* part = *p;
// skip back-facing particles (ripped from fullneb code)
// Wanderer - add support for attached particles
vec3d p_pos;
if (part->attached_objnum >= 0) {
vm_vec_unrotate(&p_pos, &part->pos, &Objects[part->attached_objnum].orient);
vm_vec_add2(&p_pos, &Objects[part->attached_objnum].pos);
} else {
p_pos = part->pos;
}
if ( vm_vec_dot_to_point(&Eye_matrix.vec.fvec, &Eye_position, &p_pos) <= 0.0f ) {
continue;
}
// calculate the alpha to draw at
alpha = get_current_alpha(&p_pos);
// if it's transparent then just skip it
if (alpha <= 0.0f) {
continue;
}
// make sure "rotate" is enabled for this particle
rotate = 1;
// if this is a tracer style particle, calculate tracer vectors
if (part->tracer_length > 0.0f) {
ts = p_pos;
temp = part->velocity;
vm_vec_normalize_quick(&temp);
vm_vec_scale_add(&te, &ts, &temp, part->tracer_length);
// don't bother rotating
rotate = 0;
}
// rotate the vertex
if (rotate) {
flags = g3_rotate_vertex( &pos, &p_pos );
if ( flags ) {
continue;
}
if (!Cmdline_nohtl)
g3_transfer_vertex(&pos, &p_pos);
}
// pct complete for the particle
pct_complete = part->age / part->max_life;
// figure out which frame we should be using
if (part->nframes > 1) {
framenum = fl2i(pct_complete * part->nframes + 0.5);
CLAMP(framenum, 0, part->nframes-1);
cur_frame = part->reverse ? (part->nframes - framenum - 1) : framenum;
} else {
cur_frame = 0;
}
if (part->type == PARTICLE_DEBUG) {
gr_set_color( 255, 0, 0 );
g3_draw_sphere_ez( &p_pos, part->radius );
} else {
framenum = part->optional_data;
Assert( cur_frame < part->nframes );
// if this is a tracer style particle
if (part->tracer_length > 0.0f) {
batch_add_laser( framenum + cur_frame, &ts, part->radius, &te, part->radius );
}
// draw as a regular bitmap
else {
batch_add_bitmap( framenum + cur_frame, tmap_flags, &pos, part->particle_index % 8, part->radius, alpha );
}
//.........这里部分代码省略.........
示例7: red_alert_bash_wingman_status
/*
* Take the red alert status information, and adjust the red alert ships accordingly
* "red alert ships" are wingmen and any ship with the red-alert-carry flag
* Wingmen without red alert data still need to be handled / removed
*/
void red_alert_bash_wingman_status()
{
int j;
ship_obj *so;
SCP_vector<red_alert_ship_status>::iterator rasii;
SCP_vector<p_object>::iterator poii;
SCP_hash_map<int, int> Wing_pobjects_deleted;
SCP_hash_map<int, int>::iterator ii;
if ( !(Game_mode & GM_CAMPAIGN_MODE) ) {
return;
}
if ( Red_alert_wingman_status.empty() ) {
return;
}
// go through all ships in the game, and see if there is red alert status data for any
so = GET_FIRST(&Ship_obj_list);
for ( ; so != END_OF_LIST(&Ship_obj_list); )
{
object *ship_objp = &Objects[so->objnum];
Assert(ship_objp->type == OBJ_SHIP);
ship *shipp = &Ships[ship_objp->instance];
if ( !(shipp->flags & SF_FROM_PLAYER_WING) && !(shipp->flags & SF_RED_ALERT_STORE_STATUS) ) {
so = GET_NEXT(so);
continue;
}
bool ship_data_restored = false;
int ship_state = RED_ALERT_DESTROYED_SHIP_CLASS;
for ( rasii = Red_alert_wingman_status.begin(); rasii != Red_alert_wingman_status.end(); ++rasii )
{
red_alert_ship_status *ras = &(*rasii);
// red-alert data matches this ship!
if ( !stricmp(ras->name.c_str(), shipp->ship_name) )
{
// we only want to restore ships which haven't been destroyed, or were removed by the player
if ( (ras->ship_class != RED_ALERT_DESTROYED_SHIP_CLASS) && (ras->ship_class != RED_ALERT_PLAYER_DEL_SHIP_CLASS) )
{
// if necessary, restore correct ship class
if ( ras->ship_class != shipp->ship_info_index )
{
if (ras->ship_class >= 0 && ras->ship_class < MAX_SHIP_CLASSES)
change_ship_type(SHIP_INDEX(shipp), ras->ship_class);
else
mprintf(("Invalid ship class specified in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
}
// restore hull (but not shields)
if (ras->hull >= 0.0f && ras->hull <= ship_objp->hull_strength)
ship_objp->hull_strength = ras->hull;
else
mprintf(("Invalid health in red alert data for ship %s. Using mission defaults.\n", shipp->ship_name));
// restore weapons and subsys
red_alert_bash_weapons(ras, &shipp->weapons);
red_alert_bash_subsys_status(ras, shipp);
ship_data_restored = true;
}
// must be destroyed or deleted
else
{
ship_state = ras->ship_class;
}
// we won't have two ships with the same name, so bail
break;
}
}
// remove ship if it was destroyed, or if there's no red-alert data for it
if ( !ship_data_restored ) {
// we need to be a little tricky here because deletion invalidates the ship_obj
ship_obj *next_so = GET_NEXT(so);
red_alert_delete_ship(shipp, ship_state);
so = next_so;
} else {
so = GET_NEXT(so);
}
}
// NOTE: in retail, red alert data was not loaded for ships that arrived later in the mission
if (!Red_alert_applies_to_delayed_ships)
return;
// go through all ships yet to arrive, and see if there is red alert status data for any
//.........这里部分代码省略.........
示例8: find_capture_device
static void find_capture_device()
{
const char *user_device = os_config_read_string( "Sound", "CaptureDevice", NULL );
const char *default_device = (const char*) alcGetString( NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER );
// in case they are the same, we only want to test it once
if ( (user_device && default_device) && !strcmp(user_device, default_device) ) {
user_device = NULL;
}
if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE ) {
const char *all_devices = (const char*) alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
const char *str_list = all_devices;
int ext_length = 0;
if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) {
while (ext_length) {
OALdevice new_device(str_list);
if (user_device && !strcmp(str_list, user_device)) {
new_device.type = OAL_DEVICE_USER;
} else if (default_device && !strcmp(str_list, default_device)) {
new_device.type = OAL_DEVICE_DEFAULT;
}
CaptureDevices.push_back( new_device );
str_list += (ext_length + 1);
ext_length = strlen(str_list);
}
}
} else {
if (default_device) {
OALdevice new_device(default_device);
new_device.type = OAL_DEVICE_DEFAULT;
CaptureDevices.push_back( new_device );
}
if (user_device) {
OALdevice new_device(user_device);
new_device.type = OAL_DEVICE_USER;
CaptureDevices.push_back( new_device );
}
}
if ( CaptureDevices.empty() ) {
return;
}
std::sort( CaptureDevices.begin(), CaptureDevices.end(), openal_device_sort_func );
// for each device that we have available, try and figure out which to use
for (size_t idx = 0; idx < CaptureDevices.size(); idx++) {
const ALCchar *device_name = CaptureDevices[idx].device_name.c_str();
ALCdevice *device = alcCaptureOpenDevice(device_name, 22050, AL_FORMAT_MONO8, 22050 * 2);
if (device == NULL) {
continue;
}
if (alcGetError(device) != ALC_NO_ERROR) {
alcCaptureCloseDevice(device);
continue;
}
// ok, we should be good with this one
Capture_device = CaptureDevices[idx].device_name;
alcCaptureCloseDevice(device);
break;
}
}
示例9: red_alert_clear
/*
* red_alert_clear()
*
* clear all red alert "wingman" data
* Allows data to be cleared from outside REDALERT_INTERNAL code
*/
void red_alert_clear()
{
Red_alert_wingman_status.clear();
}
示例10: red_alert_store_wingman_status
/*
* Record the current state of the players wingman & ships with the "red-alert-carry" flag
* Wingmen without the red-alert-carry flag are only stored if they survive
* dead wingmen must still be handled in red_alert_bash_wingman_status
*/
void red_alert_store_wingman_status()
{
ship *shipp;
red_alert_ship_status ras;
ship_obj *so;
object *ship_objp;
// store the mission filename for the red alert precursor mission
Red_alert_precursor_mission = Game_current_mission_filename;
// Pyro3d - Clear list of stored red alert ships
// Probably not the best solution, but it prevents an assertion in change_ship_type()
Red_alert_wingman_status.clear();
// store status for all existing ships
for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
ship_objp = &Objects[so->objnum];
Assert(ship_objp->type == OBJ_SHIP);
shipp = &Ships[ship_objp->instance];
if ( shipp->flags & SF_DYING ) {
continue;
}
if ( !(shipp->flags & SF_FROM_PLAYER_WING) && !(shipp->flags & SF_RED_ALERT_STORE_STATUS) ) {
continue;
}
ras.name = shipp->ship_name;
ras.hull = Objects[shipp->objnum].hull_strength;
ras.ship_class = shipp->ship_info_index;
red_alert_store_weapons(&ras, &shipp->weapons);
red_alert_store_subsys_status(&ras, shipp);
Red_alert_wingman_status.push_back( ras );
// niffiwan: trying to track down red alert bug creating HUGE pilot files
Assert( (Red_alert_wingman_status.size() <= MAX_SHIPS) );
}
// store exited ships that did not die
for (int idx=0; idx<(int)Ships_exited.size(); idx++) {
if (Ships_exited[idx].flags & SEF_RED_ALERT_CARRY) {
ras.name = Ships_exited[idx].ship_name;
ras.hull = float(Ships_exited[idx].hull_strength);
// if a ship has been destroyed or removed manually by the player, then mark it as such ...
if ( Ships_exited[idx].flags & SEF_DESTROYED ) {
ras.ship_class = RED_ALERT_DESTROYED_SHIP_CLASS;
}
else if (Ships_exited[idx].flags & SEF_PLAYER_DELETED) {
ras.ship_class = RED_ALERT_PLAYER_DEL_SHIP_CLASS;
}
// ... otherwise we want to make sure and carry over the ship class
else {
Assert( Ships_exited[idx].ship_class >= 0 );
ras.ship_class = Ships_exited[idx].ship_class;
}
red_alert_store_weapons(&ras, NULL);
red_alert_store_subsys_status(&ras, NULL);
Red_alert_wingman_status.push_back( ras );
// niffiwan: trying to track down red alert bug creating HUGE pilot files
Assert( (Red_alert_wingman_status.size() <= MAX_SHIPS) );
}
}
Assert( !Red_alert_wingman_status.empty() );
}
示例11: hud_clear_msg_buffer
void hud_clear_msg_buffer()
{
HUD_msg_buffer.clear();
}
示例12: openal_init_device
// initializes hardware device from perferred/default/enumerated list
bool openal_init_device(SCP_string *playback, SCP_string *capture)
{
if ( !Playback_device.empty() ) {
if (playback) {
*playback = Playback_device;
}
if (capture) {
*capture = Capture_device;
}
return true;
}
if (playback) {
playback->erase();
}
if (capture) {
capture->erase();
}
// initialize default setup first, for version check...
ALCdevice *device = alcOpenDevice(NULL);
if (device == NULL) {
return false;
}
ALCcontext *context = alcCreateContext(device, NULL);
if (context == NULL) {
alcCloseDevice(device);
return false;
}
alcMakeContextCurrent(context);
// version check (for 1.0 or 1.1)
ALCint AL_minor_version = 0;
alcGetIntegerv(NULL, ALC_MINOR_VERSION, sizeof(ALCint), &AL_minor_version);
if (AL_minor_version < 1) {
os::dialogs::Message(os::dialogs::MESSAGEBOX_ERROR,
"OpenAL 1.1 or newer is required for proper operation. On Linux and Windows OpenAL Soft is recommended. If you are on Mac OS X you need to upgrade your OS.");
alcMakeContextCurrent(NULL);
alcDestroyContext(context);
alcCloseDevice(device);
return false;
}
alcGetError(device);
// close default device
alcMakeContextCurrent(NULL);
alcDestroyContext(context);
alcCloseDevice(device);
// go through and find out what devices we actually want to use ...
find_playback_device();
find_capture_device();
if ( Playback_device.empty() ) {
return false;
}
#ifndef NDEBUG
if ( !PlaybackDevices.empty() ) {
nprintf(("OpenAL", " Available Playback Devices:\n"));
for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) {
nprintf(("OpenAL", " %s", PlaybackDevices[idx].device_name.c_str()));
if (PlaybackDevices[idx].type == OAL_DEVICE_USER) {
nprintf(("OpenAL", " *preferred*\n"));
} else if (PlaybackDevices[idx].type == OAL_DEVICE_DEFAULT) {
nprintf(("OpenAL", " *default*\n"));
} else {
nprintf(("OpenAL", "\n"));
}
}
}
if ( !CaptureDevices.empty() ) {
if ( !PlaybackDevices.empty() ) {
nprintf(("OpenAL", "\n"));
}
nprintf(("OpenAL", " Available Capture Devices:\n"));
for (size_t idx = 0; idx < CaptureDevices.size(); idx++) {
nprintf(("OpenAL", " %s", CaptureDevices[idx].device_name.c_str()));
if (CaptureDevices[idx].type == OAL_DEVICE_USER) {
//.........这里部分代码省略.........
示例13: particle
// Creates a single particle. See the PARTICLE_?? defines for types.
particle *particle_create( particle_info *pinfo )
{
if ( !Particles_enabled )
{
return NULL;
}
particle* new_particle = new particle();
int fps = 1;
new_particle->pos = pinfo->pos;
new_particle->velocity = pinfo->vel;
new_particle->age = 0.0f;
new_particle->max_life = pinfo->lifetime;
new_particle->radius = pinfo->rad;
new_particle->type = pinfo->type;
new_particle->optional_data = pinfo->optional_data;
new_particle->tracer_length = pinfo->tracer_length;
new_particle->attached_objnum = pinfo->attached_objnum;
new_particle->attached_sig = pinfo->attached_sig;
new_particle->reverse = pinfo->reverse;
new_particle->particle_index = (int)Particles.size();
switch (pinfo->type) {
case PARTICLE_BITMAP:
case PARTICLE_BITMAP_PERSISTENT: {
if (pinfo->optional_data < 0) {
Int3();
delete new_particle;
return NULL;
}
bm_get_info( pinfo->optional_data, NULL, NULL, NULL, &new_particle->nframes, &fps );
if ( new_particle->nframes > 1 ) {
// Recalculate max life for ani's
new_particle->max_life = i2fl(new_particle->nframes) / i2fl(fps);
}
break;
}
case PARTICLE_FIRE: {
if (Anim_bitmap_id_fire < 0) {
delete new_particle;
return NULL;
}
new_particle->optional_data = Anim_bitmap_id_fire;
new_particle->nframes = Anim_num_frames_fire;
break;
}
case PARTICLE_SMOKE: {
if (Anim_bitmap_id_smoke < 0) {
delete new_particle;
return NULL;
}
new_particle->optional_data = Anim_bitmap_id_smoke;
new_particle->nframes = Anim_num_frames_smoke;
break;
}
case PARTICLE_SMOKE2: {
if (Anim_bitmap_id_smoke2 < 0) {
delete new_particle;
return NULL;
}
new_particle->optional_data = Anim_bitmap_id_smoke2;
new_particle->nframes = Anim_num_frames_smoke2;
break;
}
default:
new_particle->nframes = 1;
break;
}
new_particle->signature = ++lastSignature;
Particles.push_back( new_particle );
#ifndef NDEBUG
if (Particles.size() > (uint)Num_particles_hwm) {
Num_particles_hwm = (int)Particles.size();
nprintf(("Particles", "Num_particles high water mark = %i\n", Num_particles_hwm));
}
#endif
return Particles.back();
}
示例14: find_playback_device
static void find_playback_device()
{
const char *user_device = os_config_read_string( "Sound", "PlaybackDevice", NULL );
const char *default_device = (const char*) alcGetString( NULL, ALC_DEFAULT_DEVICE_SPECIFIER );
// in case they are the same, we only want to test it once
if ( (user_device && default_device) && !strcmp(user_device, default_device) ) {
user_device = NULL;
}
if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE ) {
const char *all_devices = NULL;
if ( alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE ) {
all_devices = (const char*) alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
} else {
all_devices = (const char*) alcGetString(NULL, ALC_DEVICE_SPECIFIER);
}
const char *str_list = all_devices;
int ext_length = 0;
if ( (str_list != NULL) && ((ext_length = strlen(str_list)) > 0) ) {
while (ext_length) {
OALdevice new_device(str_list);
if (user_device && !strcmp(str_list, user_device)) {
new_device.type = OAL_DEVICE_USER;
} else if (default_device && !strcmp(str_list, default_device)) {
new_device.type = OAL_DEVICE_DEFAULT;
}
PlaybackDevices.push_back( new_device );
str_list += (ext_length + 1);
ext_length = strlen(str_list);
}
}
} else {
if (default_device) {
OALdevice new_device(default_device);
new_device.type = OAL_DEVICE_DEFAULT;
PlaybackDevices.push_back( new_device );
}
if (user_device) {
OALdevice new_device(user_device);
new_device.type = OAL_DEVICE_USER;
PlaybackDevices.push_back( new_device );
}
}
if ( PlaybackDevices.empty() ) {
return;
}
std::sort( PlaybackDevices.begin(), PlaybackDevices.end(), openal_device_sort_func );
ALCdevice *device = NULL;
ALCcontext *context = NULL;
// for each device that we have available, try and figure out which to use
for (size_t idx = 0; idx < PlaybackDevices.size(); idx++) {
OALdevice *pdev = &PlaybackDevices[idx];
// open our specfic device
device = alcOpenDevice( (const ALCchar*) pdev->device_name.c_str() );
if (device == NULL) {
continue;
}
context = alcCreateContext(device, NULL);
if (context == NULL) {
alcCloseDevice(device);
continue;
}
alcMakeContextCurrent(context);
alcGetError(device);
// check how many sources we can create
static const int MIN_SOURCES = 48; // MAX_CHANNELS + 16 spare
int si = 0;
for (si = 0; si < MIN_SOURCES; si++) {
ALuint source_id = 0;
alGenSources(1, &source_id);
if (alGetError() != AL_NO_ERROR) {
break;
}
alDeleteSources(1, &source_id);
}
//.........这里部分代码省略.........