static bool_t del_font( char *fontname ) { font_node_t *fontnode; if ( del_hash_entry(font_table, fontname, (hash_entry_t*)(&fontnode)) ) { check_assertion( fontnode->ref_count == 0, "Trying to delete font with non-zero reference " "count" ); delete_tex_font_metrics( fontnode->tfm ); fontnode->tex->ref_count -= 1; free(fontnode); return True; } return False; }
bool_t unbind_texture( char *binding ) { texture_node_t *tex; if (get_hash_entry( binding_table, binding, (hash_entry_t*)(&tex))) { tex->ref_count--; if (!del_hash_entry( binding_table, binding, NULL )) { check_assertion(0, "Cannot delete known texture binding"); return False; } return True; } return False; }
bool_t unbind_font( char *binding ) { font_t *font; if (get_hash_entry( binding_table, binding, (hash_entry_t*)(&font))) { font->node->ref_count -= 1; if (!del_hash_entry( binding_table, binding, NULL )) { check_assertion(0, "Cannot delete known font binding"); return False; } free(font); return True; } return False; }
/*! Associate the sounds in the _name_ array with the sound context sound_context. If more than one sound is specified, then a sound will be chosen randomly from the list each time the sound is played. If num_sounds == 0, then the entry for the sound context is deleted. \pre \c sound_context != NULL \arg \c sound_context sound context to bind sounds to \arg \c names list of sound names to bind to context \arg \c num_sounds number of elements in \c names \return none \author jfpatry \date Created: 2000-08-13 \date Modified: 2000-08-14 */ void bind_sounds_to_context( char *sound_context, char **names, int num_sounds ) { int i; sound_context_data_t *data; check_assertion( initialized_, "audio module not initialized" ); if ( get_hash_entry( sound_contexts_, sound_context, (hash_entry_t*) &data ) ) { /* Entry for this context already exists; decrement ref_cts & delete arrays */ for (i=0; i<data->num_sounds; i++) { decr_sound_data_ref_ctr( data->sound_names[i] ); free( data->sound_names[i] ); } free( data->sound_names ); free( data->chunks ); del_hash_entry( sound_contexts_, sound_context, NULL ); } else { data = (sound_context_data_t*)malloc( sizeof(sound_context_data_t) ); } if ( num_sounds == 0 ) { /* delete the context */ free( data ); return; } check_assertion( num_sounds > 0, "num_sounds isn't > 0 " ); data->num_sounds = num_sounds; data->sound_names = (char**)malloc( sizeof(char*)*num_sounds ); data->chunks = (Mix_Chunk**)malloc( sizeof(Mix_Chunk*)*num_sounds ); data->loop_count = 0; data->channel = 0; data->volume = 128; for (i=0; i<num_sounds; i++) { data->sound_names[i] = string_copy( names[i] ); incr_sound_data_ref_ctr( names[i] ); data->chunks[i] = NULL; } add_hash_entry( sound_contexts_, sound_context, (hash_entry_t)data ); }
/*! Associate the music with name _name_ to the music context _music_context_. If _name_ is NULL or the null string, the data for the music context will be deleted. \pre \c music_context != \c NULL \arg \c music_context music context to bind sounds to \arg \c name name of music to bind to context \arg \c loop number of loops to play music for (-1 to loop forever) \return none \author jfpatry \date Created: 2000-08-13 \date Modified: 2000-08-14 */ void bind_music_to_context( char *music_context, char *name, int loop ) { music_context_data_t *data; check_assertion( initialized_, "audio module not initialized" ); if ( get_hash_entry( music_contexts_, music_context, (hash_entry_t*) &data ) ) { /* Entry for this context already exists; decrement ref count & delete string */ /* check if music is playing, stop if it is */ if ( current_music_name_ != NULL && strcmp( current_music_name_, data->music_name ) == 0 ) { Mix_HaltMusic(); current_music_name_ = NULL; current_music_data_ = NULL; check_assertion( get_music_playing_status( data->music_name ), "inconsistent music playing status info" ); set_music_playing_status( data->music_name, False ); } decr_music_data_ref_ctr( data->music_name ); free( data->music_name ); del_hash_entry( music_contexts_, music_context, NULL ); } else { data = (music_context_data_t*)malloc( sizeof(music_context_data_t) ); } if ( name == NULL || name[0]=='\0' ) { /* delete the context */ free( data ); return; } data->music_name = string_copy( name ); incr_music_data_ref_ctr( name ); data->music = NULL; data->loop = loop; add_hash_entry( music_contexts_, music_context, (hash_entry_t)data ); }
/*! Adds a mouse up callback for the specified widget. \pre widget != NULL \arg \c widget the widget to receive mouse up events \arg \c cb the callback function (NULL to remove callback) \return None \author jfpatry \date Created: 2000-09-16 \date Modified: 2000-09-16 */ void ui_add_mouse_up_callback( void* widget, mouse_button_event_cb_t cb ) { char *key; hash_table_t table; ui_callback_data_t *cb_data; key = generate_key_from_pointer( widget ); table = mouse_up_cbs; if ( get_hash_entry( table, key, NULL) ) { del_hash_entry( table, key, (hash_entry_t*)&cb_data ); free(cb_data); } if ( cb != NULL ) { add_hash_entry( table, key, generate_cb_data( widget, (void*) cb ) ); } }
bool_t del_texture( char *texname ) { texture_node_t *tex; print_debug( DEBUG_TEXTURE, "Deleting texture %s", texname ); if (del_hash_entry(texture_table, texname, (hash_entry_t*)(&tex))) { check_assertion( tex->ref_count == 0, "Trying to delete texture with non-zero reference " "count" ); glDeleteTextures( 1, &(tex->texture_id) ); free(tex); return True; } return False; }
/* Delete targets marked with state = state */ int delete_targets(int state) { target_t *p = NULL; target_t *d = NULL; int i = 0; int entries = 0; for (i=0;i<HASHSIZE;i++) { p = hash.table[i]; while (p) { d = p; p = p->next; if (d->init == state) { del_hash_entry(d); entries++; } } } return entries; }
bool_t bind_texture( char *binding, char *texname ) { texture_node_t *tex, *oldtex; print_debug(DEBUG_TEXTURE, "Binding %s to texture name: %s", binding, texname); if (!get_texture( texname, &tex)) { check_assertion(0, "Attempt to bind to unloaded texture"); return False; } if (get_hash_entry(binding_table, binding, (hash_entry_t*)(&oldtex))) { oldtex->ref_count--; if (!del_hash_entry(binding_table, binding, NULL)) { check_assertion(0, "Cannot delete known texture"); return False; } } add_hash_entry(binding_table, binding, (hash_entry_t)tex); tex->ref_count++; return True; }
void add_vnum(int vnum) { hash_entry * entry; hash_entry * range, * temp; int start_vnum; int end_vnum; int cnt; /* Adds a vnum, adding to beggining or ends */ start_vnum=vnum; end_vnum=vnum; for ( ; ; ) { cnt=0; if ( (range=get_hash_entry(start_vnum-1)) != NULL) { if (range->offset > 0) printf("ERROR in ranges vnum: %i range start: %i range end: %i", start_vnum, range->vnum, range->vnum+range->offset); else { start_vnum=range->vnum+range->offset; if ( range->offset != 0 && (temp=get_hash_entry(start_vnum)) != NULL) del_hash_entry(temp); del_hash_entry(range); cnt=1; } } if ( (range=get_hash_entry(end_vnum+1)) != NULL) { if (range->offset < 0) printf("ERROR in ranges vnum: %i range start: %i range end: %i", end_vnum, range->vnum+range->offset, range->vnum); else { end_vnum=range->vnum+range->offset; if ( range->offset != 0 && (temp=get_hash_entry(start_vnum)) != NULL) del_hash_entry(temp); del_hash_entry(range); cnt=1; } } if (!cnt) break; } if (start_vnum == end_vnum) { entry=malloc(sizeof(hash_entry)); entry->vnum=start_vnum; entry->offset=0; add_hash_entry(entry); } else { entry=malloc(sizeof(hash_entry)); entry->vnum=start_vnum; entry->offset=end_vnum-start_vnum; add_hash_entry(entry); entry=malloc(sizeof(hash_entry)); entry->vnum=end_vnum; entry->offset=start_vnum-end_vnum; add_hash_entry(entry); } }