K3dScene.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00032  ***************************************************************************/
00033 
00034 #include "K3dScene.h"
00035 #include "K3dTextReadFile.h"
00036 
00037 K3dScene::K3dScene(K3dGameData *_pGameData, int _argc, char *_argv[]):
00038                         K3dTimer(_pGameData),
00039                         K3dKeyMap(_pGameData),
00040                         K3dMouse(_pGameData),
00041                         K3dLua(_pGameData),
00042                         K3dMngSystem(_pGameData),
00043                         K3dOptions(_pGameData)
00044                 {
00045                         cout << "K3dScene::K3dScene()" << endl;
00046                         m_pGameData = _pGameData;
00047                         m_bIsExit = false;
00048                         // Set this class to the global data
00049                         m_pGameData->SetScene(this);
00050                         m_pViewMatrix = m_pGameData->GetMatrixSP().New();
00051                         m_pGameData->SetViewMatrix(m_pViewMatrix);
00052 
00053                         m_iNumArguments = _argc;
00054                         for(int i=0; i<_argc; i++)
00055                         {
00056                                 m_pArgumentArray[i] = _argv[i];
00057                         }
00058                         CheckArguments();
00059                         // Load global configuration
00060                         LoadConf();
00061                         // Load global options
00062                         LoadOptions();
00063                 }
00064 
00065 K3dScene::~K3dScene()
00066 {
00067         m_pViewMatrix = m_pGameData->GetMatrixSP().Delete(m_pViewMatrix);
00068 }
00069 
00071 void K3dScene::SetScenePaths()
00072 {
00073         cout << "void K3dScene::SetScenePaths()" << endl;
00074         // Set application path
00075         //K3dString strPath = m_pArgumentArray[0];
00076         //cout << "strPath in argument = " << strPath.GetString()  << endl;
00077         // Find last "/"
00078         //size_t uiPos = strPath.RFind("/") + 1;
00079         // Remove app name
00080         //strPath.Erase(uiPos, strPath.GetSize() - uiPos);
00081         K3dString strPath = m_pGameData->GetSysHome() + K3D_STR_SHARE_PATH;
00082         cout << "strPath = " << strPath.GetString()  << endl;
00083         // Set application path
00084         m_pGameData->SetPath(strPath, K_PATH_APP);
00085         // Set maps path
00086         K3dString strMapsPath = strPath + K_STR_MAPS_PATH;
00087         cout << "strMapsPath = " << strMapsPath.GetString( )  << endl;
00088         m_pGameData->SetPath( strMapsPath, K_PATH_MAP);
00089         // Set script path
00090         K3dString strScriptPath = strPath + K_STR_SCRIPT_PATH;
00091         cout << "strScriptPath = " << strScriptPath.GetString( )  << endl;
00092         m_pGameData->SetPath( strScriptPath, K_PATH_SCRIPT);
00093 }
00094 
00096 void K3dScene::CheckArguments()
00097 {
00098         cout << "void K3dScene::CheckArguments()" << endl;
00099         // First argument is application path. Get first application argument and set default paths
00100         SetScenePaths();
00101 }
00102 
00103 
00106 void K3dScene::LoadNewScript(const char * _strFilename)
00107 {
00108         cout << "K3dScene::LoadNewScript()" << endl;
00109         // Delete this scene
00110         Delete();
00111 
00112         // Reset lua state
00113         K3dVM *pVM = m_pGameData->GetVM();
00114         if(pVM)
00115         {
00116                 pVM->RegisterFunctions();
00117                 K3dString strFilename = m_pGameData->GetPath(K_PATH_APP) + _strFilename;
00118                 pVM->GetLua()->LuaLoadFile(strFilename.GetString().c_str());
00119                 pVM->Engine_Init();
00120         }
00121 
00122 }
00123 
00126 void K3dScene::Load(K3dString& _strFilename)
00127 {
00128         cout << "void K3dScene::Load()" << endl;
00129         cout << "_strFilename = " << _strFilename.GetString( ) << endl;
00130         // Create default path array if not exists
00131         m_pGameData->InitPath();
00132         K3dString strFilename = m_pGameData->GetPath(K_PATH_APP) + _strFilename;
00133         // Set filename to the global data
00134         m_pGameData->GetMapFileName() = strFilename;
00135         Init();
00136 }
00137 
00139 void K3dScene::Init()
00140 {
00141         cout << "void K3dScene::Init()" << endl;
00142         InitMngSystem();
00143 }
00144 
00146 void K3dScene::Delete()
00147 {
00148         cout << "void K3dScene::Delete()" << endl;
00149         for(int i=0; i<m_pGameData->GetTextureObjSP().GetNum(); i++)
00150         {
00151                 K3dTextureObj *pTexture = m_pGameData->GetTextureObjSP().Get(i);
00152                 //GLuint iTexture = m_pGameData->GetTexture(i);
00153                 GLuint iTextureId = pTexture->GetId();
00154                 if(glIsTexture(iTextureId))
00155                 {
00156                         glDeleteTextures(1, &iTextureId);
00157                 }
00158         }
00159         DeleteMngSystem();
00160 }
00161 
00163 void K3dScene::Update()
00164 {
00165         // Get global timer
00166         K3dTimer *pTimer = m_pGameData->GetTimer();
00167         pTimer->CalculateFPS();
00168         UpdateKeyboard();
00169         m_pGameData->GetMouse()->UpdateMouse();
00170         UpdateMngSystem();
00171 }
00172 
00174 void K3dScene::Draw()
00175 {
00176         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00177         glLoadIdentity();
00178         DrawMngSystem();
00179         //glFlush();
00180         //SDL_GL_SwapBuffers();
00181 }

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