From 117a5289ead3a4fd7eab1502da2be5ab3966c011 Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Sat, 12 Jul 2014 19:37:34 +0000 Subject: fixed issue #223 about disabling shadows/ground textures --- src/graphics/engine/engine.cpp | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e0861d2..d0b37a5 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3124,67 +3124,67 @@ void CEngine::Draw3DScene() m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN); - // Draw terrain with shadows, if shadows enabled - if (m_shadowVisible) + // Draw terrain + + m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); + + for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) { - m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); + if (! m_objects[objRank].used) + continue; - for (int objRank = 0; objRank < static_cast(m_objects.size()); objRank++) - { - if (! m_objects[objRank].used) - continue; + if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) + continue; - if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) - continue; + if (! m_objects[objRank].drawWorld) + continue; - if (! m_objects[objRank].drawWorld) - continue; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + if (! IsVisible(objRank)) + continue; - if (! IsVisible(objRank)) - continue; + int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; - int baseObjRank = m_objects[objRank].baseObjRank; - if (baseObjRank == -1) - continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); - assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - EngineBaseObject& p1 = m_baseObjects[baseObjRank]; - if (! p1.used) - continue; + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); + + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) { - EngineBaseObjTexTier& p2 = p1.next[l2]; + EngineBaseObjLODTier& p3 = p2.next[l3]; - SetTexture(p2.tex1, 0); - SetTexture(p2.tex2, 1); + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) + continue; - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) { - EngineBaseObjLODTier& p3 = p2.next[l3]; - - if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) - continue; - - for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) - { - EngineBaseObjDataTier& p4 = p3.next[l4]; + EngineBaseObjDataTier& p4 = p3.next[l4]; - SetMaterial(p4.material); - SetState(p4.state); + SetMaterial(p4.material); + SetState(p4.state); - DrawObject(p4); - } + DrawObject(p4); } } } + } - // Draws the shadows + // Draws the shadows , if shadows enabled + if (m_shadowVisible) DrawShadow(); - } + m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN); -- cgit v1.2.3-1-g7c22 From a56e69883fe74618db71b18b1748f15c06eafc29 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 6 Aug 2014 16:57:59 +0200 Subject: Removed some unused code --- src/CBot/ClassFILE.cpp | 426 ----------------------------------------------- src/object/robotmain.cpp | 193 --------------------- src/object/robotmain.h | 1 - 3 files changed, 620 deletions(-) delete mode 100644 src/CBot/ClassFILE.cpp (limited to 'src') diff --git a/src/CBot/ClassFILE.cpp b/src/CBot/ClassFILE.cpp deleted file mode 100644 index 6906bd4..0000000 --- a/src/CBot/ClassFILE.cpp +++ /dev/null @@ -1,426 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// definition of methods for class FILE - - - -// Static variables - -static CBotClass* m_pClassFILE; -static CBotProgram* m_pFuncFile; -static int m_CompteurFileOpen = 0; - - - -// Prepares a file name. - -void PrepareFilename(CBotString &filename) //DD! -{ - int pos; - - pos = filename.ReverseFind('\\'); - if ( pos > 0 ) - { - filename = filename.Mid(pos+1); // remove the records (files)?? - } - - pos = filename.ReverseFind('/'); - if ( pos > 0 ) - { - filename = filename.Mid(pos+1); // also those with / - } - - pos = filename.ReverseFind(':'); - if ( pos > 0 ) - { - filename = filename.Mid(pos+1); // also removes the drive letter C: - } - - filename = CBotString("files\\") + filename; -} - - -// constructor of the class -// gets the filename as a parameter - -// execution -bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - CBotString mode; - - // accepts no parameters - if ( pVar == NULL ) return true; - - // must be a string - if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - - CBotString filename = pVar->GetValString(); - PrepareFilename(filename); //DR - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != NULL ) - { - // recovers the mode - mode = pVar->GetValString(); - if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; } - - // no third parameter, only two or one possible - if ( pVar->GetNext() != NULL ) { Exception = CBotErrOverParam; return false; } - } - - // save the file name - pVar = pThis->GetItem("filename"); - pVar->SetValString(filename); - - if ( ! mode.IsEmpty() ) - { - // open the called file - FILE* pFile = fopen( filename, mode ); - if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; } - - m_CompteurFileOpen ++; - - // save the handle of file - pVar = pThis->GetItem("handle"); - pVar->SetValInt((long)pFile); - } - - return true; -} - -// compilation -CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar) -{ - // accepts no parameters - if ( pVar == NULL ) return CBotTypResult( 0 ); - - // must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != NULL ) - { - // must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - // no third parameter - if ( pVar->GetNext() != NULL ) return CBotTypResult( CBotErrOverParam ); - } - - // le r�sultat est de type void (constructeur) - return CBotTypResult( 0 ); -} - - -// destructor of the class - -// execution -bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - // not open? no problem - if ( pVar->GetInit() != IS_DEF) return true; - - FILE* pFile= (FILE*)pVar->GetValInt(); - fclose(pFile); - m_CompteurFileOpen --; - - pVar->SetInit(IS_NAN); - - return true; -} - - -// FILE :: open method -// get the r / w mode as a parameter - -// execution -bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // there must be a parameter - if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; } - - // must be a string - if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - - // there may be a second parameter - if ( pVar->GetNext() != NULL ) - { - // in this case the first parameter is the file name - CBotString filename = pVar->GetValString(); - PrepareFilename(filename); //DR - - // saves the file name - CBotVar* pVar2 = pThis->GetItem("filename"); - pVar2->SetValString(filename); - - // next parameter is the mode - pVar = pVar -> GetNext(); - } - - CBotString mode = pVar->GetValString(); - if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; } - - // No third parameter - if ( pVar->GetNext() != NULL ) { Exception = CBotErrOverParam; return false; } - - // retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - // which must not be initialized - if ( pVar->GetInit() == IS_DEF) { Exception = CBotErrFileOpen; return false; } - - // contains filename - pVar = pThis->GetItem("filename"); - CBotString filename = pVar->GetValString(); - - PrepareFilename(filename); //DD! (if the name was assigned by h.filename = "..."; - - // open requsted file - FILE* pFile = fopen( filename, mode ); - if ( pFile == NULL ) //DR - { - pResult->SetValInt(false); //DR - return true; //DR - } - - m_CompteurFileOpen ++; - - // saves the handle of file - pVar = pThis->GetItem("handle"); - pVar->SetValInt((long)pFile); - - pResult->SetValInt(true); //DR - return true; -} - -// compilation -CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar) -{ - // there must be a parameter - if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam ); - - // must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != NULL ) - { - // must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // no third parameter - if ( pVar->GetNext() != NULL ) return CBotTypResult( CBotErrOverParam ); - } - - // the result is of type bool - return CBotTypResult(CBotTypBoolean); //DR -} - - -// FILE :: close method - -// execution -bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // it should not be any parameter - if ( pVar != NULL ) return CBotErrOverParam; - - // retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - if ( pVar->GetInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; } - - FILE* pFile= (FILE*)pVar->GetValInt(); - fclose(pFile); - m_CompteurFileOpen --; - - pVar->SetInit(IS_NAN); - - return true; -} - -// compilation -CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar) -{ - // it should not be any parameter - if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam ); - - // function returns a result "void" - return CBotTypResult( 0 ); -} - -// FILE :: writeln method - -// execution -bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // there must be a parameter - if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; } - - // must be a string - if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - - CBotString param = pVar->GetValString(); - - //retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - if ( pVar->GetInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; } - - FILE* pFile= (FILE*)pVar->GetValInt(); - - int res = fputs(param+CBotString("\n"), pFile); - - // on error throws an exception - if ( res < 0 ) { Exception = CBotErrWrite; return false; } - - return true; -} - -// compilation -CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar) -{ - // there must be a parameter - if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam ); - - // must be a string - if ( pVar->GetType() != CBotTypString ) return CBotTypResult( CBotErrBadString ); - - // no other parameter - if ( pVar->GetNext() != NULL ) return CBotTypResult( CBotErrOverParam ); - - // function returns "void" result - return CBotTypResult( 0 ); -} - -// FILE :: readln method - -// execution -bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // there shouldn't be any parameter - if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; } - - //retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - if ( pVar->GetInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; } - - FILE* pFile= (FILE*)pVar->GetValInt(); - - char chaine[2000]; - int i; - for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0; - - fgets(chaine, 1999, pFile); - - for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0; - - // on error throws an exception - if ( ferror(pFile) ) { Exception = CBotErrRead; return false; } - - pResult->SetValString( chaine ); - - return true; -} - -// compilation -CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar) -{ - // there shouldn't be any parameter - if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam ); - - // function return "string" result - return CBotTypResult( CBotTypString ); -} -// FILE :: readln method - - -// execution -bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - // there shouldn't be any parameter - if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; } - - // retrieves the element "handle" - pVar = pThis->GetItem("handle"); - - if ( pVar->GetInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; } - - FILE* pFile= (FILE*)pVar->GetValInt(); - - pResult->SetValInt( feof( pFile ) ); - - return true; -} - -// compilation -CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar) -{ - // there shouldn't be any parameter - if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam ); - - // function return boolean result - return CBotTypResult( CBotTypBoolean ); -} - - - - - -void InitClassFILE() -{ -// creates a class for file management -// the usage is as follows: -// file canal( "NomFichier.txt" ) -// canal.open( "r" ); // open reading -// s = canal.readln( ); // reads a line -// canal.close(); // closes the file - - // create class FILE - m_pClassFILE = new CBotClass("file", NULL); - // add the component ".filename" - m_pClassFILE->AddItem("filename", CBotTypString); - // add the component ".handle" - m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE); - - // define a constructor and destructor - m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct ); - m_pClassFILE->AddFunction("~file", rfdestruct, NULL ); - - // defined associated methods - m_pClassFILE->AddFunction("open", rfopen, cfopen ); - m_pClassFILE->AddFunction("close", rfclose, cfclose ); - m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite ); - m_pClassFILE->AddFunction("readln", rfread, cfread ); - m_pClassFILE->AddFunction("eof", rfeof, cfeof ); - - m_pFuncFile = new CBotProgram( ); - CBotStringArray ListFonctions; - m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions); - m_pFuncFile->SetIdent(-2); // restoreState as a special identifier for this function -} - diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 83b9fc9..fc15b26 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3603,199 +3603,6 @@ char* SkipNum(char *p) return p; } -//! Conversion of units -void CRobotMain::Convert() -{ - char* base = m_dialog->GetSceneName(); - int rank = m_dialog->GetSceneRank(); - - //TODO change line to string - char line[500]; - std::string tempLine; - - m_dialog->BuildSceneName(tempLine, base, rank); - strcpy(line, tempLine.c_str()); - FILE* file = fopen(line, "r"); - if (file == NULL) return; - - strcpy(line+strlen(line)-4, ".new"); - FILE* fileNew = fopen(line, "w"); - if (fileNew == NULL) return; - - char lineNew[500]; - char s[200]; - - while (fgets(line, 500, file) != NULL) - { - strcpy(lineNew, line); - - if (Cmd(line, "DeepView")) - { - char* p = strstr(line, "air="); - if (p != 0) - { - float value = OpFloat(line, "air", 500.0f); - value /= g_unit; - p[0] = 0; - p = SkipNum(p+4); - strcpy(lineNew, line); - strcat(lineNew, "air="); - sprintf(s, "%.2f", value); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - - p = strstr(line, "water="); - if (p != 0) - { - float value = OpFloat(line, "water", 100.0f); - value /= g_unit; - p[0] = 0; - p = SkipNum(p+6); - strcpy(lineNew, line); - strcat(lineNew, "water="); - sprintf(s, "%.2f", value); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - } - - if (Cmd(line, "TerrainGenerate")) - { - char* p = strstr(line, "vision="); - if (p != 0) - { - float value = OpFloat(line, "vision", 500.0f); - value /= g_unit; - p[0] = 0; - p = SkipNum(p+7); - strcpy(lineNew, line); - strcat(lineNew, "vision="); - sprintf(s, "%.2f", value); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - } - - if (Cmd(line, "CreateObject") || - Cmd(line, "CreateSpot")) - { - char* p = strstr(line, "pos="); - if (p != 0) - { - Math::Vector pos = OpPos(line, "pos"); - pos.x /= g_unit; - pos.y /= g_unit; - pos.z /= g_unit; - p[0] = 0; - p = SkipNum(p+4); - p = SkipNum(p+1); - strcpy(lineNew, line); - strcat(lineNew, "pos="); - sprintf(s, "%.2f", pos.x); - strcat(lineNew, s); - strcat(lineNew, ";"); - sprintf(s, "%.2f", pos.z); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - } - - if (Cmd(line, "EndMissionTake") || Cmd(line, "AudioChange")) - { - char* p = strstr(line, "pos="); - if (p != 0) - { - Math::Vector pos = OpPos(line, "pos"); - pos.x /= g_unit; - pos.y /= g_unit; - pos.z /= g_unit; - p[0] = 0; - p = SkipNum(p+4); - p = SkipNum(p+1); - strcpy(lineNew, line); - strcat(lineNew, "pos="); - sprintf(s, "%.2f", pos.x); - strcat(lineNew, s); - strcat(lineNew, ";"); - sprintf(s, "%.2f", pos.z); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - - p = strstr(line, "dist="); - if (p != 0) - { - float value = OpFloat(line, "dist", 32.0f); - value /= g_unit; - p[0] = 0; - p = SkipNum(p+5); - strcpy(lineNew, line); - strcat(lineNew, "dist="); - sprintf(s, "%.2f", value); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - } - - if (Cmd(line, "Camera")) - { - char* p = strstr(line, "pos="); - if (p != 0) - { - Math::Vector pos = OpPos(line, "pos"); - pos.x /= g_unit; - pos.y /= g_unit; - pos.z /= g_unit; - p[0] = 0; - p = SkipNum(p+4); - p = SkipNum(p+1); - strcpy(lineNew, line); - strcat(lineNew, "pos="); - sprintf(s, "%.2f", pos.x); - strcat(lineNew, s); - strcat(lineNew, ";"); - sprintf(s, "%.2f", pos.z); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - - p = strstr(line, "h="); - if (p != 0) - { - float value = OpFloat(line, "h", 32.0f); - value /= g_unit; - p[0] = 0; - p = SkipNum(p+2); - strcpy(lineNew, line); - strcat(lineNew, "h="); - sprintf(s, "%.2f", value); - strcat(lineNew, s); - strcat(lineNew, " "); - strcat(lineNew, p); - } - strcpy(line, lineNew); - } - - fputs(lineNew, fileNew); - } - - fclose(fileNew); - fclose(file); -} - //! Load the scene for the character void CRobotMain::ScenePerso() { diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 19e9e7d..73ddc35 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -392,7 +392,6 @@ protected: bool EventObject(const Event &event); void InitEye(); - void Convert(); void CreateScene(bool soluce, bool fixScene, bool resetObject); Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); -- cgit v1.2.3-1-g7c22 From 4a202a086fd5ca0f2d84bdb3bf7d1e6f7deb84c0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 6 Aug 2014 17:18:52 +0200 Subject: Fixed #314 --- src/graphics/engine/engine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d0b37a5..e4bf068 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -1965,10 +1965,10 @@ bool CEngine::IsWithinLODLimit(float distance, LODLevel lodLevel) } min *= m_size.x / 640.0f; - min *= m_objectDetail*2.0f; + min *= 1.0f+m_objectDetail*2.0f; max *= m_size.x / 640.0f; - max *= m_objectDetail*2.0f; + max *= 1.0f+m_objectDetail*2.0f; } return distance >= min && distance < max; -- cgit v1.2.3-1-g7c22 From ea0615ee05b0812f2bb5d7d8b970b3f83999a319 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Aug 2014 14:03:43 +0200 Subject: Fixed #315 --- src/ui/edit.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index e2df62b..24d02e9 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -373,23 +373,23 @@ bool CEdit::EventProcess(const Event &event) MoveChar(1, bControl, bShift); return true; } - if ( event.key.key == KEY(UP) ) + if ( event.key.key == KEY(UP) && m_bMulti ) { MoveLine(-1, bControl, bShift); return true; } - if ( event.key.key == KEY(DOWN) ) + if ( event.key.key == KEY(DOWN) && m_bMulti ) { MoveLine(1, bControl, bShift); return true; } - if ( event.key.key == KEY(PAGEUP) ) // PageUp ? + if ( event.key.key == KEY(PAGEUP) && m_bMulti ) // PageUp ? { MoveLine(-(m_lineVisible-1), bControl, bShift); return true; } - if ( event.key.key == KEY(PAGEDOWN) ) // PageDown ? + if ( event.key.key == KEY(PAGEDOWN) && m_bMulti ) // PageDown ? { MoveLine(m_lineVisible-1, bControl, bShift); return true; -- cgit v1.2.3-1-g7c22 From ac019c263d7b41742934a9dafd58ac2e6171109c Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 9 Aug 2014 22:45:07 +0200 Subject: Remove unnecessary delete checks (#318) --- src/CBot/CBotToken.cpp | 2 +- src/common/iman.cpp | 4 +--- src/common/singleton.h | 5 +---- src/sound/oalsound/alsound.cpp | 14 ++++---------- src/ui/interface.cpp | 7 ++----- 5 files changed, 9 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index 48033a3..17cdba1 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -105,7 +105,7 @@ void CBotToken::Free() const CBotToken& CBotToken::operator=(const CBotToken& src) { - if (m_next != NULL) delete(m_next); + delete m_next; m_next = NULL; m_prev = NULL; diff --git a/src/common/iman.cpp b/src/common/iman.cpp index 88fbb9b..edfa9c7 100644 --- a/src/common/iman.cpp +++ b/src/common/iman.cpp @@ -42,9 +42,7 @@ void CInstanceManager::Flush() { for (int i = 0; i < CLASS_MAX; i++) { - if (m_table[i].instances != nullptr) - delete[] m_table[i].instances; - + delete[] m_table[i].instances; m_table[i].instances = nullptr; } } diff --git a/src/common/singleton.h b/src/common/singleton.h index 841759d..bf5bc9d 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -62,10 +62,7 @@ public: static void ReplaceInstance(T* newInstance) { assert(newInstance != nullptr); - - if (m_instance != nullptr) - delete m_instance; - + delete m_instance; m_instance = newInstance; } #endif diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 8afbdd2..327bb6f 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -58,20 +58,14 @@ void ALSound::CleanUp() delete channel.second; } - if (m_currentMusic) - { - delete m_currentMusic; - } - + delete m_currentMusic; + for (auto item : m_oldMusic) { delete item.music; } - - if (m_previousMusic.music) - { - delete m_previousMusic.music; - } + + delete m_previousMusic.music; for (auto item : m_sounds) { diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index ab2c01b..4a0c221 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -49,11 +49,8 @@ void CInterface::Flush() { for (int i = 0; i < MAXCONTROL; i++) { - if (m_table[i] != nullptr) - { - delete m_table[i]; - m_table[i] = nullptr; - } + delete m_table[i]; + m_table[i] = nullptr; } } -- cgit v1.2.3-1-g7c22 From 9de086390bc925b6eb8cbfe332c1985e4b715d61 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 10 Aug 2014 17:51:47 +0200 Subject: Remove some more delete checks (#318) --- src/app/app.cpp | 21 ++++++--------------- src/ui/edit.cpp | 17 +++++------------ src/ui/list.cpp | 6 ++---- src/ui/window.cpp | 53 +++++++++++++++-------------------------------------- 4 files changed, 28 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/app/app.cpp b/src/app/app.cpp index 8b310c9..83a520a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -598,23 +598,14 @@ void CApplication::Destroy() { m_joystickEnabled = false; - if (m_robotMain != nullptr) - { - delete m_robotMain; - m_robotMain = nullptr; - } + delete m_robotMain; + m_robotMain = nullptr; - if (m_sound != nullptr) - { - delete m_sound; - m_sound = nullptr; - } + delete m_sound; + m_sound = nullptr; - if (m_modelManager != nullptr) - { - delete m_modelManager; - m_modelManager = nullptr; - } + delete m_modelManager; + m_modelManager = nullptr; if (m_engine != nullptr) { diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 24d02e9..4132896 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -115,21 +115,16 @@ CEdit::CEdit () : CControl () CEdit::~CEdit() { - int i; - FreeImage(); - for ( i=0 ; i Date: Sun, 10 Aug 2014 17:57:41 +0200 Subject: Fix task stopping checks in CBrain This possibly fixes some issues resulting from improperly stopping tasks (CTask::Abort() not called before deleting the task). Found while looking for instances of #318. --- src/object/brain.cpp | 161 ++++++++++++--------------------------------------- src/object/brain.h | 2 +- 2 files changed, 39 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 4bd8742..ca578ba 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -812,11 +812,11 @@ void CBrain::StopProgram() void CBrain::StopTask() { - if ( m_primaryTask != 0 ) + if (m_primaryTask != nullptr) { m_primaryTask->Abort(); delete m_primaryTask; // stops the current task - m_primaryTask = 0; + m_primaryTask = nullptr; } } @@ -900,16 +900,10 @@ void CBrain::StopEditScript(bool bCancel) Error CBrain::StartTaskTake() { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskTake(); + Error err = m_primaryTask->StartTaskTake(); UpdateInterface(); return err; } @@ -918,16 +912,10 @@ Error CBrain::StartTaskTake() Error CBrain::StartTaskManip(TaskManipOrder order, TaskManipArm arm) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskManip(order, arm); + Error err = m_primaryTask->StartTaskManip(order, arm); UpdateInterface(); return err; } @@ -936,16 +924,10 @@ Error CBrain::StartTaskManip(TaskManipOrder order, TaskManipArm arm) Error CBrain::StartTaskFlag(TaskFlagOrder order, int rank) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskFlag(order, rank); + Error err = m_primaryTask->StartTaskFlag(order, rank); UpdateInterface(); return err; } @@ -954,16 +936,10 @@ Error CBrain::StartTaskFlag(TaskFlagOrder order, int rank) Error CBrain::StartTaskBuild(ObjectType type) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskBuild(type); + Error err = m_primaryTask->StartTaskBuild(type); UpdateInterface(); return err; } @@ -972,16 +948,10 @@ Error CBrain::StartTaskBuild(ObjectType type) Error CBrain::StartTaskSearch() { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskSearch(); + Error err = m_primaryTask->StartTaskSearch(); UpdateInterface(); return err; } @@ -990,38 +960,26 @@ Error CBrain::StartTaskSearch() Error CBrain::StartTaskTerraform() { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskTerraform(); + Error err = m_primaryTask->StartTaskTerraform(); UpdateInterface(); return err; } // Change pencil. -Error CBrain::StartTaskPen(bool bDown, int color) +Error CBrain::StartTaskPen(bool down, int color) { - Error err; - m_physics->SetMotorSpeedX(0.0f); m_physics->SetMotorSpeedY(0.0f); m_physics->SetMotorSpeedZ(0.0f); - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskPen(bDown, color); + Error err = m_primaryTask->StartTaskPen(down, color); UpdateInterface(); return err; } @@ -1030,16 +988,10 @@ Error CBrain::StartTaskPen(bool bDown, int color) Error CBrain::StartTaskRecover() { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskRecover(); + Error err = m_primaryTask->StartTaskRecover(); UpdateInterface(); return err; } @@ -1048,16 +1000,10 @@ Error CBrain::StartTaskRecover() Error CBrain::StartTaskShield(TaskShieldMode mode) { - Error err; - - if ( m_secondaryTask != 0 ) - { - delete m_secondaryTask; // stops the current task - m_secondaryTask = 0; - } + StopTask(); m_secondaryTask = new CTaskManager(m_object); - err = m_secondaryTask->StartTaskShield(mode, 1000.0f); + Error err = m_secondaryTask->StartTaskShield(mode, 1000.0f); UpdateInterface(); return err; } @@ -1066,16 +1012,10 @@ Error CBrain::StartTaskShield(TaskShieldMode mode) Error CBrain::StartTaskFire(float delay) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskFire(delay); + Error err = m_primaryTask->StartTaskFire(delay); UpdateInterface(); return err; } @@ -1084,16 +1024,10 @@ Error CBrain::StartTaskFire(float delay) Error CBrain::StartTaskSpiderExplo() { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskSpiderExplo(); + Error err = m_primaryTask->StartTaskSpiderExplo(); UpdateInterface(); return err; } @@ -1102,16 +1036,10 @@ Error CBrain::StartTaskSpiderExplo() Error CBrain::StartTaskFireAnt(Math::Vector impact) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskFireAnt(impact); + Error err = m_primaryTask->StartTaskFireAnt(impact); UpdateInterface(); return err; } @@ -1120,16 +1048,10 @@ Error CBrain::StartTaskFireAnt(Math::Vector impact) Error CBrain::StartTaskGunGoal(float dirV, float dirH) { - Error err; - - if ( m_secondaryTask != 0 ) - { - delete m_secondaryTask; // stops the current task - m_secondaryTask = 0; - } + StopTask(); m_secondaryTask = new CTaskManager(m_object); - err = m_secondaryTask->StartTaskGunGoal(dirV, dirH); + Error err = m_secondaryTask->StartTaskGunGoal(dirV, dirH); UpdateInterface(); return err; } @@ -1138,16 +1060,10 @@ Error CBrain::StartTaskGunGoal(float dirV, float dirH) Error CBrain::StartTaskReset(Math::Vector goal, Math::Vector angle) { - Error err; - - if ( m_primaryTask != 0 ) - { - delete m_primaryTask; // stops the current task - m_primaryTask = 0; - } + StopTask(); m_primaryTask = new CTaskManager(m_object); - err = m_primaryTask->StartTaskReset(goal, angle); + Error err = m_primaryTask->StartTaskReset(goal, angle); UpdateInterface(); return err; } @@ -1156,30 +1072,29 @@ Error CBrain::StartTaskReset(Math::Vector goal, Math::Vector angle) Error CBrain::EndedTask() { - Error err; - - if ( m_secondaryTask != 0 ) // current task? + if (m_secondaryTask != nullptr) // current task? { - err = m_secondaryTask->IsEnded(); + Error err = m_secondaryTask->IsEnded(); if ( err != ERR_CONTINUE ) // job ended? { delete m_secondaryTask; - m_secondaryTask = 0; + m_secondaryTask = nullptr; UpdateInterface(); } } - if ( m_primaryTask != 0 ) // current task? + if (m_primaryTask != nullptr) // current task? { - err = m_primaryTask->IsEnded(); + Error err = m_primaryTask->IsEnded(); if ( err != ERR_CONTINUE ) // job ended? { delete m_primaryTask; - m_primaryTask = 0; + m_primaryTask = nullptr; UpdateInterface(); } return err; } + return ERR_STOP; } diff --git a/src/object/brain.h b/src/object/brain.h index a1f5da7..8a6b13e 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -128,7 +128,7 @@ public: Error StartTaskBuild(ObjectType type); Error StartTaskSearch(); Error StartTaskTerraform(); - Error StartTaskPen(bool bDown, int color); + Error StartTaskPen(bool down, int color); Error StartTaskRecover(); Error StartTaskShield(TaskShieldMode mode); Error StartTaskFire(float delay); -- cgit v1.2.3-1-g7c22 From 4bdfa0aa4ee3ad00429e8d68823532bdb2d72a97 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 18:18:30 +0200 Subject: Remove unused accessors from CDevice --- src/graphics/core/device.h | 40 +------- src/graphics/opengl/gldevice.cpp | 211 +-------------------------------------- src/graphics/opengl/gldevice.h | 112 +++++++++------------ 3 files changed, 49 insertions(+), 314 deletions(-) (limited to 'src') diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index a896104..476136e 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -258,26 +258,16 @@ public: //! Sets the transform matrix of given type virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0; - //! Returns the current transform matrix of given type - virtual const Math::Matrix& GetTransform(TransformType type) = 0; - //! Multiplies the current transform matrix of given type by given matrix - virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0; //! Sets the current material virtual void SetMaterial(const Material &material) = 0; - //! Returns the current material - virtual const Material& GetMaterial() = 0; //! Returns the maximum number of lights available virtual int GetMaxLightCount() = 0; //! Sets the light at given index virtual void SetLight(int index, const Light &light) = 0; - //! Returns the current light at given index - virtual const Light& GetLight(int index) = 0; //! Enables/disables the light at given index virtual void SetLightEnabled(int index, bool enabled) = 0; - //! Returns the current enable state of light at given index - virtual bool GetLightEnabled(int index) = 0; //! Creates a texture from image; the image can be safely removed after that virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) = 0; @@ -294,17 +284,11 @@ public: virtual void SetTexture(int index, const Texture &texture) = 0; //! Sets the texture image by ID at given texture stage virtual void SetTexture(int index, unsigned int textureId) = 0; - //! Returns the (multi)texture at given index - virtual Texture GetTexture(int index) = 0; //! Enables/disables the given texture stage virtual void SetTextureEnabled(int index, bool enabled) = 0; - //! Returns the current enable state of given texture stage - virtual bool GetTextureEnabled(int index) = 0; //! Sets the params for texture stage with given index virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms) = 0; - //! Returns the current params of texture stage with given index - virtual TextureStageParams GetTextureStageParams(int index) = 0; //! Sets only the texture wrap modes (for faster than thru stage params) virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0; @@ -348,61 +332,39 @@ public: //! Enables/disables the given render state virtual void SetRenderState(RenderState state, bool enabled) = 0; - //! Returns the current setting of given render state - virtual bool GetRenderState(RenderState state) = 0; //! Sets the function of depth test virtual void SetDepthTestFunc(CompFunc func) = 0; - //! Returns the current function of depth test - virtual CompFunc GetDepthTestFunc() = 0; //! Sets the depth bias (constant value added to Z-coords) virtual void SetDepthBias(float factor) = 0; - //! Returns the current depth bias - virtual float GetDepthBias() = 0; //! Sets the alpha test function and reference value virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0; - //! Returns the current alpha test function and reference value - virtual void GetAlphaTestFunc(CompFunc &func, float &refValue) = 0; //! Sets the blending functions for source and destination operations virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0; - //! Returns the current blending functions for source and destination operations - virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) = 0; //! Sets the clear color virtual void SetClearColor(const Color &color) = 0; - //! Returns the current clear color - virtual Color GetClearColor() = 0; //! Sets the global ambient color virtual void SetGlobalAmbient(const Color &color) = 0; - //! Returns the global ambient color - virtual Color GetGlobalAmbient() = 0; //! Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) = 0; - //! Returns the current fog parameters: mode, color, start distance, end distance and density (for exp models) - virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) = 0; //! Sets the current cull mode virtual void SetCullMode(CullMode mode) = 0; - //! Returns the current cull mode - virtual CullMode GetCullMode() = 0; //! Sets the shade model virtual void SetShadeModel(ShadeModel model) = 0; - //! Returns the current shade model - virtual ShadeModel GetShadeModel() = 0; //! Sets the current fill mode virtual void SetFillMode(FillMode mode) = 0; - //! Returns the current fill mode - virtual FillMode GetFillMode() = 0; //! Returns the pixels of the entire screen - virtual void* GetFrameBufferPixels()const = 0; + virtual void* GetFrameBufferPixels() const = 0; }; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index b42f29d..10eec90 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -290,11 +290,6 @@ void CGLDevice::SetUseVbo(bool vboAvailable) m_vboAvailable = vboAvailable; } -bool CGLDevice::GetUseVbo() -{ - return m_vboAvailable; -} - void CGLDevice::BeginScene() { Clear(); @@ -339,44 +334,6 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) } } -const Math::Matrix& CGLDevice::GetTransform(TransformType type) -{ - if (type == TRANSFORM_WORLD) - return m_worldMat; - else if (type == TRANSFORM_VIEW) - return m_viewMat; - else if (type == TRANSFORM_PROJECTION) - return m_projectionMat; - else - assert(false); - - return m_worldMat; // to avoid warning -} - -void CGLDevice::MultiplyTransform(TransformType type, const Math::Matrix &matrix) -{ - if (type == TRANSFORM_WORLD) - { - m_worldMat = Math::MultiplyMatrices(m_worldMat, matrix); - UpdateModelviewMatrix(); - } - else if (type == TRANSFORM_VIEW) - { - m_viewMat = Math::MultiplyMatrices(m_viewMat, matrix); - UpdateModelviewMatrix(); - } - else if (type == TRANSFORM_PROJECTION) - { - m_projectionMat = Math::MultiplyMatrices(m_projectionMat, matrix); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(m_projectionMat.Array()); - } - else - { - assert(false); - } -} - void CGLDevice::UpdateModelviewMatrix() { m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); @@ -402,11 +359,6 @@ void CGLDevice::SetMaterial(const Material &material) glMaterialfv(GL_FRONT, GL_SPECULAR, m_material.specular.Array()); } -const Material& CGLDevice::GetMaterial() -{ - return m_material; -} - int CGLDevice::GetMaxLightCount() { return m_lights.size(); @@ -482,14 +434,6 @@ void CGLDevice::UpdateLightPosition(int index) glPopMatrix(); } -const Light& CGLDevice::GetLight(int index) -{ - assert(index >= 0); - assert(index < static_cast( m_lights.size() )); - - return m_lights[index]; -} - void CGLDevice::SetLightEnabled(int index, bool enabled) { assert(index >= 0); @@ -503,14 +447,6 @@ void CGLDevice::SetLightEnabled(int index, bool enabled) glDisable(GL_LIGHT0 + index); } -bool CGLDevice::GetLightEnabled(int index) -{ - assert(index >= 0); - assert(index < static_cast( m_lights.size() )); - - return m_lightsEnabled[index]; -} - /** If image is invalid, returns invalid texture. Otherwise, returns pointer to new Texture struct. This struct must not be deleted in other way than through DeleteTexture() */ @@ -781,15 +717,6 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) UpdateTextureParams(index); } -/** - Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ -Texture CGLDevice::GetTexture(int index) -{ - assert(index >= 0 && index < static_cast( m_currentTextures.size() )); - - return m_currentTextures[index]; -} - void CGLDevice::SetTextureEnabled(int index, bool enabled) { assert(index >= 0 && index < static_cast( m_currentTextures.size() )); @@ -813,13 +740,6 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) glDisable(GL_TEXTURE_2D); } -bool CGLDevice::GetTextureEnabled(int index) -{ - assert(index >= 0 && index < static_cast( m_currentTextures.size() )); - - return m_texturesEnabled[index]; -} - /** Sets the texture parameters for the given texture stage. If the given texture was not set (bound) yet, nothing happens. @@ -1002,13 +922,6 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr else assert(false); } -TextureStageParams CGLDevice::GetTextureStageParams(int index) -{ - assert(index >= 0 && index < static_cast( m_currentTextures.size() )); - - return m_textureStageParams[index]; -} - GLenum TranslateGfxPrimitive(PrimitiveType type) { GLenum flag = 0; @@ -1529,30 +1442,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) glDisable(flag); } -bool CGLDevice::GetRenderState(RenderState state) -{ - if (state == RENDER_STATE_LIGHTING) - return m_lighting; - - GLenum flag = 0; - - switch (state) - { - case RENDER_STATE_DEPTH_WRITE: flag = GL_DEPTH_WRITEMASK; break; - case RENDER_STATE_BLENDING: flag = GL_BLEND; break; - case RENDER_STATE_FOG: flag = GL_FOG; break; - case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; - case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; - case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - default: assert(false); break; - } - - GLboolean result = GL_FALSE; - glGetBooleanv(flag, &result); - - return result == GL_TRUE; -} - CompFunc TranslateGLCompFunc(GLenum flag) { switch (flag) @@ -1592,39 +1481,16 @@ void CGLDevice::SetDepthTestFunc(CompFunc func) glDepthFunc(TranslateGfxCompFunc(func)); } -CompFunc CGLDevice::GetDepthTestFunc() -{ - GLint flag = 0; - glGetIntegerv(GL_DEPTH_FUNC, &flag); - return TranslateGLCompFunc(static_cast(flag)); -} - void CGLDevice::SetDepthBias(float factor) { glPolygonOffset(factor, 0.0f); } -float CGLDevice::GetDepthBias() -{ - GLfloat result = 0.0f; - glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &result); - return result; -} - void CGLDevice::SetAlphaTestFunc(CompFunc func, float refValue) { glAlphaFunc(TranslateGfxCompFunc(func), refValue); } -void CGLDevice::GetAlphaTestFunc(CompFunc &func, float &refValue) -{ - GLint flag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &flag); - func = TranslateGLCompFunc(static_cast(flag)); - - glGetFloatv(GL_ALPHA_TEST_REF, static_cast(&refValue)); -} - BlendFunc TranslateGLBlendFunc(GLenum flag) { switch (flag) @@ -1671,41 +1537,16 @@ void CGLDevice::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) glBlendFunc(TranslateGfxBlendFunc(srcBlend), TranslateGfxBlendFunc(dstBlend)); } -void CGLDevice::GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) -{ - GLint srcFlag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &srcFlag); - srcBlend = TranslateGLBlendFunc(static_cast(srcFlag)); - - GLint dstFlag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &dstFlag); - dstBlend = TranslateGLBlendFunc(static_cast(dstFlag)); -} - void CGLDevice::SetClearColor(const Color &color) { glClearColor(color.r, color.g, color.b, color.a); } -Color CGLDevice::GetClearColor() -{ - GLfloat color[4] = { 0.0f }; - glGetFloatv(GL_COLOR_CLEAR_VALUE, color); - return Color(color[0], color[1], color[2], color[3]); -} - void CGLDevice::SetGlobalAmbient(const Color &color) { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.Array()); } -Color CGLDevice::GetGlobalAmbient() -{ - GLfloat color[4] = { 0.0f }; - glGetFloatv(GL_LIGHT_MODEL_AMBIENT, color); - return Color(color[0], color[1], color[2], color[3]); -} - void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) { if (mode == FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); @@ -1719,23 +1560,6 @@ void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, floa glFogfv(GL_FOG_COLOR, color.Array()); } -void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) -{ - GLint flag = 0; - glGetIntegerv(GL_FOG_MODE, &flag); - if (flag == GL_LINEAR) mode = FOG_LINEAR; - else if (flag == GL_EXP) mode = FOG_EXP; - else if (flag == GL_EXP2) mode = FOG_EXP2; - else assert(false); - - glGetFloatv(GL_FOG_START, static_cast(&start)); - glGetFloatv(GL_FOG_END, static_cast(&end)); - glGetFloatv(GL_FOG_DENSITY, static_cast(&density)); - GLfloat col[4] = { 0.0f }; - glGetFloatv(GL_FOG_COLOR, col); - color = Color(col[0], col[1], col[2], col[3]); -} - void CGLDevice::SetCullMode(CullMode mode) { // Cull clockwise back faces, so front face is the opposite @@ -1745,16 +1569,6 @@ void CGLDevice::SetCullMode(CullMode mode) else assert(false); } -CullMode CGLDevice::GetCullMode() -{ - GLint flag = 0; - glGetIntegerv(GL_FRONT_FACE, &flag); - if (flag == GL_CW) return CULL_CCW; - else if (flag == GL_CCW) return CULL_CW; - else assert(false); - return CULL_CW; -} - void CGLDevice::SetShadeModel(ShadeModel model) { if (model == SHADE_FLAT) glShadeModel(GL_FLAT); @@ -1762,16 +1576,6 @@ void CGLDevice::SetShadeModel(ShadeModel model) else assert(false); } -ShadeModel CGLDevice::GetShadeModel() -{ - GLint flag = 0; - glGetIntegerv(GL_SHADE_MODEL, &flag); - if (flag == GL_FLAT) return SHADE_FLAT; - else if (flag == GL_SMOOTH) return SHADE_SMOOTH; - else assert(false); - return SHADE_FLAT; -} - void CGLDevice::SetFillMode(FillMode mode) { if (mode == FILL_POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); @@ -1780,21 +1584,10 @@ void CGLDevice::SetFillMode(FillMode mode) else assert(false); } -FillMode CGLDevice::GetFillMode() -{ - GLint flag = 0; - glGetIntegerv(GL_POLYGON_MODE, &flag); - if (flag == GL_POINT) return FILL_POINT; - else if (flag == GL_LINE) return FILL_LINES; - else if (flag == GL_FILL) return FILL_POLY; - else assert(false); - return FILL_POINT; -} - void* CGLDevice::GetFrameBufferPixels()const{ - GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y]; - + GLubyte* pixels = new GLubyte[4 * m_config.size.x * m_config.size.y]; + glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); unsigned int* p = static_cast ( static_cast(pixels) ); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 267ee73..ef9d1a6 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -92,103 +92,83 @@ public: CGLDevice(const GLDeviceConfig &config); virtual ~CGLDevice(); - virtual void DebugHook(); - virtual void DebugLights(); + virtual void DebugHook() override; + virtual void DebugLights() override; - virtual bool Create(); - virtual void Destroy(); + virtual bool Create() override; + virtual void Destroy() override; void ConfigChanged(const GLDeviceConfig &newConfig); void SetUseVbo(bool useVbo); - bool GetUseVbo(); - virtual void BeginScene(); - virtual void EndScene(); + virtual void BeginScene() override; + virtual void EndScene() override; - virtual void Clear(); + virtual void Clear() override; - virtual void SetTransform(TransformType type, const Math::Matrix &matrix); - virtual const Math::Matrix& GetTransform(TransformType type); - virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix); + virtual void SetTransform(TransformType type, const Math::Matrix &matrix) override; - virtual void SetMaterial(const Material &material); - virtual const Material& GetMaterial(); + virtual void SetMaterial(const Material &material) override; - virtual int GetMaxLightCount(); - virtual void SetLight(int index, const Light &light); - virtual const Light& GetLight(int index); - virtual void SetLightEnabled(int index, bool enabled); - virtual bool GetLightEnabled(int index); + virtual int GetMaxLightCount() override; + virtual void SetLight(int index, const Light &light) override; + virtual void SetLightEnabled(int index, bool enabled) override; - virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms); - virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms); - virtual void DestroyTexture(const Texture &texture); - virtual void DestroyAllTextures(); + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override; + virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms) override; + virtual void DestroyTexture(const Texture &texture) override; + virtual void DestroyAllTextures() override; - virtual int GetMaxTextureStageCount(); - virtual void SetTexture(int index, const Texture &texture); - virtual void SetTexture(int index, unsigned int textureId); - virtual Texture GetTexture(int index); - virtual void SetTextureEnabled(int index, bool enabled); - virtual bool GetTextureEnabled(int index); + virtual int GetMaxTextureStageCount() override; + virtual void SetTexture(int index, const Texture &texture) override; + virtual void SetTexture(int index, unsigned int textureId) override; + virtual void SetTextureEnabled(int index, bool enabled) override; - virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms); - virtual TextureStageParams GetTextureStageParams(int index); + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; - virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); + virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, - Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, - Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); - virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; + virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) override; - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); - virtual void DrawStaticBuffer(unsigned int bufferId); - virtual void DestroyStaticBuffer(unsigned int bufferId); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override; + virtual void DrawStaticBuffer(unsigned int bufferId) override; + virtual void DestroyStaticBuffer(unsigned int bufferId) override; - virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override; - virtual void SetRenderState(RenderState state, bool enabled); - virtual bool GetRenderState(RenderState state); + virtual void SetRenderState(RenderState state, bool enabled) override; - virtual void SetDepthTestFunc(CompFunc func); - virtual CompFunc GetDepthTestFunc(); + virtual void SetDepthTestFunc(CompFunc func) override; - virtual void SetDepthBias(float factor); - virtual float GetDepthBias(); + virtual void SetDepthBias(float factor) override; - virtual void SetAlphaTestFunc(CompFunc func, float refValue); - virtual void GetAlphaTestFunc(CompFunc &func, float &refValue); + virtual void SetAlphaTestFunc(CompFunc func, float refValue) override; - virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend); - virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend); + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override; - virtual void SetClearColor(const Color &color); - virtual Color GetClearColor(); + virtual void SetClearColor(const Color &color) override; - virtual void SetGlobalAmbient(const Color &color); - virtual Color GetGlobalAmbient(); + virtual void SetGlobalAmbient(const Color &color) override; - virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density); - virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density); + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override; - virtual void SetCullMode(CullMode mode); - virtual CullMode GetCullMode(); + virtual void SetCullMode(CullMode mode) override; - virtual void SetShadeModel(ShadeModel model); - virtual ShadeModel GetShadeModel(); + virtual void SetShadeModel(ShadeModel model) override; - virtual void SetFillMode(FillMode mode) ; - virtual FillMode GetFillMode(); + virtual void SetFillMode(FillMode mode) override; - virtual void* GetFrameBufferPixels()const; + virtual void* GetFrameBufferPixels() const override; private: //! Updates internal modelview matrix -- cgit v1.2.3-1-g7c22 From 74312b0405d6fb5ed75c675ceed471e1e5086f00 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 20:03:56 +0200 Subject: Better CMake organization and unit test cleanups * created a static library containing most source modules to avoid compiling source modules twice in code and unit tests * moved profile_test to main unit tests executable * removed image_test and edit_test as not really useful --- src/CMakeLists.txt | 339 ++++++++++++++++++++++++++----------------------- src/common/profile.cpp | 26 ++-- src/common/profile.h | 7 + 3 files changed, 200 insertions(+), 172 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12171f3..fbbaa37 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,178 +59,197 @@ if(PLATFORM_WINDOWS) endif() # Source files -set(SOURCES -app/app.cpp -app/gamedata.cpp -app/main.cpp -app/pausemanager.cpp -app/system.cpp -app/${SYSTEM_CPP_MODULE} -app/system_other.cpp -common/event.cpp -common/image.cpp -common/iman.cpp -common/logger.cpp -common/misc.cpp -common/profile.cpp -common/restext.cpp -common/stringutils.cpp -graphics/core/color.cpp -graphics/engine/camera.cpp -graphics/engine/cloud.cpp -graphics/engine/engine.cpp -graphics/engine/lightman.cpp -graphics/engine/lightning.cpp -graphics/engine/modelfile.cpp -graphics/engine/modelmanager.cpp -graphics/engine/particle.cpp -graphics/engine/planet.cpp -graphics/engine/pyro.cpp -graphics/engine/terrain.cpp -graphics/engine/text.cpp -graphics/engine/water.cpp -graphics/opengl/gldevice.cpp -object/auto/auto.cpp -object/auto/autobase.cpp -object/auto/autoconvert.cpp -object/auto/autoderrick.cpp -object/auto/autodestroyer.cpp -object/auto/autoegg.cpp -object/auto/autoenergy.cpp -object/auto/autofactory.cpp -object/auto/autoflag.cpp -object/auto/autohuston.cpp -object/auto/autoinfo.cpp -object/auto/autojostle.cpp -object/auto/autokid.cpp -object/auto/autolabo.cpp -object/auto/automush.cpp -object/auto/autonest.cpp -object/auto/autonuclear.cpp -object/auto/autopara.cpp -object/auto/autoportico.cpp -object/auto/autoradar.cpp -object/auto/autorepair.cpp -object/auto/autoresearch.cpp -object/auto/autoroot.cpp -object/auto/autosafe.cpp -object/auto/autostation.cpp -object/auto/autotower.cpp -object/brain.cpp -object/mainmovie.cpp -object/motion/motion.cpp -object/motion/motionant.cpp -object/motion/motionbee.cpp -object/motion/motiondummy.cpp -object/motion/motionhuman.cpp -object/motion/motionmother.cpp -object/motion/motionspider.cpp -object/motion/motiontoto.cpp -object/motion/motionvehicle.cpp -object/motion/motionworm.cpp -object/object.cpp -object/robotmain.cpp -object/objman.cpp -object/task/task.cpp -object/task/taskadvance.cpp -object/task/taskbuild.cpp -object/task/taskfire.cpp -object/task/taskfireant.cpp -object/task/taskflag.cpp -object/task/taskgoto.cpp -object/task/taskgungoal.cpp -object/task/taskinfo.cpp -object/task/taskmanager.cpp -object/task/taskmanip.cpp -object/task/taskpen.cpp -object/task/taskrecover.cpp -object/task/taskreset.cpp -object/task/tasksearch.cpp -object/task/taskshield.cpp -object/task/taskspiderexplo.cpp -object/task/tasktake.cpp -object/task/taskterraform.cpp -object/task/taskturn.cpp -object/task/taskwait.cpp -physics/physics.cpp -script/cbottoken.cpp -script/cmdtoken.cpp -script/script.cpp -sound/sound.cpp -ui/button.cpp -ui/check.cpp -ui/color.cpp -ui/compass.cpp -ui/control.cpp -ui/displayinfo.cpp -ui/displaytext.cpp -ui/edit.cpp -ui/editvalue.cpp -ui/gauge.cpp -ui/group.cpp -ui/image.cpp -ui/interface.cpp -ui/key.cpp -ui/label.cpp -ui/list.cpp -ui/maindialog.cpp -ui/mainmap.cpp -ui/mainshort.cpp -ui/map.cpp -ui/scroll.cpp -ui/shortcut.cpp -ui/slider.cpp -ui/studio.cpp -ui/target.cpp -ui/window.cpp -${OPENAL_SRC} -${RES_FILES} +set(BASE_SOURCES + app/app.cpp + app/gamedata.cpp + app/pausemanager.cpp + app/system.cpp + app/${SYSTEM_CPP_MODULE} + app/system_other.cpp + common/event.cpp + common/image.cpp + common/iman.cpp + common/logger.cpp + common/misc.cpp + common/profile.cpp + common/restext.cpp + common/stringutils.cpp + graphics/core/color.cpp + graphics/engine/camera.cpp + graphics/engine/cloud.cpp + graphics/engine/engine.cpp + graphics/engine/lightman.cpp + graphics/engine/lightning.cpp + graphics/engine/modelfile.cpp + graphics/engine/modelmanager.cpp + graphics/engine/particle.cpp + graphics/engine/planet.cpp + graphics/engine/pyro.cpp + graphics/engine/terrain.cpp + graphics/engine/text.cpp + graphics/engine/water.cpp + graphics/opengl/gldevice.cpp + object/auto/auto.cpp + object/auto/autobase.cpp + object/auto/autoconvert.cpp + object/auto/autoderrick.cpp + object/auto/autodestroyer.cpp + object/auto/autoegg.cpp + object/auto/autoenergy.cpp + object/auto/autofactory.cpp + object/auto/autoflag.cpp + object/auto/autohuston.cpp + object/auto/autoinfo.cpp + object/auto/autojostle.cpp + object/auto/autokid.cpp + object/auto/autolabo.cpp + object/auto/automush.cpp + object/auto/autonest.cpp + object/auto/autonuclear.cpp + object/auto/autopara.cpp + object/auto/autoportico.cpp + object/auto/autoradar.cpp + object/auto/autorepair.cpp + object/auto/autoresearch.cpp + object/auto/autoroot.cpp + object/auto/autosafe.cpp + object/auto/autostation.cpp + object/auto/autotower.cpp + object/brain.cpp + object/mainmovie.cpp + object/motion/motion.cpp + object/motion/motionant.cpp + object/motion/motionbee.cpp + object/motion/motiondummy.cpp + object/motion/motionhuman.cpp + object/motion/motionmother.cpp + object/motion/motionspider.cpp + object/motion/motiontoto.cpp + object/motion/motionvehicle.cpp + object/motion/motionworm.cpp + object/object.cpp + object/robotmain.cpp + object/objman.cpp + object/task/task.cpp + object/task/taskadvance.cpp + object/task/taskbuild.cpp + object/task/taskfire.cpp + object/task/taskfireant.cpp + object/task/taskflag.cpp + object/task/taskgoto.cpp + object/task/taskgungoal.cpp + object/task/taskinfo.cpp + object/task/taskmanager.cpp + object/task/taskmanip.cpp + object/task/taskpen.cpp + object/task/taskrecover.cpp + object/task/taskreset.cpp + object/task/tasksearch.cpp + object/task/taskshield.cpp + object/task/taskspiderexplo.cpp + object/task/tasktake.cpp + object/task/taskterraform.cpp + object/task/taskturn.cpp + object/task/taskwait.cpp + physics/physics.cpp + script/cbottoken.cpp + script/cmdtoken.cpp + script/script.cpp + sound/sound.cpp + ui/button.cpp + ui/check.cpp + ui/color.cpp + ui/compass.cpp + ui/control.cpp + ui/displayinfo.cpp + ui/displaytext.cpp + ui/edit.cpp + ui/editvalue.cpp + ui/gauge.cpp + ui/group.cpp + ui/image.cpp + ui/interface.cpp + ui/key.cpp + ui/label.cpp + ui/list.cpp + ui/maindialog.cpp + ui/mainmap.cpp + ui/mainshort.cpp + ui/map.cpp + ui/scroll.cpp + ui/shortcut.cpp + ui/slider.cpp + ui/studio.cpp + ui/target.cpp + ui/window.cpp + ${OPENAL_SRC} + ${RES_FILES} +) + +set(MAIN_SOURCES + app/main.cpp ) +# Libraries set(LIBS -CBot -clipboard -localename -${SDL_LIBRARY} -${SDLIMAGE_LIBRARY} -${SDLTTF_LIBRARY} -${OPENGL_LIBRARY} -${PNG_LIBRARIES} -${GLEW_LIBRARY} -${Boost_LIBRARIES} -${LIBSNDFILE_LIBRARY} -${OPTIONAL_LIBS} -${PLATFORM_LIBS} + CBot + clipboard + localename + ${SDL_LIBRARY} + ${SDLIMAGE_LIBRARY} + ${SDLTTF_LIBRARY} + ${OPENGL_LIBRARY} + ${PNG_LIBRARIES} + ${GLEW_LIBRARY} + ${Boost_LIBRARIES} + ${LIBSNDFILE_LIBRARY} + ${OPTIONAL_LIBS} + ${PLATFORM_LIBS} +) + +set(COLOBOT_LIBS ${LIBS} PARENT_SCOPE) + + +# Includes +set(LOCAL_INCLUDES + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_BINARY_DIR} ) -# Local -include_directories( -. -.. -${CMAKE_CURRENT_BINARY_DIR} +set(SYSTEM_INCLUDES + ${SDL_INCLUDE_DIR} + ${SDLIMAGE_INCLUDE_DIR} + ${SDLTTF_INCLUDE_DIR} + ${PNG_INCLUDE_DIRS} + ${GLEW_INCLUDE_PATH} + ${Boost_INCLUDE_DIRS} + ${LIBSNDFILE_INCLUDE_DIR} + ${LOCALENAME_INCLUDE_DIR} + ${OPTIONAL_INCLUDE_DIRS} + ${CLIPBOARD_INCLUDE_DIR} ) -# System -include_directories( -SYSTEM -${SDL_INCLUDE_DIR} -${SDLIMAGE_INCLUDE_DIR} -${SDLTTF_INCLUDE_DIR} -${PNG_INCLUDE_DIRS} -${GLEW_INCLUDE_PATH} -${Boost_INCLUDE_DIRS} -${LIBSNDFILE_INCLUDE_DIR} -${LOCALENAME_INCLUDE_DIR} -${OPTIONAL_INCLUDE_DIRS} -${CLIPBOARD_INCLUDE_DIR} +set(COLOBOT_LOCAL_INCLUDES ${LOCAL_INCLUDES} PARENT_SCOPE) +set(COLOBOT_SYSTEM_INCLUDES ${SYSTEM_INCLUDES} PARENT_SCOPE) + +include_directories(${LOCAL_INCLUDES}) +include_directories(SYSTEM ${SYSTEM_INCLUDES}) + + +# Link directories +link_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/CBot ) -link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) -add_executable(colobot ${SOURCES}) +# Targets + +add_library(colobotbase STATIC ${BASE_SOURCES}) -target_link_libraries(colobot ${LIBS}) +add_executable(colobot ${MAIN_SOURCES}) +target_link_libraries(colobot colobotbase ${LIBS}) install(TARGETS colobot RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) if(NOT CBOT_STATIC) diff --git a/src/common/profile.cpp b/src/common/profile.cpp index ee3e873..a63a772 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -31,8 +31,9 @@ template<> CProfile* CSingleton::m_instance = nullptr; namespace bp = boost::property_tree; -CProfile::CProfile() : - m_profileNeedSave(false) +CProfile::CProfile() + : m_profileNeedSave(false) + , m_useLocalDirectory(false) { } @@ -42,16 +43,21 @@ CProfile::~CProfile() SaveCurrentDirectory(); } +void CProfile::SetUseLocalDirectory(bool useLocalDirectory) +{ + m_useLocalDirectory = useLocalDirectory; +} + +std::string CProfile::GetIniFileLocation() +{ + return m_useLocalDirectory ? "colobot.ini" : GetSystemUtils()->GetProfileFileLocation(); +} bool CProfile::InitCurrentDirectory() { try { - #if DEV_BUILD - bp::ini_parser::read_ini("colobot.ini", m_propertyTree); - #else - bp::ini_parser::read_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); - #endif + bp::ini_parser::read_ini(GetIniFileLocation(), m_propertyTree); } catch (std::exception & e) { @@ -67,11 +73,7 @@ bool CProfile::SaveCurrentDirectory() { try { - #if DEV_BUILD - bp::ini_parser::write_ini("colobot.ini", m_propertyTree); - #else - bp::ini_parser::write_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); - #endif + bp::ini_parser::write_ini(GetIniFileLocation(), m_propertyTree); } catch (std::exception & e) { diff --git a/src/common/profile.h b/src/common/profile.h index f084ece..52f9f15 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -45,6 +45,9 @@ public: CProfile(); virtual ~CProfile(); + /** Set flag to force using ini file from local directory */ + void SetUseLocalDirectory(bool useLocalDirectory); + /** Loads colobot.ini from current directory * \return return true on success */ @@ -129,10 +132,14 @@ public: */ bool CopyFileToTemp(std::string filename); +private: + std::string GetIniFileLocation(); + private: boost::property_tree::ptree m_propertyTree; bool m_profileNeedSave; std::string m_userDirectory; + bool m_useLocalDirectory; }; //! Global function to get profile instance -- cgit v1.2.3-1-g7c22 From e4d52d9afbf6aeb090b225cc4852936dd3be5017 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 21:24:33 +0200 Subject: CProfile refactoring --- src/app/app.cpp | 10 +-- src/common/profile.cpp | 38 ++++++------ src/common/profile.h | 126 +++++++++++++++++++------------------- src/object/robotmain.cpp | 64 +++++++++---------- src/ui/maindialog.cpp | 156 +++++++++++++++++++++++------------------------ 5 files changed, 197 insertions(+), 197 deletions(-) (limited to 'src') diff --git a/src/app/app.cpp b/src/app/app.cpp index 83a520a..42ebd39 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -386,14 +386,14 @@ bool CApplication::Create() GetLogger()->Info("Creating CApplication\n"); - if (!GetProfile().InitCurrentDirectory()) + if (!GetProfile().Init()) { GetLogger()->Warn("Config not found. Default values will be used!\n"); defaultValues = true; } else { - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Data", path)) + if (!m_customDataPath && GetProfile().GetStringProperty("Resources", "Data", path)) m_dataPath = path; } @@ -411,7 +411,7 @@ bool CApplication::Create() m_gameData->SetDataDir(std::string(m_dataPath)); m_gameData->Init(); - if (GetProfile().GetLocalProfileString("Language", "Lang", path)) { + if (GetProfile().GetStringProperty("Language", "Lang", path)) { Language language; if (ParseLanguage(path, language)) { m_language = language; @@ -472,7 +472,7 @@ bool CApplication::Create() // load settings from profile int iValue; - if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Resolution", iValue) ) { std::vector modes; GetVideoResolutionList(modes, true, true); @@ -480,7 +480,7 @@ bool CApplication::Create() m_deviceConfig.size = modes.at(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Fullscreen", iValue) ) { m_deviceConfig.fullScreen = (iValue == 1); } diff --git a/src/common/profile.cpp b/src/common/profile.cpp index a63a772..79d7152 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -17,10 +17,10 @@ #include "common/profile.h" -#include "common/logger.h" - #include "app/system.h" +#include "common/logger.h" + #include #include #include @@ -33,27 +33,27 @@ namespace bp = boost::property_tree; CProfile::CProfile() : m_profileNeedSave(false) - , m_useLocalDirectory(false) + , m_useCurrentDirectory(false) { } CProfile::~CProfile() { - SaveCurrentDirectory(); + Save(); } -void CProfile::SetUseLocalDirectory(bool useLocalDirectory) +void CProfile::SetUseCurrentDirectory(bool useCurrentDirectory) { - m_useLocalDirectory = useLocalDirectory; + m_useCurrentDirectory = useCurrentDirectory; } std::string CProfile::GetIniFileLocation() { - return m_useLocalDirectory ? "colobot.ini" : GetSystemUtils()->GetProfileFileLocation(); + return m_useCurrentDirectory ? "colobot.ini" : GetSystemUtils()->GetProfileFileLocation(); } -bool CProfile::InitCurrentDirectory() +bool CProfile::Init() { try { @@ -67,7 +67,7 @@ bool CProfile::InitCurrentDirectory() return true; } -bool CProfile::SaveCurrentDirectory() +bool CProfile::Save() { if (m_profileNeedSave) { @@ -84,7 +84,7 @@ bool CProfile::SaveCurrentDirectory() return true; } -bool CProfile::SetLocalProfileString(std::string section, std::string key, std::string value) +bool CProfile::SetStringProperty(std::string section, std::string key, std::string value) { try { @@ -100,7 +100,7 @@ bool CProfile::SetLocalProfileString(std::string section, std::string key, std:: } -bool CProfile::GetLocalProfileString(std::string section, std::string key, std::string &buffer) +bool CProfile::GetStringProperty(std::string section, std::string key, std::string &buffer) { try { @@ -115,7 +115,7 @@ bool CProfile::GetLocalProfileString(std::string section, std::string key, std:: } -bool CProfile::SetLocalProfileInt(std::string section, std::string key, int value) +bool CProfile::SetIntProperty(std::string section, std::string key, int value) { try { @@ -131,7 +131,7 @@ bool CProfile::SetLocalProfileInt(std::string section, std::string key, int valu } -bool CProfile::GetLocalProfileInt(std::string section, std::string key, int &value) +bool CProfile::GetIntProperty(std::string section, std::string key, int &value) { try { @@ -146,7 +146,7 @@ bool CProfile::GetLocalProfileInt(std::string section, std::string key, int &val } -bool CProfile::SetLocalProfileFloat(std::string section, std::string key, float value) +bool CProfile::SetFloatProperty(std::string section, std::string key, float value) { try { @@ -162,7 +162,7 @@ bool CProfile::SetLocalProfileFloat(std::string section, std::string key, float } -bool CProfile::GetLocalProfileFloat(std::string section, std::string key, float &value) +bool CProfile::GetFloatProperty(std::string section, std::string key, float &value) { try { @@ -177,7 +177,7 @@ bool CProfile::GetLocalProfileFloat(std::string section, std::string key, float } -std::vector< std::string > CProfile::GetLocalProfileSection(std::string section, std::string key) +std::vector< std::string > CProfile::GetSection(std::string section, std::string key) { std::vector< std::string > ret_list; boost::regex re(key + "[0-9]*"); //we want to match all key followed by any number @@ -207,13 +207,13 @@ void CProfile::SetUserDir(std::string dir) } -std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir) +std::string CProfile::GetUserBasedPath(std::string dir, std::string defaultDir) { std::string path = dir; boost::replace_all(path, "\\", "/"); if (dir.find("/") == std::string::npos) { - path = default_dir + "/" + dir; + path = defaultDir + "/" + dir; } if (m_userDirectory.length() > 0) @@ -222,7 +222,7 @@ std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir) } else { - boost::replace_all(path, "%user%", default_dir); + boost::replace_all(path, "%user%", defaultDir); } return fs::path(path).make_preferred().string(); diff --git a/src/common/profile.h b/src/common/profile.h index 52f9f15..ad0458e 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -45,91 +45,91 @@ public: CProfile(); virtual ~CProfile(); - /** Set flag to force using ini file from local directory */ - void SetUseLocalDirectory(bool useLocalDirectory); + /** Set flag to force using ini file from current directory */ + void SetUseCurrentDirectory(bool useCurrentDirectory); /** Loads colobot.ini from current directory - * \return return true on success - */ - bool InitCurrentDirectory(); + * \return return true on success + */ + bool Init(); /** Saves colobot.ini to current directory - * \return return true on success - */ - bool SaveCurrentDirectory(); + * \return return true on success + */ + bool Save(); /** Sets string value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileString(std::string section, std::string key, std::string value); + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetStringProperty(std::string section, std::string key, std::string value); /** Gets string value in section under specified key - * \param section - * \param key - * \param buffer - * \return return true on success - */ - bool GetLocalProfileString(std::string section, std::string key, std::string& buffer); + * \param section + * \param key + * \param buffer + * \return return true on success + */ + bool GetStringProperty(std::string section, std::string key, std::string& buffer); /** Sets int value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileInt(std::string section, std::string key, int value); + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetIntProperty(std::string section, std::string key, int value); /** Gets int value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool GetLocalProfileInt(std::string section, std::string key, int &value); + * \param section + * \param key + * \param value + * \return return true on success + */ + bool GetIntProperty(std::string section, std::string key, int &value); /** Sets float value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileFloat(std::string section, std::string key, float value); + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetFloatProperty(std::string section, std::string key, float value); /** Gets float value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool GetLocalProfileFloat(std::string section, std::string key, float &value); + * \param section + * \param key + * \param value + * \return return true on success + */ + bool GetFloatProperty(std::string section, std::string key, float &value); /** Gets all values in section under specified key - * \param section - * \param key - * \return vector of values - */ - std::vector< std::string > GetLocalProfileSection(std::string section, std::string key); + * \param section + * \param key + * \return vector of values + */ + std::vector< std::string > GetSection(std::string section, std::string key); /** Sets current user directory - * \param dir - */ + * \param dir + */ void SetUserDir(std::string dir); /** Returns path based on current user. Replaces %user% in path with current user dir or - * uses default_dir param if no user dir is specified - * \param dir - * \param default_dir - * \return path - */ - std::string GetUserBasedPath(std::string dir, std::string default_dir); - - /** opy a file into the temporary folder. - * \param filename - * \return true on success - */ + * uses default_dir param if no user dir is specified + * \param dir + * \param default_dir + * \return path + */ + std::string GetUserBasedPath(std::string dir, std::string defaultDir); + + /** Copy a file into the temporary folder. + * \param filename + * \return true on success + */ bool CopyFileToTemp(std::string filename); private: @@ -139,7 +139,7 @@ private: boost::property_tree::ptree m_propertyTree; bool m_profileNeedSave; std::string m_userDirectory; - bool m_useLocalDirectory; + bool m_useCurrentDirectory; }; //! Global function to get profile instance diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index fc15b26..d33ea27 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -721,11 +721,11 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) if (loadProfile) { - if (GetProfile().GetLocalProfileFloat("Edit", "FontSize", fValue)) m_fontSize = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; + if (GetProfile().GetFloatProperty("Edit", "FontSize", fValue)) m_fontSize = fValue; + if (GetProfile().GetFloatProperty("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; + if (GetProfile().GetFloatProperty("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; + if (GetProfile().GetFloatProperty("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; + if (GetProfile().GetFloatProperty("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; } m_IOPublic = false; @@ -735,11 +735,11 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) if (loadProfile) { - if (GetProfile().GetLocalProfileInt ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IODimX", fValue)) m_IODim.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IODimY", fValue)) m_IODim.y = fValue; + if (GetProfile().GetIntProperty ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; + if (GetProfile().GetFloatProperty("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; + if (GetProfile().GetFloatProperty("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; + if (GetProfile().GetFloatProperty("Edit", "IODimX", fValue)) m_IODim.x = fValue; + if (GetProfile().GetFloatProperty("Edit", "IODimY", fValue)) m_IODim.y = fValue; } m_short->FlushShortcuts(); @@ -757,7 +757,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) g_unit = UNIT; m_gamerName = ""; - if (loadProfile) GetProfile().GetLocalProfileString("Gamer", "LastName", m_gamerName); + if (loadProfile) GetProfile().GetStringProperty("Gamer", "LastName", m_gamerName); SetGlobalGamerName(m_gamerName); ReadFreeParam(); if (loadProfile) m_dialog->SetupRecall(); @@ -966,18 +966,18 @@ void CRobotMain::CreateIni() { m_dialog->SetupMemorize(); - GetProfile().SetLocalProfileFloat("Edit", "FontSize", m_fontSize); - GetProfile().SetLocalProfileFloat("Edit", "WindowPosX", m_windowPos.x); - GetProfile().SetLocalProfileFloat("Edit", "WindowPosY", m_windowPos.y); - GetProfile().SetLocalProfileFloat("Edit", "WindowDimX", m_windowDim.x); - GetProfile().SetLocalProfileFloat("Edit", "WindowDimY", m_windowDim.y); - GetProfile().SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); - GetProfile().SetLocalProfileFloat("Edit", "IOPosX", m_IOPos.x); - GetProfile().SetLocalProfileFloat("Edit", "IOPosY", m_IOPos.y); - GetProfile().SetLocalProfileFloat("Edit", "IODimX", m_IODim.x); - GetProfile().SetLocalProfileFloat("Edit", "IODimY", m_IODim.y); + GetProfile().SetFloatProperty("Edit", "FontSize", m_fontSize); + GetProfile().SetFloatProperty("Edit", "WindowPosX", m_windowPos.x); + GetProfile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y); + GetProfile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x); + GetProfile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y); + GetProfile().SetIntProperty("Edit", "IOPublic", m_IOPublic); + GetProfile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x); + GetProfile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y); + GetProfile().SetFloatProperty("Edit", "IODimX", m_IODim.x); + GetProfile().SetFloatProperty("Edit", "IODimY", m_IODim.y); - GetProfile().SaveCurrentDirectory(); + GetProfile().Save(); } void CRobotMain::SetDefaultInputBindings() @@ -2258,7 +2258,7 @@ float CRobotMain::GetGameTime() void CRobotMain::SetFontSize(float size) { m_fontSize = size; - GetProfile().SetLocalProfileFloat("Edit", "FontSize", m_fontSize); + GetProfile().SetFloatProperty("Edit", "FontSize", m_fontSize); } float CRobotMain::GetFontSize() @@ -2270,8 +2270,8 @@ float CRobotMain::GetFontSize() void CRobotMain::SetWindowPos(Math::Point pos) { m_windowPos = pos; - GetProfile().SetLocalProfileFloat("Edit", "WindowPosX", m_windowPos.x); - GetProfile().SetLocalProfileFloat("Edit", "WindowPosY", m_windowPos.y); + GetProfile().SetFloatProperty("Edit", "WindowPosX", m_windowPos.x); + GetProfile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y); } Math::Point CRobotMain::GetWindowPos() @@ -2282,8 +2282,8 @@ Math::Point CRobotMain::GetWindowPos() void CRobotMain::SetWindowDim(Math::Point dim) { m_windowDim = dim; - GetProfile().SetLocalProfileFloat("Edit", "WindowDimX", m_windowDim.x); - GetProfile().SetLocalProfileFloat("Edit", "WindowDimY", m_windowDim.y); + GetProfile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x); + GetProfile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y); } Math::Point CRobotMain::GetWindowDim() @@ -2296,7 +2296,7 @@ Math::Point CRobotMain::GetWindowDim() void CRobotMain::SetIOPublic(bool mode) { m_IOPublic = mode; - GetProfile().SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); + GetProfile().SetIntProperty("Edit", "IOPublic", m_IOPublic); } bool CRobotMain::GetIOPublic() @@ -2307,8 +2307,8 @@ bool CRobotMain::GetIOPublic() void CRobotMain::SetIOPos(Math::Point pos) { m_IOPos = pos; - GetProfile().SetLocalProfileFloat("Edit", "IOPosX", m_IOPos.x); - GetProfile().SetLocalProfileFloat("Edit", "IOPosY", m_IOPos.y); + GetProfile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x); + GetProfile().SetFloatProperty("Edit", "IOPosY", m_IOPos.y); } Math::Point CRobotMain::GetIOPos() @@ -2319,8 +2319,8 @@ Math::Point CRobotMain::GetIOPos() void CRobotMain::SetIODim(Math::Point dim) { m_IODim = dim; - GetProfile().SetLocalProfileFloat("Edit", "IODimX", m_IODim.x); - GetProfile().SetLocalProfileFloat("Edit", "IODimY", m_IODim.y); + GetProfile().SetFloatProperty("Edit", "IODimX", m_IODim.x); + GetProfile().SetFloatProperty("Edit", "IODimY", m_IODim.y); } Math::Point CRobotMain::GetIODim() diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 39e7aa9..1b0facb 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3541,7 +3541,7 @@ void CMainDialog::NameSelect() GetGamerFace(m_main->GetGamerName()); - GetProfile().SetLocalProfileString("Gamer", "LastName", m_main->GetGamerName()); + GetProfile().SetStringProperty("Gamer", "LastName", m_main->GetGamerName()); } // Creates a new player. @@ -5164,46 +5164,46 @@ void CMainDialog::ChangeSetupButtons() void CMainDialog::SetupMemorize() { - GetProfile().SetLocalProfileString("Directory", "scene", m_sceneDir); - GetProfile().SetLocalProfileString("Directory", "savegame", m_savegameDir); - GetProfile().SetLocalProfileString("Directory", "public", m_publicDir); - GetProfile().SetLocalProfileString("Directory", "user", m_userDir); - GetProfile().SetLocalProfileString("Directory", "files", m_filesDir); - GetProfile().SetLocalProfileInt("Setup", "Tooltips", m_bTooltip); - GetProfile().SetLocalProfileInt("Setup", "InterfaceGlint", m_bGlint); - GetProfile().SetLocalProfileInt("Setup", "InterfaceGlint", m_bRain); - GetProfile().SetLocalProfileInt("Setup", "Soluce4", m_bSoluce4); - GetProfile().SetLocalProfileInt("Setup", "Movies", m_bMovies); - GetProfile().SetLocalProfileInt("Setup", "NiceReset", m_bNiceReset); - GetProfile().SetLocalProfileInt("Setup", "HimselfDamage", m_bHimselfDamage); - GetProfile().SetLocalProfileInt("Setup", "CameraScroll", m_bCameraScroll); - GetProfile().SetLocalProfileInt("Setup", "CameraInvertX", m_bCameraInvertX); - GetProfile().SetLocalProfileInt("Setup", "CameraInvertY", m_bCameraInvertY); - GetProfile().SetLocalProfileInt("Setup", "InterfaceEffect", m_bEffect); - GetProfile().SetLocalProfileInt("Setup", "GroundShadow", m_engine->GetShadow()); - GetProfile().SetLocalProfileInt("Setup", "GroundSpot", m_engine->GetGroundSpot()); - GetProfile().SetLocalProfileInt("Setup", "ObjectDirty", m_engine->GetDirty()); - GetProfile().SetLocalProfileInt("Setup", "FogMode", m_engine->GetFog()); - GetProfile().SetLocalProfileInt("Setup", "LensMode", m_engine->GetLensMode()); - GetProfile().SetLocalProfileInt("Setup", "SkyMode", m_engine->GetSkyMode()); - GetProfile().SetLocalProfileInt("Setup", "PlanetMode", m_engine->GetPlanetMode()); - GetProfile().SetLocalProfileInt("Setup", "LightMode", m_engine->GetLightMode()); - GetProfile().SetLocalProfileFloat("Setup", "ParticleDensity", m_engine->GetParticleDensity()); - GetProfile().SetLocalProfileFloat("Setup", "ClippingDistance", m_engine->GetClippingDistance()); - GetProfile().SetLocalProfileFloat("Setup", "ObjectDetail", m_engine->GetObjectDetail()); - GetProfile().SetLocalProfileFloat("Setup", "GadgetQuantity", m_engine->GetGadgetQuantity()); - GetProfile().SetLocalProfileInt("Setup", "TextureQuality", m_engine->GetTextureQuality()); - GetProfile().SetLocalProfileInt("Setup", "TotoMode", m_engine->GetTotoMode()); - GetProfile().SetLocalProfileInt("Setup", "AudioVolume", m_sound->GetAudioVolume()); - GetProfile().SetLocalProfileInt("Setup", "MusicVolume", m_sound->GetMusicVolume()); - GetProfile().SetLocalProfileInt("Setup", "EditIndentMode", m_engine->GetEditIndentMode()); - GetProfile().SetLocalProfileInt("Setup", "EditIndentValue", m_engine->GetEditIndentValue()); + GetProfile().SetStringProperty("Directory", "scene", m_sceneDir); + GetProfile().SetStringProperty("Directory", "savegame", m_savegameDir); + GetProfile().SetStringProperty("Directory", "public", m_publicDir); + GetProfile().SetStringProperty("Directory", "user", m_userDir); + GetProfile().SetStringProperty("Directory", "files", m_filesDir); + GetProfile().SetIntProperty("Setup", "Tooltips", m_bTooltip); + GetProfile().SetIntProperty("Setup", "InterfaceGlint", m_bGlint); + GetProfile().SetIntProperty("Setup", "InterfaceGlint", m_bRain); + GetProfile().SetIntProperty("Setup", "Soluce4", m_bSoluce4); + GetProfile().SetIntProperty("Setup", "Movies", m_bMovies); + GetProfile().SetIntProperty("Setup", "NiceReset", m_bNiceReset); + GetProfile().SetIntProperty("Setup", "HimselfDamage", m_bHimselfDamage); + GetProfile().SetIntProperty("Setup", "CameraScroll", m_bCameraScroll); + GetProfile().SetIntProperty("Setup", "CameraInvertX", m_bCameraInvertX); + GetProfile().SetIntProperty("Setup", "CameraInvertY", m_bCameraInvertY); + GetProfile().SetIntProperty("Setup", "InterfaceEffect", m_bEffect); + GetProfile().SetIntProperty("Setup", "GroundShadow", m_engine->GetShadow()); + GetProfile().SetIntProperty("Setup", "GroundSpot", m_engine->GetGroundSpot()); + GetProfile().SetIntProperty("Setup", "ObjectDirty", m_engine->GetDirty()); + GetProfile().SetIntProperty("Setup", "FogMode", m_engine->GetFog()); + GetProfile().SetIntProperty("Setup", "LensMode", m_engine->GetLensMode()); + GetProfile().SetIntProperty("Setup", "SkyMode", m_engine->GetSkyMode()); + GetProfile().SetIntProperty("Setup", "PlanetMode", m_engine->GetPlanetMode()); + GetProfile().SetIntProperty("Setup", "LightMode", m_engine->GetLightMode()); + GetProfile().SetFloatProperty("Setup", "ParticleDensity", m_engine->GetParticleDensity()); + GetProfile().SetFloatProperty("Setup", "ClippingDistance", m_engine->GetClippingDistance()); + GetProfile().SetFloatProperty("Setup", "ObjectDetail", m_engine->GetObjectDetail()); + GetProfile().SetFloatProperty("Setup", "GadgetQuantity", m_engine->GetGadgetQuantity()); + GetProfile().SetIntProperty("Setup", "TextureQuality", m_engine->GetTextureQuality()); + GetProfile().SetIntProperty("Setup", "TotoMode", m_engine->GetTotoMode()); + GetProfile().SetIntProperty("Setup", "AudioVolume", m_sound->GetAudioVolume()); + GetProfile().SetIntProperty("Setup", "MusicVolume", m_sound->GetMusicVolume()); + GetProfile().SetIntProperty("Setup", "EditIndentMode", m_engine->GetEditIndentMode()); + GetProfile().SetIntProperty("Setup", "EditIndentValue", m_engine->GetEditIndentValue()); /* screen setup */ if (m_setupFull) - GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 1); + GetProfile().SetIntProperty("Setup", "Fullscreen", 1); else - GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 0); + GetProfile().SetIntProperty("Setup", "Fullscreen", 0); CList *pl; CWindow *pw; @@ -5213,7 +5213,7 @@ void CMainDialog::SetupMemorize() pl = static_cast(pw->SearchControl(EVENT_LIST2)); if ( pl != 0 ) { - GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect()); + GetProfile().SetIntProperty("Setup", "Resolution", pl->GetSelect()); } } else @@ -5230,9 +5230,9 @@ void CMainDialog::SetupMemorize() key << b.secondary << " "; } - GetProfile().SetLocalProfileString("Setup", "KeyMap", key.str()); + GetProfile().SetStringProperty("Setup", "KeyMap", key.str()); - GetProfile().SetLocalProfileInt("Setup", "DeleteGamer", m_bDeleteGamer); + GetProfile().SetIntProperty("Setup", "DeleteGamer", m_bDeleteGamer); } // Remember all the settings. @@ -5243,48 +5243,48 @@ void CMainDialog::SetupRecall() int iValue; std::string key; - if ( GetProfile().GetLocalProfileString("Directory", "scene", key) ) + if ( GetProfile().GetStringProperty("Directory", "scene", key) ) { m_sceneDir = key; } - if ( GetProfile().GetLocalProfileString("Directory", "savegame", key) ) + if ( GetProfile().GetStringProperty("Directory", "savegame", key) ) { m_savegameDir = key; } - if ( GetProfile().GetLocalProfileString("Directory", "public", key) ) + if ( GetProfile().GetStringProperty("Directory", "public", key) ) { m_publicDir = key; } - if ( GetProfile().GetLocalProfileString("Directory", "user", key) ) + if ( GetProfile().GetStringProperty("Directory", "user", key) ) { m_userDir = key; } - if ( GetProfile().GetLocalProfileString("Directory", "files", key) ) + if ( GetProfile().GetStringProperty("Directory", "files", key) ) { m_filesDir = key; } - if ( GetProfile().GetLocalProfileInt("Setup", "TotoMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "TotoMode", iValue) ) { m_engine->SetTotoMode(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "Tooltips", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Tooltips", iValue) ) { m_bTooltip = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "InterfaceGlint", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "InterfaceGlint", iValue) ) { m_bGlint = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "InterfaceGlint", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "InterfaceGlint", iValue) ) { m_bRain = iValue; } @@ -5295,86 +5295,86 @@ void CMainDialog::SetupRecall() // m_engine->SetNiceMouse(iValue); // } - if ( GetProfile().GetLocalProfileInt("Setup", "Soluce4", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Soluce4", iValue) ) { m_bSoluce4 = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "Movies", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Movies", iValue) ) { m_bMovies = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "NiceReset", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "NiceReset", iValue) ) { m_bNiceReset = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "HimselfDamage", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "HimselfDamage", iValue) ) { m_bHimselfDamage = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "CameraScroll", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "CameraScroll", iValue) ) { m_bCameraScroll = iValue; m_camera->SetCameraScroll(m_bCameraScroll); } - if ( GetProfile().GetLocalProfileInt("Setup", "CameraInvertX", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "CameraInvertX", iValue) ) { m_bCameraInvertX = iValue; m_camera->SetCameraInvertX(m_bCameraInvertX); } - if ( GetProfile().GetLocalProfileInt("Setup", "CameraInvertY", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "CameraInvertY", iValue) ) { m_bCameraInvertY = iValue; m_camera->SetCameraInvertY(m_bCameraInvertY); } - if ( GetProfile().GetLocalProfileInt("Setup", "InterfaceEffect", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "InterfaceEffect", iValue) ) { m_bEffect = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "GroundShadow", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "GroundShadow", iValue) ) { m_engine->SetShadow(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "GroundSpot", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "GroundSpot", iValue) ) { m_engine->SetGroundSpot(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "ObjectDirty", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "ObjectDirty", iValue) ) { m_engine->SetDirty(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "FogMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "FogMode", iValue) ) { m_engine->SetFog(iValue); m_camera->SetOverBaseColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); // TODO: color ok? } - if ( GetProfile().GetLocalProfileInt("Setup", "LensMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "LensMode", iValue) ) { m_engine->SetLensMode(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "SkyMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "SkyMode", iValue) ) { m_engine->SetSkyMode(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "PlanetMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "PlanetMode", iValue) ) { m_engine->SetPlanetMode(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "LightMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "LightMode", iValue) ) { m_engine->SetLightMode(iValue); } @@ -5384,52 +5384,52 @@ void CMainDialog::SetupRecall() // m_engine->SetJoystick(iValue); // } - if ( GetProfile().GetLocalProfileFloat("Setup", "ParticleDensity", fValue) ) + if ( GetProfile().GetFloatProperty("Setup", "ParticleDensity", fValue) ) { m_engine->SetParticleDensity(fValue); } - if ( GetProfile().GetLocalProfileFloat("Setup", "ClippingDistance", fValue) ) + if ( GetProfile().GetFloatProperty("Setup", "ClippingDistance", fValue) ) { m_engine->SetClippingDistance(fValue); } - if ( GetProfile().GetLocalProfileFloat("Setup", "ObjectDetail", fValue) ) + if ( GetProfile().GetFloatProperty("Setup", "ObjectDetail", fValue) ) { m_engine->SetObjectDetail(fValue); } - if ( GetProfile().GetLocalProfileFloat("Setup", "GadgetQuantity", fValue) ) + if ( GetProfile().GetFloatProperty("Setup", "GadgetQuantity", fValue) ) { m_engine->SetGadgetQuantity(fValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "TextureQuality", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "TextureQuality", iValue) ) { m_engine->SetTextureQuality(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "AudioVolume", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "AudioVolume", iValue) ) { m_sound->SetAudioVolume(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "MusicVolume", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "MusicVolume", iValue) ) { m_sound->SetMusicVolume(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "EditIndentMode", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "EditIndentMode", iValue) ) { m_engine->SetEditIndentMode(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "EditIndentValue", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "EditIndentValue", iValue) ) { m_engine->SetEditIndentValue(iValue); } - if (GetProfile().GetLocalProfileString("Setup", "KeyMap", key)) + if (GetProfile().GetStringProperty("Setup", "KeyMap", key)) { std::stringstream skey; skey.str(key); @@ -5442,17 +5442,17 @@ void CMainDialog::SetupRecall() } } - if ( GetProfile().GetLocalProfileInt("Setup", "DeleteGamer", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "DeleteGamer", iValue) ) { m_bDeleteGamer = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Resolution", iValue) ) { m_setupSelMode = iValue; } - if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) + if ( GetProfile().GetIntProperty("Setup", "Fullscreen", iValue) ) { m_setupFull = (iValue == 1); } -- cgit v1.2.3-1-g7c22 From 2770ee8927cb91419b1918f46228435026790cf6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 7 Oct 2014 21:40:51 +0200 Subject: Fixed issue #324 --- src/object/brain.cpp | 16 ++++++++++++++-- src/object/brain.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/object/brain.cpp b/src/object/brain.cpp index ca578ba..01f20f9 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -820,6 +820,18 @@ void CBrain::StopTask() } } +// Stops the current secondary task. + +void CBrain::StopSecondaryTask() +{ + if (m_secondaryTask != nullptr) + { + m_secondaryTask->Abort(); + delete m_secondaryTask; // stops the current secondary task + m_secondaryTask = nullptr; + } +} + // Introduces a virus into a program. // Returns true if it was inserted. @@ -1000,7 +1012,7 @@ Error CBrain::StartTaskRecover() Error CBrain::StartTaskShield(TaskShieldMode mode) { - StopTask(); + StopSecondaryTask(); m_secondaryTask = new CTaskManager(m_object); Error err = m_secondaryTask->StartTaskShield(mode, 1000.0f); @@ -1048,7 +1060,7 @@ Error CBrain::StartTaskFireAnt(Math::Vector impact) Error CBrain::StartTaskGunGoal(float dirV, float dirH) { - StopTask(); + StopSecondaryTask(); m_secondaryTask = new CTaskManager(m_object); Error err = m_secondaryTask->StartTaskGunGoal(dirV, dirH); diff --git a/src/object/brain.h b/src/object/brain.h index 8a6b13e..6b0d790 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -102,6 +102,7 @@ public: int GetProgram(); void StopProgram(); void StopTask(); + void StopSecondaryTask(); bool IntroduceVirus(); void SetActiveVirus(bool bActive); -- cgit v1.2.3-1-g7c22