DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

m_misc.cpp (7099B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "Precompiled.h"
     30 #include "globaldata.h"
     31 
     32 
     33 #include <sys/stat.h>
     34 #include <sys/types.h>
     35 #include <fcntl.h>
     36 #include <stdlib.h>
     37 
     38 #include <ctype.h>
     39 
     40 
     41 #include "doomdef.h"
     42 #include "g_game.h"
     43 #include "z_zone.h"
     44 
     45 #include "m_swap.h"
     46 #include "m_argv.h"
     47 
     48 #include "w_wad.h"
     49 
     50 #include "i_system.h"
     51 #include "i_video.h"
     52 #include "v_video.h"
     53 
     54 #include "hu_stuff.h"
     55 
     56 // State.
     57 #include "doomstat.h"
     58 
     59 // Data.
     60 #include "dstrings.h"
     61 
     62 #include "m_misc.h"
     63 #include "d3xp/Game_local.h"
     64 
     65 //
     66 // M_DrawText
     67 // Returns the final X coordinate
     68 // HU_Init must have been called to init the font
     69 //
     70 
     71 int
     72 M_DrawText
     73 ( int		x,
     74   int		y,
     75   qboolean	direct,
     76   char*		string )
     77 {
     78     int 	c;
     79     int		w;
     80 
     81     while (*string)
     82     {
     83 	c = toupper(*string) - HU_FONTSTART;
     84 	string++;
     85 	if (c < 0 || c> HU_FONTSIZE)
     86 	{
     87 	    x += 4;
     88 	    continue;
     89 	}
     90 		
     91 	w = SHORT (::g->hu_font[c]->width);
     92 	if (x+w > SCREENWIDTH)
     93 	    break;
     94 	if (direct)
     95 	    V_DrawPatchDirect(x, y, 0, ::g->hu_font[c]);
     96 	else
     97 	    V_DrawPatch(x, y, 0, ::g->hu_font[c]);
     98 	x+=w;
     99     }
    100 
    101     return x;
    102 }
    103 
    104 
    105 //
    106 // M_WriteFile
    107 //
    108 boolean M_WriteFile ( char const*	name, void*		source, int		length ) {
    109 	
    110 	idFile *		handle = NULL;
    111 	int		count;
    112 
    113 	handle = fileSystem->OpenFileWrite( name, "fs_savepath" );
    114 
    115 	if (handle == NULL )
    116 		return false;
    117 
    118 	count = handle->Write( source, length );
    119 	fileSystem->CloseFile( handle );
    120 
    121 	if (count < length)
    122 		return false;
    123 
    124 	return true;
    125 }
    126 
    127 
    128 //
    129 // M_ReadFile
    130 //
    131 int M_ReadFile ( char const*	name, byte**	buffer ) {
    132 	int count, length;
    133 	idFile * handle = NULL;
    134 	byte		*buf;
    135 
    136 	handle = fileSystem->OpenFileRead( name, false );
    137 
    138 	if (handle == NULL ) {
    139 		I_Error ("Couldn't read file %s", name);
    140 	}
    141 
    142 	length = handle->Length();
    143 
    144 	buf = ( byte* )Z_Malloc ( handle->Length(), PU_STATIC, NULL);
    145 	count = handle->Read( buf, length );
    146 
    147 	if (count < length ) {
    148 		I_Error ("Couldn't read file %s", name);
    149 	}
    150 
    151 	fileSystem->CloseFile( handle );
    152 
    153 	*buffer = buf;
    154 	return length;
    155 }
    156 
    157 //
    158 // Write a save game to the specified device using the specified game name.
    159 //
    160 static qboolean SaveGame( void* source, DWORD length )
    161 {
    162 	return false;
    163 }
    164 
    165 
    166 qboolean M_WriteSaveGame( void* source, int length )
    167 {
    168 	return SaveGame( source, length );
    169 }
    170 
    171 int M_ReadSaveGame( byte** buffer )
    172 {
    173 	return 0;
    174 }
    175 
    176 
    177 //
    178 // DEFAULTS
    179 //
    180 
    181 
    182 
    183 
    184 
    185 
    186 
    187 
    188 
    189 
    190 
    191 // machine-independent sound params
    192 
    193 
    194 // UNIX hack, to be removed.
    195 #ifdef SNDSERV
    196 #endif
    197 
    198 #ifdef LINUX
    199 #endif
    200 
    201 extern const char* const temp_chat_macros[];
    202 
    203 
    204 
    205 
    206 
    207 
    208 
    209 //
    210 // M_SaveDefaults
    211 //
    212 void M_SaveDefaults (void)
    213 {
    214 /*
    215     int		i;
    216     int		v;
    217     FILE*	f;
    218 	
    219     f = f o pen (::g->defaultfile, "w");
    220     if (!f)
    221 	return; // can't write the file, but don't complain
    222 		
    223     for (i=0 ; i<::g->numdefaults ; i++)
    224     {
    225 	if (::g->defaults[i].defaultvalue > -0xfff
    226 	    && ::g->defaults[i].defaultvalue < 0xfff)
    227 	{
    228 	    v = *::g->defaults[i].location;
    229 	    fprintf (f,"%s\t\t%i\n",::g->defaults[i].name,v);
    230 	} else {
    231 	    fprintf (f,"%s\t\t\"%s\"\n",::g->defaults[i].name,
    232 		     * (char **) (::g->defaults[i].location));
    233 	}
    234     }
    235 	
    236     fclose (f);
    237 */
    238 }
    239 
    240 
    241 //
    242 // M_LoadDefaults
    243 //
    244 
    245 void M_LoadDefaults (void)
    246 {
    247     int		i;
    248     //int		len;
    249     //FILE*	f;
    250     //char	def[80];
    251     //char	strparm[100];
    252     //char*	newstring;
    253     //int		parm;
    254     //qboolean	isstring;
    255     
    256     // set everything to base values
    257     ::g->numdefaults = sizeof(::g->defaults)/sizeof(::g->defaults[0]);
    258     for (i=0 ; i < ::g->numdefaults ; i++)
    259 		*::g->defaults[i].location = ::g->defaults[i].defaultvalue;
    260     
    261     // check for a custom default file
    262     i = M_CheckParm ("-config");
    263     if (i && i < ::g->myargc-1)
    264     {
    265 		::g->defaultfile = ::g->myargv[i+1];
    266 		I_Printf ("	default file: %s\n",::g->defaultfile);
    267     }
    268     else
    269 		::g->defaultfile = ::g->basedefault;
    270 
    271 /*
    272     // read the file in, overriding any set ::g->defaults
    273     f = f o pen (::g->defaultfile, "r");
    274     if (f)
    275     {
    276 		while (!feof(f))
    277 		{
    278 			isstring = false;
    279 			if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
    280 			{
    281 				if (strparm[0] == '"')
    282 				{
    283 					// get a string default
    284 					isstring = true;
    285 					len = strlen(strparm);
    286 					newstring = (char *)DoomLib::Z_Malloc(len, PU_STATIC, 0);
    287 					strparm[len-1] = 0;
    288 					strcpy(newstring, strparm+1);
    289 				}
    290 				else if (strparm[0] == '0' && strparm[1] == 'x')
    291 					sscanf(strparm+2, "%x", &parm);
    292 				else
    293 					sscanf(strparm, "%i", &parm);
    294 				
    295 				for (i=0 ; i<::g->numdefaults ; i++)
    296 					if (!strcmp(def, ::g->defaults[i].name))
    297 					{
    298 						if (!isstring)
    299 							*::g->defaults[i].location = parm;
    300 						else
    301 							*::g->defaults[i].location = (int) newstring;
    302 						break;
    303 					}
    304 			}
    305 		}
    306 			
    307 		fclose (f);
    308     }
    309 */
    310 }
    311 
    312 
    313 //
    314 // SCREEN SHOTS
    315 //
    316 
    317 
    318 
    319 
    320 //
    321 // WritePCXfile
    322 //
    323 void
    324 WritePCXfile
    325 ( char*		filename,
    326   byte*		data,
    327   int		width,
    328   int		height,
    329   byte*		palette )
    330 {
    331 	I_Error( "depreciated" );
    332 }
    333 
    334 
    335 //
    336 // M_ScreenShot
    337 //
    338 void M_ScreenShot (void)
    339 {
    340 /*
    341     int		i;
    342     byte*	linear;
    343     char	lbmname[12];
    344     
    345     // munge planar buffer to linear
    346     linear = ::g->screens[2];
    347     I_ReadScreen (linear);
    348     
    349     // find a file name to save it to
    350     strcpy(lbmname,"DOOM00.pcx");
    351 		
    352     for (i=0 ; i<=99 ; i++)
    353     {
    354 		lbmname[4] = i/10 + '0';
    355 		lbmname[5] = i%10 + '0';
    356 		if (_access(lbmname,0) == -1)
    357 			break;	// file doesn't exist
    358     }
    359     if (i==100)
    360 		I_Error ("M_ScreenShot: Couldn't create a PCX");
    361     
    362     // save the pcx file
    363     WritePCXfile (lbmname, linear,
    364 		  SCREENWIDTH, SCREENHEIGHT,
    365 		  (byte*)W_CacheLumpName ("PLAYPAL",PU_CACHE_SHARED));
    366 	
    367     ::g->players[::g->consoleplayer].message = "screen shot";
    368 */
    369 }
    370 
    371 
    372