K3dOptions.h

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #pragma once
00034 
00035 #include "K3dStream.h"
00036 #include "../Script/K3dLua.h"
00037 
00038         class K3dOptions
00039         {
00040                 K3dGameData *m_pGameData;       
00041                 K3dStream *m_pStream;           
00042         
00044                 void LoadGraphics();
00046                 void LoadTexture();
00048                 void LoadFontBmp();
00050                 void LoadScript();
00051 //              void LoadObjectIds();
00052         public:
00053                 K3dOptions(K3dGameData *_pGameData);
00054                 ~K3dOptions(void);
00055                 
00056                 bool LoadOptions();
00057                 void DeleteOptions();
00058                 void PrintGraphicDriverName();
00059                 void PrintGraphicDriverInfo();
00060                 void PrintOpenglInfo();
00061                 void PrintModes();
00062                 void PrintParams(int _iWidth, int _iHeight, int _iBpp, bool _bIsSuccess);
00063 
00064         };
00065 
00067         inline void K3dOptions::LoadGraphics()
00068         {
00069                 cout << "void K3dOptions::LoadGraphics()" << endl;
00070                 TGraphicOption *ptOption = new TGraphicOption;
00071                 K3dString strFc = "void K3dOptions::LoadGraphics() -- ";
00072                 K3dString strOut;
00073                 // Get lua from global data
00074                 K3dLua *pLua = m_pGameData->GetLua();
00075                 pLua->LuaGetGlobal(K_STR_GRAPHICS);
00076                 if (!pLua->LuaIsTable(-1))
00077                 {
00078                 strOut = strFc + K_STR_GRAPHICS;
00079                         strOut += " is not a valid graphics table";
00080                         pLua->LuaError(strOut.GetString().c_str());
00081                 }
00082         ptOption->bFullscreen = pLua->LuaGetFieldBool(K_STR_FULLSCREEN);
00083                 cout << "bFullscreen = " << ptOption->bFullscreen << endl;
00084                 ptOption->iWidth = (int) pLua->LuaGetFieldNumber(K_STR_SCREENWIDTH);
00085                 cout << "iWidth = " << ptOption->iWidth << endl;
00086                 ptOption->iHeight = (int) pLua->LuaGetFieldNumber(K_STR_SCREENHEIGHT);
00087                 cout << "iHeight = " << ptOption->iHeight << endl;
00088                 ptOption->iColorBits = (int) pLua->LuaGetFieldNumber(K_STR_COLORBITS);
00089                 cout << "iColorBits = " << ptOption->iColorBits << endl;
00090                 ptOption->uiFlags = (int) pLua->LuaGetFieldNumber(K_STR_FLAGS);
00091                 cout << "uiFlags = " << ptOption->uiFlags << endl;
00092                 ptOption->iNearPlane = (int) pLua->LuaGetFieldNumber(K_STR_NEAR);
00093                 cout << "iNearPlane = " << ptOption->iNearPlane << endl;
00094                 ptOption->iFarPlane = (int) pLua->LuaGetFieldNumber(K_STR_FAR);
00095                 cout << "iFarPlane = " << ptOption->iFarPlane << endl;
00096                 ptOption->iFovy = (int) pLua->LuaGetFieldNumber(K_STR_FOVY);
00097                 cout << "iFovy = " << ptOption->iFovy << endl;
00098 
00099                 m_pGameData->SetGraphicOption(ptOption);
00100         }
00101 
00103         inline void K3dOptions::LoadTexture()
00104         {
00105                 cout << "void K3dOptions::LoadTexture()" << endl;
00106                 TTextureOption *ptOption = new TTextureOption;
00107                 K3dString strFc = "void K3dOptions::LoadTexture() -- ";
00108                 K3dString strOut;
00109 
00110                 // Get lua from global data
00111                 K3dLua *pLua = m_pGameData->GetLua();
00112                 pLua->LuaGetGlobal(K_STR_TEXTURE);
00113                 if (!pLua->LuaIsTable(-1))
00114                 {
00115                 strOut = strFc + K_STR_TEXTURE;
00116                         strOut += " is not a valid texture table";
00117                         pLua->LuaError(strOut.GetString().c_str());
00118                 }
00119                 ptOption->bLightmap = pLua->LuaGetFieldBool(K_STR_LIGHTMAP);
00120                 cout << "bLightmap = " << ptOption->bLightmap << endl;
00121                 ptOption->bLinear = pLua->LuaGetFieldBool(K_STR_LINEAR);
00122                 cout << "bLinear = " << ptOption->bLinear << endl;
00123                 ptOption->bMipmap = pLua->LuaGetFieldBool(K_STR_MIPMAP);
00124                 cout << "bMipmap = " << ptOption->bMipmap << endl;
00125                 ptOption->bMultitexture = pLua->LuaGetFieldBool(K_STR_MULTITEXTURE);
00126                 cout << "bMultitexture = " << ptOption->bMultitexture << endl;
00127                 ptOption->bTexture = pLua->LuaGetFieldBool(K_STR_TEXTURE);
00128                 cout << "bTexture = " << ptOption->bTexture << endl;
00129                 ptOption->fGamma = (float)pLua->LuaGetFieldNumber(K_STR_GAMMA);
00130                 cout << "fGamma = " << ptOption->fGamma << endl;
00131                 
00132                 m_pGameData->SetTextureOption(ptOption);
00133         }
00134 
00136         inline void K3dOptions::LoadScript()
00137         {
00138                 cout << "void K3dOptions::LoadScript()" << endl;
00139                 TScriptOption *ptOption = new TScriptOption;
00140 
00141                 K3dString strFc = "void K3dOptions::LoadScript() -- ";
00142                 K3dString strOut;
00143 
00144                 // Get lua from global data
00145                 K3dLua *pLua = m_pGameData->GetLua();
00146                 pLua->LuaGetGlobal(K_STR_SCRIPT);
00147                 if (!pLua->LuaIsTable(-1))
00148                 {
00149                         strOut = strFc + K_STR_FONTBMP;
00150                         strOut += " is not a valid script table";
00151                         pLua->LuaError(strOut.GetString().c_str());
00152                 }
00153                 K3dString strDefault = m_pGameData->GetSysHome() + K3D_STR_SHARE_PATH + pLua->LuaGetFieldString(K_STR_DEFAULT);
00154                 ptOption->strDefault = strDefault.GetString().c_str();
00155                 cout << "strDefault = " << ptOption->strDefault << endl;
00156 
00157                 m_pGameData->SetScriptOption(ptOption);
00158         }
00159 
00161         inline void K3dOptions::DeleteOptions()
00162         {
00163                 cout << "void K3dOptions::DeleteOptions()" << endl;
00164                 TGraphicOption *ptGOption = m_pGameData->GetGraphicOption();
00165                 if(ptGOption!=NULL)
00166                 {
00167                         delete ptGOption;
00168                         ptGOption = NULL;
00169                 }
00170 
00171                 TTextureOption *ptTOption = m_pGameData->GetTextureOption();
00172                 if(ptTOption!=NULL)
00173                 {
00174                         delete ptTOption;
00175                         ptTOption = NULL;
00176                 }
00177 
00178                 TFontBmpOption *ptFOption = m_pGameData->GetFontBmpOption();
00179                 if(ptFOption !=NULL)
00180                 {
00181                         delete ptFOption ;
00182                         ptFOption  = NULL;
00183                 }
00184 
00185                 TScriptOption *ptScriptOption = m_pGameData->GetScriptOption();
00186                 if(ptScriptOption !=NULL)
00187                 {
00188                         delete ptScriptOption ;
00189                         ptScriptOption  = NULL;
00190                 }
00191         }
00192 
00194         inline void K3dOptions::PrintGraphicDriverName()
00195         {
00196                 char strBuff[20];
00197                 SDL_VideoDriverName(strBuff, 20);
00198 
00199                 printf("Name of the graphic driver: %s\n", strBuff);
00200                 printf("\n");
00201         }
00202 
00204         inline void K3dOptions::PrintGraphicDriverInfo()
00205         {
00206                 printf("Info about graphic hardware:\n");
00207 
00208                 //SDL_VideoInfo *ptVinfo;
00209                 //ptVinfo = (SDL_VideoInfo *)SDL_GetVideoInfo();
00210                 SDL_VideoInfo *ptVinfo;
00211                 ptVinfo = new SDL_VideoInfo;
00212 
00213                 printf("Is it possible to create hardware surfaces?          ");
00214                 if(ptVinfo->hw_available) printf("YES\n"); else printf("NO\n");
00215 
00216                 printf("Is there a window manager available?                 ");
00217                 if(ptVinfo->wm_available) printf("YES\n"); else printf("NO\n");
00218 
00219                 printf("Are hardware to hardware blits accelerated?          ");
00220                 if(ptVinfo->blit_hw) printf("YES\n"); else printf("NO\n");
00221 
00222                 printf("Are hardware to hardware colorkey blits accelerated? ");
00223                 if(ptVinfo->blit_hw_CC) printf("YES\n"); else printf("NO\n");
00224 
00225                 printf("Are hardware to hardware alpha blits accelerated?    ");
00226                 if(ptVinfo->blit_hw_A) printf("YES\n"); else printf("NO\n");
00227 
00228                 printf("Are software to hardware blits accelerated?          ");
00229                 if(ptVinfo->blit_sw) printf("YES\n"); else printf("NO\n");
00230 
00231                 printf("Are software to hardware colorkey blits accelerated? ");
00232                 if(ptVinfo->blit_sw_CC) printf("YES\n"); else printf("NO\n");
00233 
00234                 printf("Are software to hardware alpha blits accelerated?    ");
00235                 if(ptVinfo->blit_sw_A) printf("YES\n"); else printf("NO\n");
00236 
00237                 printf("Are color fills accelerated?                         ");
00238                 if(ptVinfo->blit_fill) printf("YES\n"); else printf("NO\n");
00239 
00240                 printf("Total amount of video memory: %u kB.\n", ptVinfo->video_mem);
00241 
00242                 printf("\n");
00243                 if (ptVinfo)
00244                 {
00245                         delete ptVinfo;
00246                         ptVinfo = NULL;
00247                 }
00248         }
00249 
00251         inline void K3dOptions::PrintOpenglInfo()
00252         {
00253                 printf("OpenGL info:\n");
00254                 printf("Vendor: %s\n", glGetString(GL_VENDOR));
00255                 printf("Renderer: %s\n",glGetString(GL_RENDERER));
00256                 printf("Version: %s\n",glGetString(GL_VERSION));
00257                 printf("Extensions: %s\n",glGetString(GL_EXTENSIONS));
00258         }
00259 
00261         inline void K3dOptions::PrintModes()
00262         {
00263                 SDL_Rect **pptModes;
00264                 pptModes = SDL_ListModes(NULL, K_WIN_FLAGS);
00265 
00266                 printf("Available graphic pptModes for '%s' flags:\n", K_STR_WIN_FLAGS);
00267 
00268                 // Jsou vubec nejake mody dostupne?
00269                 if(pptModes == (SDL_Rect **)0)
00270                 {
00271                         printf("No modes available!\n");
00272                 }
00273 
00274                 if(pptModes == (SDL_Rect **)-1)
00275                 {
00276                         printf("All resolutions available.\n");
00277                 }
00278                 else
00279                 {
00280                         for(int i = 0; pptModes[i]; i++)
00281                                 printf("%d x %d\n", pptModes[i]->w, pptModes[i]->h);
00282                 }
00283 
00284                 printf("\n");
00285         }
00286 
00292         inline void K3dOptions::PrintParams(int _iWidth, int _iHeight, int _iBpp, bool _bIsSuccess)
00293         {
00294                 if(_bIsSuccess)
00295                 {
00296                         printf("Parameters of created window:\n"
00297                                 "\twidth  = %d\n"
00298                                 "\theight = %d\n"
00299                                 "\tbpp    = %d\n"
00300                                 "\tflags  = %s\n", _iWidth, _iHeight, _iBpp, K_STR_WIN_FLAGS);
00301                 }
00302                 else
00303                 {
00304                         fprintf(stderr, "Unable to create window\n"
00305                                 "\twidth  = %d\n"
00306                                 "\theight = %d\n"
00307                                 "\tbpp    = %d\n"
00308                                 "\tflags  = %s\n", _iWidth, _iHeight, _iBpp, K_STR_WIN_FLAGS);
00309                 }
00310         }

Generated on Thu Aug 16 23:53:28 2007 for K3dEngine by  doxygen 1.5.0