m_misc.cpp 6.9 KB

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