Exemplo n.º 1
0
static int mission_menu_handler(listbox *lb, d_event *event, mission_menu *mm)
{
	const char **list = listbox_get_items(lb);
	int citem = listbox_get_citem(lb);

	switch (event->type)
	{
		case EVENT_NEWMENU_SELECTED:
			if (citem >= 0)
			{
				// Chose a mission
				strcpy(GameCfg.LastMission, list[citem]);
				
				if (!load_mission(mm->mission_list + citem))
				{
					nm_messagebox( NULL, 1, TXT_OK, TXT_MISSION_ERROR);
					return 1;	// stay in listbox so user can select another one
				}
			}
			return !(*mm->when_selected)();
			break;

		case EVENT_WINDOW_CLOSE:
			free_mission_list(mm->mission_list);
			d_free(list);
			d_free(mm);
			break;
			
		default:
			break;
	}
	
	return 0;
}
Exemplo n.º 2
0
Arquivo: hash.c Projeto: btb/d2x
void hashtable_free( hashtable *ht )	{
	if (ht->key != NULL )
		d_free( ht->key );
	if (ht->value != NULL )
		d_free( ht->value );
	ht->size = 0;
}
Exemplo n.º 3
0
int automap_handler(window *wind, d_event *event, automap *am)
{
	switch (event->type)
	{
		case EVENT_WINDOW_ACTIVATED:
			game_flush_inputs();
			event_toggle_focus(1);
			key_toggle_repeat(0);
			break;

		case EVENT_WINDOW_DEACTIVATED:
			event_toggle_focus(0);
			key_toggle_repeat(1);
			break;

		case EVENT_IDLE:
		case EVENT_JOYSTICK_BUTTON_UP:
		case EVENT_JOYSTICK_BUTTON_DOWN:
		case EVENT_JOYSTICK_MOVED:
		case EVENT_MOUSE_BUTTON_UP:
		case EVENT_MOUSE_BUTTON_DOWN:
		case EVENT_MOUSE_MOVED:
			automap_process_input(wind, event, am);
			break;
		case EVENT_KEY_COMMAND:
		case EVENT_KEY_RELEASE:
		{
			int kret = automap_key_command(wind, event, am);
			if (!kret)
				automap_process_input(wind, event, am);
			return kret;
		}
			
		case EVENT_WINDOW_DRAW:
			draw_automap(am);
			break;
			
		case EVENT_WINDOW_CLOSE:
			if (!am->pause_game)
				ConsoleObject->mtype.phys_info.flags |= am->old_wiggle;		// Restore wiggle
			event_toggle_focus(0);
			key_toggle_repeat(1);
#ifdef OGL
			gr_free_bitmap_data(&am->automap_background);
#endif
			d_free(am->edges);
			d_free(am->drawingListBright);
			d_free(am);
			window_set_visible(Game_wind, 1);
			Automap_active = 0;
			return 0;	// continue closing
			break;

		default:
			return 0;
			break;
	}

	return 1;
}
Exemplo n.º 4
0
void gr_close()
{
	ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;

	if (gl_initialized)
	{
		ogl_smash_texture_list_internal();
	}

	if (grd_curscreen)
	{
		if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
			d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
		d_free(grd_curscreen);
	}
	ogl_close_pixel_buffers();
#ifdef _WIN32
	if (ogl_rt_loaded)
		OpenGL_LoadLibrary(false);
#endif

#ifdef OGLES
	ogles_destroy();
#ifdef RPI
	con_printf(CON_DEBUG, "RPi: cleanuing up\n");
	if (dispman_display != DISPMANX_NO_HANDLE) {
		rpi_destroy_element();
		con_printf(CON_DEBUG, "RPi: closing display\n");
		vc_dispmanx_display_close(dispman_display);
		dispman_display = DISPMANX_NO_HANDLE;
	}
#endif
#endif
}
Exemplo n.º 5
0
Arquivo: sphere.c Projeto: paud/d2x-xl
int CreateSphere (tSphereData *sdP)
{
	int			nFaces, i, j;
	tOOF_vector	*buf [2];

if (sdP->nFaceNodes == 3) {
	nFaces = 8;
	j = 6;
	}
else {
	nFaces = 6;
	j = 4;
	}
for (i = 0; i < sdP->nTessDepth; i++)
	nFaces *= j;
for (i = 0; i < 2; i++) {
	if (!(buf [i] = (tOOF_vector *) d_malloc (nFaces * (sdP->nFaceNodes + 1) * sizeof (tOOF_vector)))) {
		if (i)
			d_free (buf [i - 1]);
		return -1;
		}
	}
j = (sdP->nFaceNodes == 3) ? 
	 BuildSphereTri ((tOOF_triangle **) buf, &nFaces, sdP->nTessDepth) : 
	 BuildSphereQuad ((tOOF_quad **) buf, &nFaces, sdP->nTessDepth);
d_free (buf [!j]);
sdP->pSphere = buf [j];
return nFaces;
}
Exemplo n.º 6
0
void free_mission(void)
{
    // May become more complex with the editor
    if (Current_mission)
	{
		if (Current_mission->path && !PLAYING_BUILTIN_MISSION)
		{
			char hogpath[PATH_MAX];

			sprintf(hogpath, MISSION_DIR "%s.hog", Current_mission->path);
			PHYSFSX_contfile_close(hogpath);
		}

		if (Current_mission->path)
			d_free(Current_mission->path);

		if (Level_names)
			d_free(Level_names);
		if(Secret_level_names)
			d_free(Secret_level_names);
		if(Secret_level_table)
			d_free(Secret_level_table);
		
        d_free(Current_mission);
    }
}
Exemplo n.º 7
0
Arquivo: sphere.c Projeto: paud/d2x-xl
int CreateSphere (tOOF_vector **pSphere)
{
    int			nFaces, i, j;
    tOOF_vector	*buf [2];

    if (gameData.render.sphere.nFaceNodes == 3) {
        nFaces = 8;
        j = 6;
    }
    else {
        nFaces = 6;
        j = 4;
    }
    for (i = 0; i < gameData.render.sphere.nTessDepth; i++)
        nFaces *= j;
    for (i = 0; i < 2; i++) {
        if (!(buf [i] = (tOOF_vector *) d_malloc (nFaces * (gameData.render.sphere.nFaceNodes + 1) * sizeof (tOOF_vector)))) {
            if (i)
                d_free (buf [i - 1]);
            return -1;
        }
    }
    j = (gameData.render.sphere.nFaceNodes == 3) ?
        BuildSphereTri ((tOOF_triangle **) buf, &nFaces) :
        BuildSphereQuad ((tOOF_quad **) buf, &nFaces);
    d_free (buf [!j]);
    *pSphere = buf [j];
    return nFaces;
}
Exemplo n.º 8
0
void align_polygon_model_data(polymodel *pm)
{
	int i, chunk_len;
	int total_correction = 0;
	ubyte *cur_old, *cur_new;
	chunk cur_ch;
	chunk ch_list[MAX_CHUNKS];
	int no_chunks = 0;
	int tmp_size = pm->model_data_size + SHIFT_SPACE;
	ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data

	Assert(tmp != NULL);
	//start with first chunk (is always aligned!)
	cur_old = pm->model_data;
	cur_new = tmp;
	chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
	memcpy(cur_new, cur_old, chunk_len);
	while (no_chunks > 0) {
		int first_index = get_first_chunks_index(ch_list, no_chunks);
		cur_ch = ch_list[first_index];
		// remove first chunk from array:
		no_chunks--;
		for (i = first_index; i < no_chunks; i++)
			ch_list[i] = ch_list[i + 1];
		// if (new) address unaligned:
		if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
			// calculate how much to move to be aligned
			short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
			// correct chunks' addresses
			cur_ch.correction += to_shift;
			for (i = 0; i < no_chunks; i++)
				ch_list[i].correction += to_shift;
			total_correction += to_shift;
			Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
			Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
		}
		//write (corrected) chunk for current chunk:
		*((short *)(cur_ch.new_base + cur_ch.offset))
		  = INTEL_SHORT(cur_ch.correction
				+ INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
		//write (correctly aligned) chunk:
		cur_old = old_dest(cur_ch);
		cur_new = new_dest(cur_ch);
		chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
		memcpy(cur_new, cur_old, chunk_len);
		//correct submodel_ptr's for pm, too
		for (i = 0; i < MAX_SUBMODELS; i++)
			if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
			    && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
				pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
 	}
	d_free(pm->model_data);
	pm->model_data_size += total_correction;
	pm->model_data = 
	d_malloc(pm->model_data_size);
	Assert(pm->model_data != NULL);
	memcpy(pm->model_data, tmp, pm->model_data_size);
	d_free(tmp);
}
Exemplo n.º 9
0
Arquivo: hmp.c Projeto: btb/d2x
void hmp_close(hmp_file *hmp)
{
	int i;

	for (i = 0; i < hmp->num_trks; i++)
		if (hmp->trks[i].data)
			d_free(hmp->trks[i].data);
	d_free(hmp);
}
Exemplo n.º 10
0
static void mve_audio_callback(void *userdata, unsigned char *stream, int len)
{
	int total=0;
	int length;
	if (mve_audio_bufhead == mve_audio_buftail)
		return /* 0 */;

	//fprintf(stderr, "+ <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);

	while (mve_audio_bufhead != mve_audio_buftail                                           /* while we have more buffers  */
		   &&  len > (mve_audio_buflens[mve_audio_bufhead]-mve_audio_curbuf_curpos))        /* and while we need more data */
	{
		length = mve_audio_buflens[mve_audio_bufhead]-mve_audio_curbuf_curpos;
		memcpy(stream,                                                                  /* cur output position */
		       ((unsigned char *)mve_audio_buffers[mve_audio_bufhead])+mve_audio_curbuf_curpos,           /* cur input position  */
		       length);                                                                 /* cur input length    */

		total += length;
		stream += length;                                                               /* advance output */
		len -= length;                                                                  /* decrement avail ospace */
		d_free(mve_audio_buffers[mve_audio_bufhead]);                                   /* free the buffer */
		mve_audio_buffers[mve_audio_bufhead]=NULL;                                      /* free the buffer */
		mve_audio_buflens[mve_audio_bufhead]=0;                                         /* free the buffer */

		if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS)                                 /* next buffer */
			mve_audio_bufhead = 0;
		mve_audio_curbuf_curpos = 0;
	}

	//fprintf(stderr, "= <%d (%d), %d, %d>: %d\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len, total);
	/*    return total; */

	if (len != 0                                                                        /* ospace remaining  */
		&&  mve_audio_bufhead != mve_audio_buftail)                                     /* buffers remaining */
	{
		memcpy(stream,                                                                  /* dest */
			   ((unsigned char *)mve_audio_buffers[mve_audio_bufhead]) + mve_audio_curbuf_curpos,         /* src */
			   len);                                                                    /* length */

		mve_audio_curbuf_curpos += len;                                                 /* advance input */
		stream += len;                                                                  /* advance output (unnecessary) */
		len -= len;                                                                     /* advance output (unnecessary) */

		if (mve_audio_curbuf_curpos >= mve_audio_buflens[mve_audio_bufhead])            /* if this ends the current chunk */
		{
			d_free(mve_audio_buffers[mve_audio_bufhead]);                               /* free buffer */
			mve_audio_buffers[mve_audio_bufhead]=NULL;
			mve_audio_buflens[mve_audio_bufhead]=0;

			if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS)                             /* next buffer */
				mve_audio_bufhead = 0;
			mve_audio_curbuf_curpos = 0;
		}
	}

	//fprintf(stderr, "- <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);
}
Exemplo n.º 11
0
/* 
 * Add archives to the game.
 * 1) archives from Sharepath/Data to extend/replace builtin game content
 * 2) archived demos
 */
void PHYSFSX_addArchiveContent()
{
	char **list = NULL;
	static const char *const archive_exts[] = { ".zip", ".7z", NULL };
	char *file[2];
	int i = 0, content_updated = 0;

	con_printf(CON_DEBUG, "PHYSFS: Adding archives to the game.\n");
	// find files in Searchpath ...
	list = PHYSFSX_findFiles("", archive_exts);
	// if found, add them...
	for (i = 0; list[i] != NULL; i++)
	{
		MALLOC(file[0], char, PATH_MAX);
		MALLOC(file[1], char, PATH_MAX);
		snprintf(file[0], sizeof(char)*PATH_MAX, "%s", list[i]);
		PHYSFSX_getRealPath(file[0],file[1]);
		if (PHYSFS_addToSearchPath(file[1], 0))
		{
			con_printf(CON_DEBUG, "PHYSFS: Added %s to Search Path\n",file[1]);
			content_updated = 1;
		}
		d_free(file[0]);
		d_free(file[1]);
	}
	PHYSFS_freeList(list);
	list = NULL;

#if PHYSFS_VER_MAJOR >= 2
	// find files in DEMO_DIR ...
	list = PHYSFSX_findFiles(DEMO_DIR, archive_exts);
	// if found, add them...
	for (i = 0; list[i] != NULL; i++)
	{
		MALLOC(file[0], char, PATH_MAX);
		MALLOC(file[1], char, PATH_MAX);
		snprintf(file[0], sizeof(char)*PATH_MAX, "%s%s", DEMO_DIR, list[i]);
		PHYSFSX_getRealPath(file[0],file[1]);
		if (PHYSFS_mount(file[1], DEMO_DIR, 0))
		{
			con_printf(CON_DEBUG, "PHYSFS: Added %s to %s\n",file[1], DEMO_DIR);
			content_updated = 1;
		}
		d_free(file[0]);
		d_free(file[1]);
	}

	PHYSFS_freeList(list);
	list = NULL;
#endif

	if (content_updated)
	{
		con_printf(CON_DEBUG, "Game content updated!\n");
		PHYSFSX_listSearchPathContent();
	}
}
Exemplo n.º 12
0
void joy_close()
{
	SDL_JoystickClose(SDL_Joysticks[num_joysticks].handle);

	while (Joystick.n_axes--)
		d_free(joyaxis_text[Joystick.n_axes]);
	while (Joystick.n_buttons--)
		d_free(joybutton_text[Joystick.n_buttons]);
}
Exemplo n.º 13
0
static void free_mission_list(mle *mission_list)
{
	int i;

	for (i = 0; i < num_missions; i++)
		d_free(mission_list[i].path);
	
	d_free(mission_list);
	num_missions = 0;
}
Exemplo n.º 14
0
void plyr_read_stats_v(int *k, int *d){
	char filename[PATH_MAX];
	int k1=-1,k2=0,d1=-1,d2=0;
	PHYSFS_file *f;
	
	*k=0;*d=0;//in case the file doesn't exist.

	memset(filename, '\0', PATH_MAX);
	snprintf(filename,PATH_MAX,GameArg.SysUsePlayersDir?"Players/%s.eff":"%s.eff",Players[Player_num].callsign);
	f = PHYSFSX_openReadBuffered(filename);

	if(f)
	{
		char line[256],*word;
		if(!PHYSFS_eof(f))
		{
			 PHYSFSX_fgets(line,50,f);
			 word=splitword(line,':');
			 if(!strcmp(word,"kills"))
				*k=atoi(line);
			 d_free(word);
		}
		if(!PHYSFS_eof(f))
                {
			 PHYSFSX_fgets(line,50,f);
			 word=splitword(line,':');
			 if(!strcmp(word,"deaths"))
				*d=atoi(line);
			 d_free(word);
		 }
		if(!PHYSFS_eof(f))
		{
			 PHYSFSX_fgets(line,50,f);
			 word=splitword(line,':');
			 if(!strcmp(word,"key") && strlen(line)>10){
				 unsigned char *p;
				 if (line[0]=='0' && line[1]=='1'){
					 if ((p=decode_stat((unsigned char*)line+3,&k1,effcode1))&&
					     (p=decode_stat(p+1,&k2,effcode2))&&
					     (p=decode_stat(p+1,&d1,effcode3))){
						 decode_stat(p+1,&d2,effcode4);
					 }
				 }
			 }
			 d_free(word);
		}
		if (k1!=k2 || k1!=*k || d1!=d2 || d1!=*d)
		{
			*k=0;*d=0;
		}
	}

	if(f)
		PHYSFS_close(f);
}
Exemplo n.º 15
0
//writes out an uncompressed RGB .tga file
//if we got really spiffy, we could optionally link in libpng or something, and use that.
void write_bmp(char *savename,int w,int h,unsigned char *buf)
{
	PHYSFS_file* TGAFile;
	TGA_header TGA;
	GLbyte HeightH,HeightL,WidthH,WidthL;
	unsigned int pixel;
	unsigned char *rgbaBuf;

	buf = (unsigned char*)d_calloc(w*h*4,sizeof(unsigned char));

	rgbaBuf = (unsigned char*) d_calloc(w * h * 4, sizeof(unsigned char));
	glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaBuf);
	for(pixel = 0; pixel < w * h; pixel++) {
		*(buf + pixel * 3) = *(rgbaBuf + pixel * 4 + 2);
		*(buf + pixel * 3 + 1) = *(rgbaBuf + pixel * 4 + 1);
		*(buf + pixel * 3 + 2) = *(rgbaBuf + pixel * 4);
	}
	d_free(rgbaBuf);

	if (!(TGAFile = PHYSFSX_openWriteBuffered(savename)))
	{
		con_printf(CON_URGENT,"Could not create TGA file to dump screenshot!");
		d_free(buf);
		return;
	}

	HeightH = (GLbyte)(h / 256);
	HeightL = (GLbyte)(h % 256);
	WidthH  = (GLbyte)(w / 256);
	WidthL  = (GLbyte)(w % 256);
	// Write TGA Header
	TGA.TGAheader[0] = 0;
	TGA.TGAheader[1] = 0;
	TGA.TGAheader[2] = 2;
	TGA.TGAheader[3] = 0;
	TGA.TGAheader[4] = 0;
	TGA.TGAheader[5] = 0;
	TGA.TGAheader[6] = 0;
	TGA.TGAheader[7] = 0;
	TGA.TGAheader[8] = 0;
	TGA.TGAheader[9] = 0;
	TGA.TGAheader[10] = 0;
	TGA.TGAheader[11] = 0;
	TGA.header[0] = (GLbyte) WidthL;
	TGA.header[1] = (GLbyte) WidthH;
	TGA.header[2] = (GLbyte) HeightL;
	TGA.header[3] = (GLbyte) HeightH;
	TGA.header[4] = (GLbyte) 24;
	TGA.header[5] = 0;
	PHYSFS_write(TGAFile,&TGA,sizeof(TGA_header),1);
	PHYSFS_write(TGAFile,buf,w*h*3*sizeof(unsigned char),1);
	PHYSFS_close(TGAFile);
	d_free(buf);
}
Exemplo n.º 16
0
/**********************************************************************
 *
 *	free_posmem
 *
 * Frees memory, that is not needed to create transition table.
 */
static void free_posmem(void)
{
	REG1 int	i;
	REG2 node_t*	tnode = &rbuf.tree[rbuf.root];

	d_free(&tnode->lastpos);
	--tnode;
	for (i = rbuf.root-1; i-- >= 0; tnode--) {
		d_free(&tnode->firstpos);
		d_free(&tnode->lastpos);
	}
}
Exemplo n.º 17
0
void LoadTerrain (char *filename)
{
	grs_bitmap	bmHeight;
	int			iff_error;
	int			i, j;
	ubyte			h, hMin, hMax;

LogErr ("            loading terrain height map\n");
iff_error = iff_read_bitmap (filename, &bmHeight, BM_LINEAR);
if (iff_error != IFF_NO_ERROR) {
#if TRACE		
	con_printf (1, "File %s - IFF error: %s", filename, iff_errormsg (iff_error));
#endif		
	Error ("File %s - IFF error: %s", filename, iff_errormsg (iff_error));
}
if (gameData.render.terrain.pHeightMap)
	d_free (gameData.render.terrain.pHeightMap)
else
	atexit (FreeTerrainHeightMap);		//first time
gameData.render.terrain.nGridW = bmHeight.bm_props.w;
gameData.render.terrain.nGridH = bmHeight.bm_props.h;
Assert (gameData.render.terrain.nGridW <= TERRAIN_GRID_MAX_SIZE);
Assert (gameData.render.terrain.nGridH <= TERRAIN_GRID_MAX_SIZE);
gameData.render.terrain.pHeightMap = bmHeight.bm_texBuf;
hMax = 0;
hMin = 255;
for (i = 0; i < gameData.render.terrain.nGridW; i++)
	for (j = 0; j < gameData.render.terrain.nGridH; j++) {
		h = HEIGHT (i, j);
		if (h > hMax)
			hMax = h;
		if (h < hMin)
			hMin = h;
		}
for (i = 0; i < gameData.render.terrain.nGridW; i++) {
	for (j = 0; j < gameData.render.terrain.nGridH; j++) {
		HEIGHT (i, j) -= hMin;
		}
	}
//	d_free (bmHeight.bm_texBuf);
gameData.render.terrain.bmP = gameData.endLevel.terrain.bmP;
#if 0 //the following code turns the (palettized) terrain texture into a white TGA texture for testing
gameData.render.terrain.bmP->bm_props.rowsize *= 4;
gameData.render.terrain.bmP->bm_props.flags |= BM_FLAG_TGA;
d_free (gameData.render.terrain.bmP->bm_texBuf);
gameData.render.terrain.bmP->bm_texBuf = d_malloc (gameData.render.terrain.bmP->bm_props.h * gameData.render.terrain.bmP->bm_props.rowsize);
memset (gameData.render.terrain.bmP->bm_texBuf, 0xFF, gameData.render.terrain.bmP->bm_props.h * gameData.render.terrain.bmP->bm_props.rowsize);
#endif
LogErr ("            building terrain light map\n");
BuildTerrainLightMap ();
}
Exemplo n.º 18
0
void ui_pad_close()
{
	int i, j;

	for (i=0; i< MAX_NUM_PADS; i++ )
		if (KeyPad[i])
		{
			for (j=0; j<17; j++ )
				d_free(KeyPad[i]->buttontext[j]);
			d_free( KeyPad[i] );
			KeyPad[i] = NULL;	
		}

}
Exemplo n.º 19
0
void ui_gadget_delete_all( UI_WINDOW * wnd )
{
	UI_GADGET * tmp;

	while( wnd->gadget != NULL )
	{
		tmp = wnd->gadget;
		if (tmp->next == tmp )
		{
			wnd->gadget = NULL;
		} else {
			tmp->next->prev = tmp->prev;
			tmp->prev->next = tmp->next;
			wnd->gadget = tmp->next;
		}
		if (tmp->canvas)
			gr_free_sub_canvas( tmp->canvas );


		if (tmp->kind == 1 )    // Button
		{
			UI_GADGET_BUTTON * but1 = (UI_GADGET_BUTTON *)tmp;
			if (but1->text)
				d_free( but1->text );
		}

		if (tmp->kind == 6 )    // Inputbox
		{
			UI_GADGET_INPUTBOX * but1 = (UI_GADGET_INPUTBOX *)tmp;
			d_free( but1->text );
		}

		if (tmp->kind == 5 )    // Checkbox
		{
			UI_GADGET_CHECKBOX * but1 = (UI_GADGET_CHECKBOX *)tmp;
			d_free( but1->text );
		}
		
		if (tmp->kind == 9 )    // Icon
		{
			UI_GADGET_ICON * but1 = (UI_GADGET_ICON *)tmp;
			d_free( but1->text );
		}


		d_free( tmp );
	}
}
Exemplo n.º 20
0
void seq_close()
{
	SEQ_DUMPBUF();
	ioctl(seqfd,SNDCTL_SEQ_SYNC);
	close(seqfd);
	d_free(voices);
}
Exemplo n.º 21
0
int do_game_pause()
{
	char *msg;
	char total_time[9],level_time[9];

#ifdef NETWORK
	if (Game_mode & GM_MULTI)
	{
		netplayerinfo_on= !netplayerinfo_on;
		return(KEY_PAUSE);
	}
#endif

	MALLOC(msg, char, 1024);
	if (!msg)
		return 0;

	songs_pause();

	format_time(total_time, f2i(Players[Player_num].time_total) + Players[Player_num].hours_total*3600);
	format_time(level_time, f2i(Players[Player_num].time_level) + Players[Player_num].hours_level*3600);
	if (Newdemo_state!=ND_STATE_PLAYBACK)
		snprintf(msg,1024,"PAUSE\n\nSkill level:  %s\nHostages on board:  %d\nTime on level: %s\nTotal time in game: %s",MENU_DIFFICULTY_TEXT(Difficulty_level),Players[Player_num].hostages_on_board,level_time,total_time);
	else
	  	snprintf(msg,1024,"PAUSE\n\nSkill level:  %s\nHostages on board:  %d\n",MENU_DIFFICULTY_TEXT(Difficulty_level),Players[Player_num].hostages_on_board);
	set_screen_mode(SCREEN_MENU);

	if (!window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))pause_handler, msg))
		d_free(msg);

	return 0 /*key*/;	// Keycode returning ripped out (kreatordxx)
}
Exemplo n.º 22
0
void _CDECL_ FreeTerrainLightMap ()
{
if (gameData.render.terrain.pLightMap) {
	LogErr ("unloading terrain light map\n");
	d_free (gameData.render.terrain.pLightMap);
	}
}
Exemplo n.º 23
0
void _CDECL_ FreeTerrainHeightMap (void)
{
if (gameData.render.terrain.pHeightMap) {
	LogErr ("unloading terrain height map\n");
	d_free (gameData.render.terrain.pHeightMap);
	}
}
Exemplo n.º 24
0
void medkey_init()
{
	PHYSFS_file * keyfile;
	char keypress[100];
	char line_buffer[200];
	int key;
	int i;	//, size;
	int np;
	char * LispCommand;

	MALLOC( LispCommand, char, DIAGNOSTIC_MESSAGE_MAX );

	for (i=0; i<2048; i++ )
		KeyFunction[i] = NULL;

	keyfile = PHYSFSX_openReadBuffered( "GLOBAL.KEY" );
	if (keyfile)
	{
		while (PHYSFSX_fgets(line_buffer, 200, keyfile))
		{
			sscanf(line_buffer, " %s %s ", keypress, LispCommand);
			//ReadLispMacro( keyfile, LispCommand );

			if ( (key=DecodeKeyText( keypress ))!= -1 )
			{
				Assert( key < 2048);
				KeyFunction[key] = func_get( LispCommand, &np );
			} else {
				Error( "Bad key %s in GLOBAL.KEY!", keypress );
			}
		}
		PHYSFS_close(keyfile);
	}
	d_free( LispCommand );
}
Exemplo n.º 25
0
void free_mission(void)
{
    // May become more complex with the editor
    if (Current_mission)
	{
		if (!PLAYING_BUILTIN_MISSION)
		{
			char hogpath[PATH_MAX];

			sprintf(hogpath, MISSION_DIR "%s.hog", Current_mission->path);
			PHYSFSX_contfile_close(hogpath);
		}
		d_free(Current_mission->path);
        d_free(Current_mission);
    }
}
Exemplo n.º 26
0
Arquivo: med.c Projeto: paud/d2x-xl
void medkey_init()
{
	FILE * keyfile;
	char keypress[100];
	int key;
	int i;	//, size;
	int np;
	char * LispCommand;

	MALLOC( LispCommand, char, DIAGNOSTIC_MESSAGE_MAX );

	for (i=0; i<2048; i++ )
		KeyFunction[i] = NULL;

	keyfile = fopen( "GLOBAL.KEY", "rt" );
	if (keyfile)
	{
		while (fscanf( keyfile, " %s %s ", keypress, LispCommand ) != EOF )
		{
			//ReadLispMacro( keyfile, LispCommand );

			if ( (key=DecodeKeyText( keypress ))!= -1 )
			{
				Assert( key < 2048);
				KeyFunction[key] = func_get( LispCommand, &np );
			} else {
				Error( "Bad key %s in GLOBAL.KEY!", keypress );
			}
		}
		fclose(keyfile);
	}
	d_free( LispCommand );
}
Exemplo n.º 27
0
Arquivo: sphere.c Projeto: paud/d2x-xl
void DestroySphere (tSphereData *sdP)
{
if (sdP) {
	d_free (sdP->pSphere);
	sdP->nFaces = 0;
	}
}
Exemplo n.º 28
0
Arquivo: digi.c Projeto: paud/d2x-xl
int DigiSpeedupSound (digi_sound *gsp, struct sound_slot *ssp, int speed)
{
    int	h, i, j, l;
    ubyte	*pDest, *pSrc;

    l = FixMulDiv (ssp->bResampled ? ssp->length : gsp->length, speed, F1_0);
    if (!(pDest = (ubyte *) d_malloc (l)))
        return -1;
    pSrc = ssp->bResampled ? ssp->samples : gsp->data;
    for (h = i = j = 0; i < l; i++) {
        pDest [j] = pSrc [i];
        h += speed;
        while (h >= F1_0) {
            j++;
            h -= F1_0;
        }
    }
    if (ssp->bResampled)
    {
        d_free (ssp->samples);
    }
    else
        ssp->bResampled = 1;
    ssp->samples = pDest;
    return ssp->length = j;
}
Exemplo n.º 29
0
Arquivo: hash.c Projeto: btb/d2x
int hashtable_init( hashtable *ht, int size )	{
	int i;

	ht->size=0;

	for (i=1; i<13; i++ )	{
		if ( (1<<i) >= size )	{
			ht->bitsize = i;
			ht->size = 1<<i;
			break;
		}
	}
	size = ht->size;
	ht->and_mask = ht->size - 1;
	if (ht->size==0)
		Error( "Hashtable has size of 0" );

	ht->key = d_malloc( size * sizeof(char *) );
	if (ht->key==NULL)
		Error( "Not enough memory to create a hash table of size %d", size );

	for (i=0; i<size; i++ )
		ht->key[i] = NULL;

	// Use calloc cause we want zero'd array.
	ht->value = d_malloc( size*sizeof(int) );
	if (ht->value==NULL)	{
		d_free(ht->key);
		Error( "Not enough memory to create a hash table of size %d\n", size );
	}

	ht->nitems = 0;

	return 0;
}
Exemplo n.º 30
0
/*
 * dput()
 *
 * This is complicated by the fact that we do not want to put
 * dentries that are no longer on any hash chain on the unused
 * list: we'd much rather just get rid of them immediately.
 *
 * However, that implies that we have to traverse the dentry
 * tree upwards to the parents which might _also_ now be
 * scheduled for deletion (it may have been only waiting for
 * its last child to go away).
 *
 * This tail recursion is done by hand as we don't want to depend
 * on the compiler to always get this right (gcc generally doesn't).
 * Real recursion would eat up our stack space.
 */
void dput(struct dentry *dentry)
{
	int count;

	if (!dentry)
		return;

repeat:
	count = dentry->d_count - 1;
	if (count != 0)
		goto out;

	/*
	 * Note that if d_op->d_delete blocks,
	 * the dentry could go back in use.
	 * Each fs will have to watch for this.
	 */
	if (dentry->d_op && dentry->d_op->d_delete) {
		dentry->d_op->d_delete(dentry);

		count = dentry->d_count - 1;
		if (count != 0)
			goto out;
	}

	if (!list_empty(&dentry->d_lru)) {
		dentry_stat.nr_unused--;
		list_del(&dentry->d_lru);
	}
	if (list_empty(&dentry->d_hash)) {
		struct dentry * parent;

		list_del(&dentry->d_child);
		dentry_iput(dentry);
		parent = dentry->d_parent;
		d_free(dentry);
		if (dentry == parent)
			return;
		dentry = parent;
		goto repeat;
	}
	list_add(&dentry->d_lru, &dentry_unused);
	dentry_stat.nr_unused++;
	/*
	 * Update the timestamp
	 */
	dentry->d_reftime = jiffies;

out:
	if (count >= 0) {
		dentry->d_count = count;
		return;
	}

	printk(KERN_CRIT "Negative d_count (%d) for %s/%s\n",
		count,
		dentry->d_parent->d_name.name,
		dentry->d_name.name);
	*(int *)0 = 0;	
}