00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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
00060 LoadConf();
00061
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
00075
00076
00077
00078
00079
00080
00081 K3dString strPath = m_pGameData->GetSysHome() + K3D_STR_SHARE_PATH;
00082 cout << "strPath = " << strPath.GetString() << endl;
00083
00084 m_pGameData->SetPath(strPath, K_PATH_APP);
00085
00086 K3dString strMapsPath = strPath + K_STR_MAPS_PATH;
00087 cout << "strMapsPath = " << strMapsPath.GetString( ) << endl;
00088 m_pGameData->SetPath( strMapsPath, K_PATH_MAP);
00089
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
00100 SetScenePaths();
00101 }
00102
00103
00106 void K3dScene::LoadNewScript(const char * _strFilename)
00107 {
00108 cout << "K3dScene::LoadNewScript()" << endl;
00109
00110 Delete();
00111
00112
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
00131 m_pGameData->InitPath();
00132 K3dString strFilename = m_pGameData->GetPath(K_PATH_APP) + _strFilename;
00133
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
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
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
00180
00181 }