config.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. Copyright (C) 2005, 2010 - Cryptic Sea
  3. This file is part of Gish.
  4. Gish is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. void loadconfig(void)
  17. {
  18. int count,count2;
  19. char tempstr[32];
  20. config.resolutionx=800;
  21. config.resolutiony=600;
  22. config.bitsperpixel=32;
  23. config.depthbits=24;
  24. config.stencilbits=8;
  25. config.fullscreen=0;
  26. config.sound=1;
  27. config.music=1;
  28. config.joystick=1;
  29. option.sound=1;
  30. option.music=1;
  31. option.soundvolume=1.0f;
  32. option.musicvolume=1.0f;
  33. control[0].key[0]=SCAN_LEFT;
  34. control[0].key[1]=SCAN_RIGHT;
  35. control[0].key[2]=SCAN_DOWN;
  36. control[0].key[3]=SCAN_UP;
  37. control[0].key[4]=SCAN_A;
  38. control[0].key[5]=SCAN_SPACE;
  39. control[0].key[6]=SCAN_S;
  40. control[0].key[7]=SCAN_D;
  41. control[0].joysticknum=0;
  42. control[0].axis[0]=0;
  43. control[0].axis[1]=1;
  44. for (count=0;count<4;count++)
  45. control[0].button[count]=-1;
  46. for (count=0;count<4;count++)
  47. control[0].button[count+4]=count;
  48. control[0].button[8]=5;
  49. control[1].joysticknum=-1;
  50. control[1].axis[0]=0;
  51. control[1].axis[1]=1;
  52. for (count=0;count<4;count++)
  53. control[1].button[count]=-1;
  54. for (count=0;count<4;count++)
  55. control[1].button[count+4]=count;
  56. control[2].joysticknum=-1;
  57. control[2].axis[0]=0;
  58. control[2].axis[1]=1;
  59. for (count=0;count<4;count++)
  60. control[2].button[count]=-1;
  61. for (count=0;count<4;count++)
  62. control[2].button[count+4]=count;
  63. control[3].joysticknum=-1;
  64. control[3].axis[0]=0;
  65. control[3].axis[1]=1;
  66. for (count=0;count<4;count++)
  67. control[3].button[count]=-1;
  68. for (count=0;count<4;count++)
  69. control[3].button[count+4]=count;
  70. loadtextfile("config.txt");
  71. optionreadint(&config.resolutionx,"screenwidth=");
  72. optionreadint(&config.resolutiony,"screenheight=");
  73. optionreadint(&config.bitsperpixel,"bitsperpixel=");
  74. optionreadint(&config.depthbits,"depthbits=");
  75. optionreadint(&config.stencilbits,"stencilbits=");
  76. optionreadint(&config.fullscreen,"fullscreen=");
  77. optionreadint(&config.sound,"sound=");
  78. optionreadint(&config.music,"music=");
  79. optionreadint(&config.joystick,"joystick=");
  80. optionreadint(&option.sound,"soundon=");
  81. optionreadint(&option.music,"musicon=");
  82. count=-1;
  83. optionreadint(&count,"soundvolume=");
  84. if (count!=-1)
  85. option.soundvolume=(float)count/100.0f;
  86. count=-1;
  87. optionreadint(&count,"musicvolume=");
  88. if (count!=-1)
  89. option.musicvolume=(float)count/100.0f;
  90. for (count=0;count<4;count++)
  91. {
  92. for (count2=0;count2<16;count2++)
  93. {
  94. sprintf(tempstr,"player%dkey%d=",count+1,count2+1);
  95. optionreadint(&control[count].key[count2],tempstr);
  96. }
  97. sprintf(tempstr,"player%djoysticknum=",count+1);
  98. optionreadint(&control[count].joysticknum,tempstr);
  99. for (count2=0;count2<4;count2++)
  100. {
  101. sprintf(tempstr,"player%daxis%d=",count+1,count2+1);
  102. optionreadint(&control[count].axis[count2],tempstr);
  103. }
  104. for (count2=0;count2<16;count2++)
  105. {
  106. sprintf(tempstr,"player%dbutton%d=",count+1,count2+1);
  107. optionreadint(&control[count].button[count2],tempstr);
  108. }
  109. }
  110. windowinfo.resolutionx=config.resolutionx;
  111. windowinfo.resolutiony=config.resolutiony;
  112. windowinfo.bitsperpixel=config.bitsperpixel;
  113. windowinfo.depthbits=config.depthbits;
  114. windowinfo.stencilbits=config.stencilbits;
  115. windowinfo.fullscreen=config.fullscreen;
  116. }
  117. void saveconfig(void)
  118. {
  119. int count,count2;
  120. char tempstr[32];
  121. config.resolutionx=windowinfo.resolutionx;
  122. config.resolutiony=windowinfo.resolutiony;
  123. config.bitsperpixel=windowinfo.bitsperpixel;
  124. config.depthbits=windowinfo.depthbits;
  125. config.stencilbits=windowinfo.stencilbits;
  126. config.fullscreen=windowinfo.fullscreen;
  127. if ((fp=fopen("config.txt","wb"))==NULL)
  128. return;
  129. optionwriteint(&config.resolutionx,"screenwidth=");
  130. optionwriteint(&config.resolutiony,"screenheight=");
  131. optionwriteint(&config.bitsperpixel,"bitsperpixel=");
  132. optionwriteint(&config.depthbits,"depthbits=");
  133. optionwriteint(&config.stencilbits,"stencilbits=");
  134. optionwriteint(&config.fullscreen,"fullscreen=");
  135. optionwriteint(&config.sound,"sound=");
  136. optionwriteint(&config.music,"music=");
  137. optionwriteint(&config.joystick,"joystick=");
  138. optionwriteint(&option.sound,"soundon=");
  139. optionwriteint(&option.music,"musicon=");
  140. count=option.soundvolume*100.0f;
  141. optionwriteint(&count,"soundvolume=");
  142. count=option.musicvolume*100.0f;
  143. optionwriteint(&count,"musicvolume=");
  144. for (count=0;count<4;count++)
  145. {
  146. for (count2=0;count2<16;count2++)
  147. {
  148. sprintf(tempstr,"player%dkey%d=",count+1,count2+1);
  149. optionwriteint(&control[count].key[count2],tempstr);
  150. }
  151. sprintf(tempstr,"player%djoysticknum=",count+1);
  152. optionwriteint(&control[count].joysticknum,tempstr);
  153. for (count2=0;count2<4;count2++)
  154. {
  155. sprintf(tempstr,"player%daxis%d=",count+1,count2+1);
  156. optionwriteint(&control[count].axis[count2],tempstr);
  157. }
  158. for (count2=0;count2<16;count2++)
  159. {
  160. sprintf(tempstr,"player%dbutton%d=",count+1,count2+1);
  161. optionwriteint(&control[count].button[count2],tempstr);
  162. }
  163. }
  164. fclose(fp);
  165. }
  166. void notsupportedmenu(void)
  167. {
  168. int count;
  169. char *glvendor;
  170. char *glrenderer;
  171. char *glversion;
  172. char *ext;
  173. glvendor=(char *) glGetString(GL_VENDOR);
  174. glrenderer=(char *) glGetString(GL_RENDERER);
  175. glversion=(char *) glGetString(GL_VERSION);
  176. ext=(char *) glGetString(GL_EXTENSIONS);
  177. resetmenuitems();
  178. while (!menuitem[0].active && !windowinfo.shutdown)
  179. {
  180. glClearColor(0.0f,0.0f,0.0f,0.0f);
  181. glClear(GL_COLOR_BUFFER_BIT);
  182. numofmenuitems=0;
  183. createmenuitem("Exit",8,8,16,1.0f,1.0f,1.0f,1.0f);
  184. setmenuitem(MO_HOTKEY,SCAN_ESC);
  185. count=352;
  186. createmenuitem("NVIDIA Drivers",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  187. count+=16;
  188. createmenuitem("ATI Drivers",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  189. count+=16;
  190. createmenuitem("Intel Drivers",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  191. count+=16;
  192. checksystemmessages();
  193. checkkeyboard();
  194. checkmouse();
  195. checkmenuitems();
  196. setuptextdisplay();
  197. count=224;
  198. drawtext("Multitexture required",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  199. count+=16;
  200. count+=16;
  201. drawtext("Make sure you have the",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  202. count+=16;
  203. drawtext("latest video card drivers",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  204. count+=16;
  205. drawtext("for your computer",(320|TEXT_CENTER),count,16,1.0f,1.0f,1.0f,1.0f);
  206. count+=16;
  207. count=432;
  208. drawtext("GL_VERSION: /s",8,count,12,1.0f,1.0f,1.0f,1.0f,glversion);
  209. count+=12;
  210. drawtext("GL_VENDOR: /s",8,count,12,1.0f,1.0f,1.0f,1.0f,glvendor);
  211. count+=12;
  212. drawtext("GL_RENDERER: /s",8,count,12,1.0f,1.0f,1.0f,1.0f,glrenderer);
  213. count+=12;
  214. drawmenuitems();
  215. drawmousecursor(768+font.cursornum,mouse.x,mouse.y,16,1.0f,1.0f,1.0f,1.0f);
  216. SDL_GL_SwapBuffers();
  217. if (menuitem[1].active)
  218. {
  219. launchwebpage("www.nvidia.com/content/drivers/drivers.asp");
  220. menuitem[1].active=0;
  221. }
  222. if (menuitem[2].active)
  223. {
  224. launchwebpage("ati.amd.com/support/driver.html");
  225. menuitem[2].active=0;
  226. }
  227. if (menuitem[3].active)
  228. {
  229. launchwebpage("downloadcenter.intel.com");
  230. menuitem[3].active=0;
  231. }
  232. }
  233. resetmenuitems();
  234. if ((fp=fopen("glreport.txt","wb"))==NULL)
  235. return;
  236. fprintf(fp,"%s\r\n",glversion);
  237. fprintf(fp,"%s\r\n",glvendor);
  238. fprintf(fp,"%s\r\n",glrenderer);
  239. fprintf(fp,"%s\r\n",ext);
  240. }
  241. void optionreadint(int *ptr,char *str)
  242. {
  243. if (findstring(str))
  244. *ptr=getint();
  245. parser.textloc=0;
  246. }
  247. void optionwriteint(int *ptr,char *str)
  248. {
  249. fprintf(fp,"%s%d\r\n",str,*ptr);
  250. }
  251. void optionreadstring(char *ptr,char *str,int size)
  252. {
  253. if (findstring(str))
  254. getstring(ptr,size);
  255. parser.textloc=0;
  256. }
  257. void optionwritestring(char *ptr,char *str,int size)
  258. {
  259. fprintf(fp,"%s%s\r\n",str,ptr);
  260. }