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(-) 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 15f73d0cea6855107a61f2360254a24a2d66944d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 13 Jul 2014 04:32:51 +0200 Subject: Auto-update from Pootle 2014-07-13 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index d9ad327..b4c9190 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d9ad3270af60905f53929cdf44aa47b4f910f603 +Subproject commit b4c9190a85ef8bda3a1b7992dada1f8fcecc37c2 -- cgit v1.2.3-1-g7c22 From 878d37a593f02fe0b1ff9f9d34b3b35a8c152c40 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 15 Jul 2014 04:33:12 +0200 Subject: Auto-update from Pootle 2014-07-15 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b4c9190..14137c0 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b4c9190a85ef8bda3a1b7992dada1f8fcecc37c2 +Subproject commit 14137c0761f13d8395f43dca28cad813b6ad5c9b -- cgit v1.2.3-1-g7c22 From 6fd5caeee9c3ec684d748977f501520bc32bff98 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 16 Jul 2014 04:33:09 +0200 Subject: Auto-update from Pootle 2014-07-16 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 14137c0..d775bf9 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 14137c0761f13d8395f43dca28cad813b6ad5c9b +Subproject commit d775bf97639bb272425e7c3f8be85c813fce4271 -- cgit v1.2.3-1-g7c22 From b03f15e0dbdeb254d7a40010234cec837db90627 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 17 Jul 2014 04:33:02 +0200 Subject: Auto-update from Pootle 2014-07-17 This commit was automatically generated from http://translations.colobot.info/ --- po/de.po | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/po/de.po b/po/de.po index b6ce0cf..3c5b134 100644 --- a/po/de.po +++ b/po/de.po @@ -7,17 +7,18 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-07-10 16:50+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" +"PO-Revision-Date: 2014-06-30 12:23+0200\n" +"Last-Translator: krzys_h \n" "Language-Team: LANGUAGE \n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Translate Toolkit 1.11.0\n" +"X-Generator: Pootle 2.5.1.1\n" "X-Language: de_DE\n" "X-Source-Language: en_US\n" +"X-POOTLE-MTIME: 1404127439.000000\n" msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" @@ -644,8 +645,9 @@ msgstr "Anweisungen über die Mission(\\key help;)" msgid "Take off to finish the mission" msgstr "Abheben nach vollbrachter Mission" +#, fuzzy msgid "Destroy" -msgstr "" +msgstr "Einstampfer" msgid "Build a derrick" msgstr "Baut einen Bohrturm" @@ -686,8 +688,9 @@ msgstr "Baut einen Blitzableiter" msgid "Build a exchange post" msgstr "Baut einen Infoserver" +#, fuzzy msgid "Build a destroyer" -msgstr "" +msgstr "Gebäude zerstört" msgid "Show if the ground is flat" msgstr "Zeigt ob der Boden eben ist" @@ -1469,8 +1472,9 @@ msgstr "Keine Fahne in Reichweite" msgid "Not found anything to destroy" msgstr "" +#, fuzzy msgid "Inappropriate object" -msgstr "" +msgstr "Roboter ungeeignet" msgid "" "The mission is not accomplished yet (press \\key help; for more details)" -- cgit v1.2.3-1-g7c22 From 20df3a91a25c23e142189cf870007af126239600 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Jul 2014 04:33:05 +0200 Subject: Auto-update from Pootle 2014-07-20 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index d775bf9..2f2c690 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d775bf97639bb272425e7c3f8be85c813fce4271 +Subproject commit 2f2c6907dbdffd16ee998179b29f82d05e290d1e -- cgit v1.2.3-1-g7c22 From 459f72fb58f9e2586d693eb78accb73cb5efc699 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 23 Jul 2014 04:33:02 +0200 Subject: Auto-update from Pootle 2014-07-23 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- po/de.po | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/data b/data index 2f2c690..b8d5e71 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 2f2c6907dbdffd16ee998179b29f82d05e290d1e +Subproject commit b8d5e712c64a1d426522f09272a45e229979e591 diff --git a/po/de.po b/po/de.po index 3c5b134..ab932d3 100644 --- a/po/de.po +++ b/po/de.po @@ -7,8 +7,8 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-07-10 16:50+0200\n" -"PO-Revision-Date: 2014-06-30 12:23+0200\n" -"Last-Translator: krzys_h \n" +"PO-Revision-Date: 2014-07-22 20:26+0200\n" +"Last-Translator: GermanBot \n" "Language-Team: LANGUAGE \n" "Language: de\n" "MIME-Version: 1.0\n" @@ -18,7 +18,7 @@ msgstr "" "X-Generator: Pootle 2.5.1.1\n" "X-Language: de_DE\n" "X-Source-Language: en_US\n" -"X-POOTLE-MTIME: 1404127439.000000\n" +"X-POOTLE-MTIME: 1406057163.000000\n" msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" @@ -645,9 +645,8 @@ msgstr "Anweisungen über die Mission(\\key help;)" msgid "Take off to finish the mission" msgstr "Abheben nach vollbrachter Mission" -#, fuzzy msgid "Destroy" -msgstr "Einstampfer" +msgstr "Zerstören" msgid "Build a derrick" msgstr "Baut einen Bohrturm" @@ -688,9 +687,8 @@ msgstr "Baut einen Blitzableiter" msgid "Build a exchange post" msgstr "Baut einen Infoserver" -#, fuzzy msgid "Build a destroyer" -msgstr "Gebäude zerstört" +msgstr "Baue einen Zerstörer" msgid "Show if the ground is flat" msgstr "Zeigt ob der Boden eben ist" @@ -822,7 +820,7 @@ msgid "Shoot (\\key action;)" msgstr "Feuer (\\key action;)" msgid "Explode (\\key action;)" -msgstr "" +msgstr "Explodieren (\\key action;)" msgid "Recycle (\\key action;)" msgstr "Recyceln (\\key action;)" @@ -1296,7 +1294,7 @@ msgid "Lunar Roving Vehicle" msgstr "Lunar Roving Vehicle" msgid "Internal error - tell the developers" -msgstr "" +msgstr "Interner Fehler - Benachrichtige die Entwickler" msgid "Unknown command" msgstr "Befehl unbekannt" @@ -1359,10 +1357,10 @@ msgid "Too close to a building" msgstr "Zu nahe an einem Gebäude" msgid "Can not produce this object in this mission" -msgstr "" +msgstr "Das Objekt kann in dieser Mission nicht produziert werden" msgid "Can not produce not researched object" -msgstr "" +msgstr "Das erforschte Objekt kann nicht produziert werden" msgid "Ground inappropriate" msgstr "Boden ungeeignet" @@ -1470,7 +1468,7 @@ msgid "No flag nearby" msgstr "Keine Fahne in Reichweite" msgid "Not found anything to destroy" -msgstr "" +msgstr "Nichts zum Zerstampfen gefunden" #, fuzzy msgid "Inappropriate object" -- cgit v1.2.3-1-g7c22 From f290b6c4e73afaaa5326ee3919b0c95cd877a45c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 24 Jul 2014 04:32:39 +0200 Subject: Auto-update from Pootle 2014-07-24 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b8d5e71..0e40e07 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b8d5e712c64a1d426522f09272a45e229979e591 +Subproject commit 0e40e07941e0b932413570999db7e27dc964fc6d -- cgit v1.2.3-1-g7c22 From 86683c06ade41db9a3fe8390a697b702966d3047 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 24 Jul 2014 11:44:51 +0200 Subject: Pootle broke stuff, I've fixed stuff --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 0e40e07..55b1a1c 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 0e40e07941e0b932413570999db7e27dc964fc6d +Subproject commit 55b1a1c201c9a8104d9f46bf6e68bde6960b7bc5 -- cgit v1.2.3-1-g7c22 From d5859fc70e3f8f24f57ca4881a06f69009ebef96 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Jul 2014 04:32:56 +0200 Subject: Auto-update from Pootle 2014-07-25 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 55b1a1c..9ee3b6b 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 55b1a1c201c9a8104d9f46bf6e68bde6960b7bc5 +Subproject commit 9ee3b6b3b8944253d5dd2611980529d40eff13d4 -- cgit v1.2.3-1-g7c22 From 5860684e782092031480a0e424ad35485609b04e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Jul 2014 04:33:05 +0200 Subject: Auto-update from Pootle 2014-07-26 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- po/de.po | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/data b/data index 9ee3b6b..b00b9cd 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 9ee3b6b3b8944253d5dd2611980529d40eff13d4 +Subproject commit b00b9cd26e445dcef52d29b3a3db3253dd4c3137 diff --git a/po/de.po b/po/de.po index ab932d3..34ae436 100644 --- a/po/de.po +++ b/po/de.po @@ -7,8 +7,8 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-07-10 16:50+0200\n" -"PO-Revision-Date: 2014-07-22 20:26+0200\n" -"Last-Translator: GermanBot \n" +"PO-Revision-Date: 2014-07-25 20:39+0200\n" +"Last-Translator: krzys_h \n" "Language-Team: LANGUAGE \n" "Language: de\n" "MIME-Version: 1.0\n" @@ -18,7 +18,7 @@ msgstr "" "X-Generator: Pootle 2.5.1.1\n" "X-Language: de_DE\n" "X-Source-Language: en_US\n" -"X-POOTLE-MTIME: 1406057163.000000\n" +"X-POOTLE-MTIME: 1406317182.000000\n" msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" @@ -178,7 +178,7 @@ msgid "Cancel" msgstr "Abbrechen" msgid "LOADING" -msgstr "Laden" +msgstr "LOADING" msgid "Keyword help(\\key cbot;)" msgstr "Hilfe über den Begriff (\\key cbot;)" @@ -1690,6 +1690,7 @@ msgstr "Diese Klasse gibt es schon" msgid "\" ] \" missing" msgstr "Es fehlt eine geschlossene eckige Klammer \" ] \"" +#, fuzzy msgid "Reserved keyword of CBOT language" msgstr "Dieses Wort ist reserviert" -- cgit v1.2.3-1-g7c22 From f2f9bd3c9e2e630b16fb5a265d0529517be98098 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Jul 2014 04:32:47 +0200 Subject: Auto-update from Pootle 2014-07-28 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b00b9cd..29947d2 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b00b9cd26e445dcef52d29b3a3db3253dd4c3137 +Subproject commit 29947d2c372713e9dd499c2d75a5f34793aab975 -- cgit v1.2.3-1-g7c22 From a74f601ec18b5b6e155aab4c47c9115602e03a25 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 29 Jul 2014 04:32:53 +0200 Subject: Auto-update from Pootle 2014-07-29 This commit was automatically generated from http://translations.colobot.info/ --- po/de.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/po/de.po b/po/de.po index 34ae436..7f99374 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-07-10 16:50+0200\n" -"PO-Revision-Date: 2014-07-25 20:39+0200\n" +"PO-Revision-Date: 2014-07-28 09:27+0200\n" "Last-Translator: krzys_h \n" "Language-Team: LANGUAGE \n" "Language: de\n" @@ -18,7 +18,7 @@ msgstr "" "X-Generator: Pootle 2.5.1.1\n" "X-Language: de_DE\n" "X-Source-Language: en_US\n" -"X-POOTLE-MTIME: 1406317182.000000\n" +"X-POOTLE-MTIME: 1406536037.000000\n" msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" @@ -178,7 +178,7 @@ msgid "Cancel" msgstr "Abbrechen" msgid "LOADING" -msgstr "LOADING" +msgstr "LADEN" msgid "Keyword help(\\key cbot;)" msgstr "Hilfe über den Begriff (\\key cbot;)" -- cgit v1.2.3-1-g7c22 From 73d6d945119561c227b2d6eab810b1db78752cbf Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 5 Aug 2014 04:33:13 +0200 Subject: Auto-update from Pootle 2014-08-05 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 29947d2..ea18354 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 29947d2c372713e9dd499c2d75a5f34793aab975 +Subproject commit ea1835405d8b33ecc9d9f53848abb724eaf59a22 -- 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 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(-) 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 78f69f61663d5005debd0fbfc40f686bb61322f1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 7 Aug 2014 04:32:58 +0200 Subject: Auto-update from Pootle 2014-08-07 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index ea18354..6a8c1ff 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit ea1835405d8b33ecc9d9f53848abb724eaf59a22 +Subproject commit 6a8c1ffefe3a14377b9786f6ac72f8516b62f67f -- cgit v1.2.3-1-g7c22 From b0dbfa3d157e52eaf1c66375e9389d35d11c56b1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Aug 2014 04:32:46 +0200 Subject: Auto-update from Pootle 2014-08-08 This commit was automatically generated from http://translations.colobot.info/ --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 6a8c1ff..bbc351c 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 6a8c1ffefe3a14377b9786f6ac72f8516b62f67f +Subproject commit bbc351c29b739b3031922aef06493fd4a404bbbf -- cgit v1.2.3-1-g7c22 From 17fe2b3d61ea14a083a6e077b827d3e41361a8f8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Aug 2014 13:41:31 +0200 Subject: Updated submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index bbc351c..a521070 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit bbc351c29b739b3031922aef06493fd4a404bbbf +Subproject commit a521070bb17737e1d3990ba09d09d036749635ab -- 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(-) 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(-) 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(-) 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(-) 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 ++++++++---------- test/unit/graphics/core/device_mock.h | 17 --- 4 files changed, 49 insertions(+), 331 deletions(-) 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 diff --git a/test/unit/graphics/core/device_mock.h b/test/unit/graphics/core/device_mock.h index 498239f..78c8502 100644 --- a/test/unit/graphics/core/device_mock.h +++ b/test/unit/graphics/core/device_mock.h @@ -21,11 +21,8 @@ public: MOCK_METHOD0(Clear, void()); MOCK_METHOD2(SetTransform, void(Gfx::TransformType type, const Math::Matrix &matrix)); - MOCK_METHOD1(GetTransform, const Math::Matrix& (Gfx::TransformType type)); - MOCK_METHOD2(MultiplyTransform, void(Gfx::TransformType type, const Math::Matrix &matrix)); MOCK_METHOD1(SetMaterial, void(const Gfx::Material &material)); - MOCK_METHOD0(GetMaterial, const Gfx::Material&()); MOCK_METHOD0(GetMaxLightCount, int()); @@ -33,7 +30,6 @@ public: MOCK_METHOD1(GetLight, const Gfx::Light&(int index)); MOCK_METHOD2(SetLightEnabled, void(int index, bool enabled)); - MOCK_METHOD1(GetLightEnabled, bool(int index)); MOCK_METHOD2(CreateTexture, Gfx::Texture(CImage *image, const Gfx::TextureCreateParams ¶ms)); MOCK_METHOD2(CreateTexture, Gfx::Texture(ImageData *data, const Gfx::TextureCreateParams ¶ms)); @@ -45,13 +41,10 @@ public: MOCK_METHOD2(SetTexture, void(int index, const Gfx::Texture &texture)); MOCK_METHOD2(SetTexture, void(int index, unsigned int textureId)); - MOCK_METHOD1(GetTexture, Gfx::Texture(int index)); MOCK_METHOD2(SetTextureEnabled, void(int index, bool enabled)); - MOCK_METHOD1(GetTextureEnabled, bool(int index)); MOCK_METHOD2(SetTextureStageParams, void(int index, const Gfx::TextureStageParams ¶ms)); - MOCK_METHOD1(GetTextureStageParams, Gfx::TextureStageParams(int index)); MOCK_METHOD3(SetTextureStageWrap, void(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT)); @@ -77,34 +70,24 @@ public: MOCK_METHOD1(GetRenderState, bool(Gfx::RenderState state)); MOCK_METHOD1(SetDepthTestFunc, void(Gfx::CompFunc func)); - MOCK_METHOD0(GetDepthTestFunc, Gfx::CompFunc()); MOCK_METHOD1(SetDepthBias, void(float factor)); - MOCK_METHOD0(GetDepthBias, float()); MOCK_METHOD2(SetAlphaTestFunc, void(Gfx::CompFunc func, float refValue)); - MOCK_METHOD2(GetAlphaTestFunc, void(Gfx::CompFunc &func, float &refValue)); MOCK_METHOD2(SetBlendFunc, void(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend)); - MOCK_METHOD2(GetBlendFunc, void(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend)); MOCK_METHOD1(SetClearColor, void(const Gfx::Color &color)); - MOCK_METHOD0(GetClearColor, Gfx::Color()); MOCK_METHOD1(SetGlobalAmbient, void(const Gfx::Color &color)); - MOCK_METHOD0(GetGlobalAmbient, Gfx::Color()); MOCK_METHOD5(SetFogParams, void(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density)); - MOCK_METHOD5(GetFogParams, void(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density)); MOCK_METHOD1(SetCullMode, void(Gfx::CullMode mode)); - MOCK_METHOD0(GetCullMode, Gfx::CullMode()); MOCK_METHOD1(SetShadeModel, void(Gfx::ShadeModel model)); - MOCK_METHOD0(GetShadeModel, Gfx::ShadeModel()); MOCK_METHOD1(SetFillMode, void(Gfx::FillMode mode)); - MOCK_METHOD0(GetFillMode, Gfx::FillMode()); MOCK_CONST_METHOD0(GetFrameBufferPixels, void*()); }; -- 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 --- CMakeLists.txt | 74 ++++---- src/CMakeLists.txt | 339 ++++++++++++++++++---------------- src/common/profile.cpp | 26 +-- src/common/profile.h | 7 + test/unit/CMakeLists.txt | 258 ++++---------------------- test/unit/common/CMakeLists.txt | 21 --- test/unit/common/image_test.cpp | 57 ------ test/unit/common/profile_test.cpp | 9 +- test/unit/ui/CMakeLists.txt | 46 ----- test/unit/ui/edit_test.cpp | 90 --------- test/unit/ui/mocks/text_mock.h | 35 ---- test/unit/ui/stubs/app_stub.cpp | 42 ----- test/unit/ui/stubs/engine_stub.cpp | 104 ----------- test/unit/ui/stubs/particle_stub.cpp | 205 -------------------- test/unit/ui/stubs/restext_stub.cpp | 12 -- test/unit/ui/stubs/robotmain_stub.cpp | 25 --- 16 files changed, 280 insertions(+), 1070 deletions(-) delete mode 100644 test/unit/common/CMakeLists.txt delete mode 100644 test/unit/common/image_test.cpp delete mode 100644 test/unit/ui/CMakeLists.txt delete mode 100644 test/unit/ui/edit_test.cpp delete mode 100644 test/unit/ui/mocks/text_mock.h delete mode 100644 test/unit/ui/stubs/app_stub.cpp delete mode 100644 test/unit/ui/stubs/engine_stub.cpp delete mode 100644 test/unit/ui/stubs/particle_stub.cpp delete mode 100644 test/unit/ui/stubs/restext_stub.cpp delete mode 100644 test/unit/ui/stubs/robotmain_stub.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bf1e12e..6deed31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,43 +294,6 @@ endif() # Targets ## -if(TESTS) - # Google Test library - find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src PATH_SUFFIXES gtest) - find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS /usr/include) - if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_SRC_DIR AND GTEST_INCLUDE_DIR) - message(STATUS "Using system gtest library in ${GTEST_SRC_DIR}") - else() - message(STATUS "Using bundled gtest library") - set(GTEST_SRC_DIR ${colobot_SOURCE_DIR}/lib/gtest) - set(GTEST_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gtest/include) - endif() - - add_subdirectory(${GTEST_SRC_DIR} lib/gtest) - - # Google Mock library - find_path(GMOCK_SRC_DIR NAMES src/gmock.cc src/gmock-all.cc PATHS /usr/src PATH_SUFFIXES gmock) - find_path(GMOCK_INCLUDE_DIR gmock/gmock.h PATHS /usr/include) - if(NOT(FORCE_BUNDLED_GMOCK) AND GMOCK_SRC_DIR AND GMOCK_INCLUDE_DIR) - message(STATUS "Using system gmock library in ${GMOCK_SRC_DIR}") - - include_directories(${GMOCK_SRC_DIR}) - # gmock-all.cc includes all other sources - add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc) - else() - message(STATUS "Using bundled gmock library") - set(GMOCK_SRC_DIR ${colobot_SOURCE_DIR}/lib/gmock) - set(GMOCK_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gmock/include) - add_subdirectory(${GMOCK_SRC_DIR} lib/gmock) - endif() - - - # Tests targets - enable_testing() - add_subdirectory(test) - -endif() - # Installation paths defined before compiling sources if(PLATFORM_WINDOWS) if(MXE) @@ -370,6 +333,43 @@ if(DESKTOP) add_subdirectory(desktop) endif() +if(TESTS) + # Google Test library + find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src PATH_SUFFIXES gtest) + find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS /usr/include) + if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_SRC_DIR AND GTEST_INCLUDE_DIR) + message(STATUS "Using system gtest library in ${GTEST_SRC_DIR}") + else() + message(STATUS "Using bundled gtest library") + set(GTEST_SRC_DIR ${colobot_SOURCE_DIR}/lib/gtest) + set(GTEST_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gtest/include) + endif() + + add_subdirectory(${GTEST_SRC_DIR} lib/gtest) + + # Google Mock library + find_path(GMOCK_SRC_DIR NAMES src/gmock.cc src/gmock-all.cc PATHS /usr/src PATH_SUFFIXES gmock) + find_path(GMOCK_INCLUDE_DIR gmock/gmock.h PATHS /usr/include) + if(NOT(FORCE_BUNDLED_GMOCK) AND GMOCK_SRC_DIR AND GMOCK_INCLUDE_DIR) + message(STATUS "Using system gmock library in ${GMOCK_SRC_DIR}") + + include_directories(${GMOCK_SRC_DIR}) + # gmock-all.cc includes all other sources + add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc) + else() + message(STATUS "Using bundled gmock library") + set(GMOCK_SRC_DIR ${colobot_SOURCE_DIR}/lib/gmock) + set(GMOCK_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gmock/include) + add_subdirectory(${GMOCK_SRC_DIR} lib/gmock) + endif() + + + # Tests targets + enable_testing() + add_subdirectory(test) + +endif() + ## # Installation 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 diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index bdb5a67..cd745c3 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,170 +1,3 @@ -set(SRC_DIR ${colobot_SOURCE_DIR}/src) - -# Additional libraries per platform -if(MXE) # MXE requires special treatment - set(PLATFORM_LIBS ${MXE_LIBS}) -elseif(PLATFORM_WINDOWS) - # because it isn't included in standard linking libraries - set(PLATFORM_LIBS "-lintl") -elseif(PLATFORM_GNU) - set(PLATFORM_LIBS "-lX11") -elseif(PLATFORM_LINUX) - # for clock_gettime - set(PLATFORM_LIBS "-lrt -lX11") -elseif(PLATFORM_MACOSX) - find_library(LIBINTL_LIBRARY NAMES intl libintl ) - set(PLATFORM_LIBS ${LIBINTL_LIBRARY} ${X11_X11_LIB}) -endif() - - -# Configure file -configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) - -# Code sources -set(COLOBOT_SOURCES -${SRC_DIR}/app/app.cpp -${SRC_DIR}/app/gamedata.cpp -${SRC_DIR}/app/pausemanager.cpp -${SRC_DIR}/app/system.cpp -${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -${SRC_DIR}/app/system_other.cpp -${SRC_DIR}/common/event.cpp -${SRC_DIR}/common/image.cpp -${SRC_DIR}/common/iman.cpp -${SRC_DIR}/common/logger.cpp -${SRC_DIR}/common/misc.cpp -${SRC_DIR}/common/profile.cpp -${SRC_DIR}/common/restext.cpp -${SRC_DIR}/common/stringutils.cpp -${SRC_DIR}/graphics/core/color.cpp -${SRC_DIR}/graphics/engine/camera.cpp -${SRC_DIR}/graphics/engine/cloud.cpp -${SRC_DIR}/graphics/engine/engine.cpp -${SRC_DIR}/graphics/engine/lightman.cpp -${SRC_DIR}/graphics/engine/lightning.cpp -${SRC_DIR}/graphics/engine/modelfile.cpp -${SRC_DIR}/graphics/engine/modelmanager.cpp -${SRC_DIR}/graphics/engine/particle.cpp -${SRC_DIR}/graphics/engine/planet.cpp -${SRC_DIR}/graphics/engine/pyro.cpp -${SRC_DIR}/graphics/engine/terrain.cpp -${SRC_DIR}/graphics/engine/text.cpp -${SRC_DIR}/graphics/engine/water.cpp -${SRC_DIR}/graphics/opengl/gldevice.cpp -${SRC_DIR}/object/auto/auto.cpp -${SRC_DIR}/object/auto/autobase.cpp -${SRC_DIR}/object/auto/autoconvert.cpp -${SRC_DIR}/object/auto/autoderrick.cpp -${SRC_DIR}/object/auto/autodestroyer.cpp -${SRC_DIR}/object/auto/autoegg.cpp -${SRC_DIR}/object/auto/autoenergy.cpp -${SRC_DIR}/object/auto/autofactory.cpp -${SRC_DIR}/object/auto/autoflag.cpp -${SRC_DIR}/object/auto/autohuston.cpp -${SRC_DIR}/object/auto/autoinfo.cpp -${SRC_DIR}/object/auto/autojostle.cpp -${SRC_DIR}/object/auto/autokid.cpp -${SRC_DIR}/object/auto/autolabo.cpp -${SRC_DIR}/object/auto/automush.cpp -${SRC_DIR}/object/auto/autonest.cpp -${SRC_DIR}/object/auto/autonuclear.cpp -${SRC_DIR}/object/auto/autopara.cpp -${SRC_DIR}/object/auto/autoportico.cpp -${SRC_DIR}/object/auto/autoradar.cpp -${SRC_DIR}/object/auto/autorepair.cpp -${SRC_DIR}/object/auto/autoresearch.cpp -${SRC_DIR}/object/auto/autoroot.cpp -${SRC_DIR}/object/auto/autosafe.cpp -${SRC_DIR}/object/auto/autostation.cpp -${SRC_DIR}/object/auto/autotower.cpp -${SRC_DIR}/object/brain.cpp -${SRC_DIR}/object/mainmovie.cpp -${SRC_DIR}/object/motion/motion.cpp -${SRC_DIR}/object/motion/motionant.cpp -${SRC_DIR}/object/motion/motionbee.cpp -${SRC_DIR}/object/motion/motionhuman.cpp -${SRC_DIR}/object/motion/motionmother.cpp -${SRC_DIR}/object/motion/motionspider.cpp -${SRC_DIR}/object/motion/motiontoto.cpp -${SRC_DIR}/object/motion/motionvehicle.cpp -${SRC_DIR}/object/motion/motionworm.cpp -${SRC_DIR}/object/motion/motiondummy.cpp -${SRC_DIR}/object/object.cpp -${SRC_DIR}/object/objman.cpp -${SRC_DIR}/object/robotmain.cpp -${SRC_DIR}/object/task/task.cpp -${SRC_DIR}/object/task/taskadvance.cpp -${SRC_DIR}/object/task/taskbuild.cpp -${SRC_DIR}/object/task/taskfire.cpp -${SRC_DIR}/object/task/taskfireant.cpp -${SRC_DIR}/object/task/taskflag.cpp -${SRC_DIR}/object/task/taskgoto.cpp -${SRC_DIR}/object/task/taskgungoal.cpp -${SRC_DIR}/object/task/taskinfo.cpp -${SRC_DIR}/object/task/taskmanager.cpp -${SRC_DIR}/object/task/taskmanip.cpp -${SRC_DIR}/object/task/taskpen.cpp -${SRC_DIR}/object/task/taskrecover.cpp -${SRC_DIR}/object/task/taskreset.cpp -${SRC_DIR}/object/task/tasksearch.cpp -${SRC_DIR}/object/task/taskshield.cpp -${SRC_DIR}/object/task/taskspiderexplo.cpp -${SRC_DIR}/object/task/tasktake.cpp -${SRC_DIR}/object/task/taskterraform.cpp -${SRC_DIR}/object/task/taskturn.cpp -${SRC_DIR}/object/task/taskwait.cpp -${SRC_DIR}/physics/physics.cpp -${SRC_DIR}/script/cbottoken.cpp -${SRC_DIR}/script/cmdtoken.cpp -${SRC_DIR}/script/script.cpp -${SRC_DIR}/sound/sound.cpp -${SRC_DIR}/ui/button.cpp -${SRC_DIR}/ui/check.cpp -${SRC_DIR}/ui/color.cpp -${SRC_DIR}/ui/compass.cpp -${SRC_DIR}/ui/control.cpp -${SRC_DIR}/ui/displayinfo.cpp -${SRC_DIR}/ui/displaytext.cpp -${SRC_DIR}/ui/edit.cpp -${SRC_DIR}/ui/editvalue.cpp -${SRC_DIR}/ui/gauge.cpp -${SRC_DIR}/ui/group.cpp -${SRC_DIR}/ui/image.cpp -${SRC_DIR}/ui/interface.cpp -${SRC_DIR}/ui/key.cpp -${SRC_DIR}/ui/label.cpp -${SRC_DIR}/ui/list.cpp -${SRC_DIR}/ui/maindialog.cpp -${SRC_DIR}/ui/mainmap.cpp -${SRC_DIR}/ui/mainshort.cpp -${SRC_DIR}/ui/map.cpp -${SRC_DIR}/ui/scroll.cpp -${SRC_DIR}/ui/shortcut.cpp -${SRC_DIR}/ui/slider.cpp -${SRC_DIR}/ui/studio.cpp -${SRC_DIR}/ui/target.cpp -${SRC_DIR}/ui/window.cpp -) - -set(OPENAL_SOURCES "") - -if(OPENAL_SOUND) - set(OPENAL_SOURCES - ${SRC_DIR}/sound/oalsound/alsound.cpp - ${SRC_DIR}/sound/oalsound/buffer.cpp - ${SRC_DIR}/sound/oalsound/channel.cpp - ) -endif() - -# Optional libraries -set(OPTIONAL_LIBS "") - -if(OPENAL_SOUND) - set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) - set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) -endif() - - # Platform-dependent tests if(PLATFORM_WINDOWS) set(PLATFORM_TESTS app/system_windows_test.cpp) @@ -172,67 +5,58 @@ elseif(PLATFORM_LINUX) set(PLATFORM_TESTS app/system_linux_test.cpp) endif() -# Tests +# Sources set(UT_SOURCES -main.cpp -app/app_test.cpp -graphics/engine/lightman_test.cpp -math/func_test.cpp -math/geometry_test.cpp -math/matrix_test.cpp -math/vector_test.cpp -${PLATFORM_TESTS} + main.cpp + app/app_test.cpp + common/profile_test.cpp + graphics/engine/lightman_test.cpp + math/func_test.cpp + math/geometry_test.cpp + math/matrix_test.cpp + math/vector_test.cpp + ${PLATFORM_TESTS} ) -# Local +# Includes include_directories( -. -common -math -${SRC_DIR} -${CMAKE_CURRENT_BINARY_DIR} + common + math + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${COLOBOT_LOCAL_INCLUDES} ) -# System include_directories( -SYSTEM -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} -${SDL_INCLUDE_DIR} -${SDLIMAGE_INCLUDE_DIR} -${SDLTTF_INCLUDE_DIR} -${PNG_INCLUDE_DIRS} -${GLEW_INCLUDE_PATH} -${Boost_INCLUDE_DIRS} -${OPTIONAL_INCLUDE_DIRS} -${LIBSNDFILE_INCLUDE_DIR} -${CLIPBOARD_INCLUDE_DIR} -${LOCALENAME_INCLUDE_DIR} + SYSTEM + ${GTEST_INCLUDE_DIR} + ${GMOCK_INCLUDE_DIR} + ${COLOBOT_SYSTEM_INCLUDES} ) +# Libraries set(LIBS -gtest -gmock -CBot -clipboard -localename -${SDL_LIBRARY} -${SDLIMAGE_LIBRARY} -${SDLTTF_LIBRARY} -${OPENGL_LIBRARY} -${PNG_LIBRARIES} -${GLEW_LIBRARY} -${Boost_LIBRARIES} -${OPTIONAL_LIBS} -${PLATFORM_LIBS} -${LIBSNDFILE_LIBRARY} + gtest + gmock + colobotbase + ${COLOBOT_LIBS} ) -add_executable(colobot_ut ${COLOBOT_SOURCES} ${UT_SOURCES} ${OPENAL_SOURCES}) -target_link_libraries(colobot_ut ${LIBS}) +# Test files -add_test(colobot_ut ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/colobot_ut) +set(TEST_FILES + common/colobot.ini +) -# TODO: change the unit cases to independent automated tests to be included in colobot_ut -add_subdirectory(common) -add_subdirectory(ui) +file(COPY ${TEST_FILES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + +# Targets + +add_executable(colobot_ut ${UT_SOURCES}) +target_link_libraries(colobot_ut ${LIBS}) + +add_test( + NAME colobot_ut + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/colobot_ut + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} +) diff --git a/test/unit/common/CMakeLists.txt b/test/unit/common/CMakeLists.txt deleted file mode 100644 index cf37961..0000000 --- a/test/unit/common/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -set(SRC_DIR ${colobot_SOURCE_DIR}/src) - -include_directories( -${SRC_DIR} -${GTEST_INCLUDE_DIR} -) - -add_executable(image_test ${SRC_DIR}/common/image.cpp image_test.cpp) -target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRARIES}) -add_test(NAME image_test - COMMAND ${CMAKE_BINARY_DIR}/image_test ${CMAKE_SOURCE_DIR}/test/envs/opengl/tex1.png ${CMAKE_BINARY_DIR}/tex1_test.png) - -file(COPY colobot.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - -add_executable(profile_test ${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/logger.cpp profile_test.cpp) -set_target_properties(profile_test PROPERTIES COMPILE_DEFINITIONS "DEV_BUILD=1") -target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) - -add_test(NAME profile_test - COMMAND ${CMAKE_BINARY_DIR}/profile_test - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp deleted file mode 100644 index 2b20a17..0000000 --- a/test/unit/common/image_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "common/image.h" - -#include -#include - -/* For now, just a simple test: loading a file from image - * and saving it to another in PNG. */ - -int main(int argc, char *argv[]) -{ - if (argc != 3) - { - printf("Usage: %s in_image out_image\n", argv[0]); - return 0; - } - - CImage image; - - if (! image.Load(argv[1])) - { - std::string err = image.GetError(); - printf("Error loading '%s': %s\n", argv[1], err.c_str()); - return 1; - } - Gfx::Color color; - std::string str; - - color = image.GetPixel(Math::IntPoint(0, 0)); - str = color.ToString(); - printf("pixel @ (0,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(0, 1)); - str = color.ToString(); - printf("pixel @ (0,1): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 0)); - str = color.ToString(); - printf("pixel @ (1,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 1)); - str = color.ToString(); - printf("pixel @ (1,1): %s\n", str.c_str()); - - image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f)); - image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f)); - image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); - image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)); - - if (! image.SavePNG(argv[2])) - { - std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); - return 2; - } - - return 0; -} diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp index dabcba6..1a4f239 100644 --- a/test/unit/common/profile_test.cpp +++ b/test/unit/common/profile_test.cpp @@ -11,13 +11,14 @@ class CProfileTest : public testing::Test { protected: - CLogger m_logger; CProfile m_profile; }; TEST_F(CProfileTest, ReadTest) { + m_profile.SetUseLocalDirectory(true); + ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file std::string result; @@ -36,9 +37,3 @@ TEST_F(CProfileTest, ReadTest) list = m_profile.GetLocalProfileSection("test_multi", "entry"); ASSERT_EQ(5u, list.size()); } - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt deleted file mode 100644 index 7f7b2f8..0000000 --- a/test/unit/ui/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -set(SRC_DIR ${colobot_SOURCE_DIR}/src) - -include_directories( -. -${SRC_DIR} -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} -${CLIPBOARD_INCLUDE_DIR} -) - -# Platform-dependent implementation of CSystemUtils -if(PLATFORM_WINDOWS) -elseif(PLATFORM_MACOSX) - set(ADDITIONAL_LIB "${X11_X11_LIB}") -else() - set(ADDITIONAL_LIB "-lX11") -endif() - -add_executable(edit_test -${SRC_DIR}/app/gamedata.cpp -${SRC_DIR}/app/system.cpp -${SRC_DIR}/app/${SYSTEM_CPP_MODULE} -${SRC_DIR}/app/system_other.cpp -${SRC_DIR}/common/event.cpp -${SRC_DIR}/common/logger.cpp -${SRC_DIR}/common/misc.cpp -${SRC_DIR}/common/profile.cpp -${SRC_DIR}/common/iman.cpp -${SRC_DIR}/common/stringutils.cpp -${SRC_DIR}/graphics/engine/text.cpp -${SRC_DIR}/ui/button.cpp -${SRC_DIR}/ui/control.cpp -${SRC_DIR}/ui/edit.cpp -${SRC_DIR}/ui/scroll.cpp -stubs/app_stub.cpp -stubs/engine_stub.cpp -stubs/particle_stub.cpp -stubs/restext_stub.cpp -stubs/robotmain_stub.cpp -edit_test.cpp) - -target_link_libraries(edit_test gtest gmock clipboard ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES} ${ADDITIONAL_LIB}) - - - -add_test(edit_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp deleted file mode 100644 index 34af013..0000000 --- a/test/unit/ui/edit_test.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "app/app.h" -#include "app/gamedata.h" - -#include "ui/edit.h" - -#include "mocks/text_mock.h" - -#include - -#include -#include - -class CEditTest : public testing::Test -{ -public: - CEditTest() - : m_robotMain(nullptr) - , m_gameData(nullptr) - , m_engine(nullptr) - , m_edit(nullptr) - {} - - virtual void SetUp() - { - m_robotMain = new CRobotMain(&m_app, false); - - m_gameData = new CGameData(); - - m_engine = new Gfx::CEngine(nullptr); - - m_edit = new Ui::CEdit; - } - - virtual void TearDown() - { - delete m_edit; - m_edit = nullptr; - delete m_engine; - m_engine = nullptr; - delete m_gameData; - m_gameData = nullptr; - delete m_robotMain; - m_robotMain = nullptr; - } - virtual ~CEditTest() - { - - }; - -protected: - CApplication m_app; - CRobotMain* m_robotMain; - CGameData * m_gameData; - Gfx::CEngine * m_engine; - Ui::CEdit * m_edit; - CLogger m_logger; -}; - -using ::testing::_; -using ::testing::An; -using ::testing::Return; - -TEST_F(CEditTest, WriteTest) -{ - ASSERT_TRUE(true); - CTextMock * text = dynamic_cast(m_engine->GetText()); - EXPECT_CALL(*text, GetCharWidth(_, _, _, _)).WillRepeatedly(Return(1.0f)); - EXPECT_CALL(*text, GetStringWidth(An(), _, _, _)).WillOnce(Return(1.0f)); - std::string filename = "test.file"; - m_edit->SetMaxChar(Ui::EDITSTUDIOMAX); - m_edit->SetAutoIndent(true); - std::string inputScript = "{\ntext1\ntext2\n\ntext3\n{\ntext4\n}\n}"; - std::string expectedScript = "{\r\n\ttext1\r\n\ttext2\r\n\t\r\n\ttext3\r\n\t{\r\n\t\ttext4\r\n\t}\r\n}"; - m_edit->SetText(inputScript.c_str(), true); - GetLogger()->Info("Writing text \n"); - m_edit->WriteText("script.txt"); - - std::fstream scriptFile; - - scriptFile.open("script.txt", std::ios_base::binary | std::ios_base::in); - std::string outputScript((std::istreambuf_iterator(scriptFile)), std::istreambuf_iterator()); - ASSERT_STREQ(expectedScript.c_str(), outputScript.c_str()); -} - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h deleted file mode 100644 index b9af6d3..0000000 --- a/test/unit/ui/mocks/text_mock.h +++ /dev/null @@ -1,35 +0,0 @@ -#include "common/logger.h" - -#include "graphics/engine/text.h" - -#include - -class CTextMock : public Gfx::CText -{ -public: - CTextMock(Gfx::CEngine* engine) : CText(engine) - { - } - - virtual ~CTextMock() - { - }; - - MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char ch, - Gfx::FontType type, - float size, - float offset)); - MOCK_METHOD4(GetStringWidth, float(const std::string &text, - std::vector::iterator format, - std::vector::iterator end, - float size)); - MOCK_METHOD3(GetStringWidth, float(std::string text, - Gfx::FontType font, - float size)); - MOCK_METHOD4(GetStringWidth, float(Gfx::UTF8Char ch, - Gfx::FontType font, - float size, - float offset)); - -}; - diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp deleted file mode 100644 index 95430d8..0000000 --- a/test/unit/ui/stubs/app_stub.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "app/app.h" - -#include "graphics/opengl/gldevice.h" - -template<> CApplication* CSingleton::m_instance = nullptr; - -namespace Gfx { - -GLDeviceConfig::GLDeviceConfig() -{ -} - -} /* Gfx */ - - -CApplication::CApplication() -{ -} - -CApplication::~CApplication() -{ -} - -CSoundInterface* CApplication::GetSound() -{ - return nullptr; -} - -CEventQueue* CApplication::GetEventQueue() -{ - return nullptr; -} - -Event CApplication::CreateUpdateEvent() -{ - return Event(EVENT_NULL); -} - -char CApplication::GetLanguageChar() const -{ - return 'E'; -} diff --git a/test/unit/ui/stubs/engine_stub.cpp b/test/unit/ui/stubs/engine_stub.cpp deleted file mode 100644 index 0a2777c..0000000 --- a/test/unit/ui/stubs/engine_stub.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "graphics/engine/engine.h" -#include "graphics/engine/text.h" - -#include "mocks/text_mock.h" - -template<> Gfx::CEngine* CSingleton::m_instance = nullptr; - -namespace Gfx { - -CEngine::CEngine(CApplication* app) : - m_app(app) -{ - m_text = new CTextMock(this); - m_text->Create(); -} - -CEngine::~CEngine() -{ - delete m_text; - m_text = nullptr; -} - -CParticle* CEngine::GetParticle() -{ - return nullptr; -} - -Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) -{ - return Math::Point(size.x, size.y); -} - -void CEngine::SetState(int state, const Color& color) -{ - if (state == m_lastState && color == m_lastColor) - return; - - m_lastState = state; - m_lastColor = color; -} - -Math::IntPoint CEngine::GetWindowSize() -{ - return m_size; -} - -void CEngine::AddStatisticTriangle(int count) -{ - m_statisticTriangle += count; -} - -void CEngine::SetMouseType(EngineMouseType type) -{ - m_mouseType = type; -} - -bool CEngine::SetTexture(const std::string& /* name */, int /* stage */) -{ - return true; -} - -CText* CEngine::GetText() -{ - return m_text; -} - -CDevice* CEngine::GetDevice() -{ - return m_device; -} - -int CEngine::GetEditIndentValue() -{ - return m_editIndentValue; -} - -void CEngine::DeleteTexture(const std::string& /* texName */) -{ -} - -Texture CEngine::LoadTexture(const std::string& /* name */) -{ - Texture texture; - return texture; -} - -Math::Vector CEngine::GetEyePt() -{ - return Math::Vector(); -} - -Math::Vector CEngine::GetLookatPt() -{ - return Math::Vector(); -} - -bool CEngine::GetPause() -{ - return false; -} - - -} /* Gfx */ - diff --git a/test/unit/ui/stubs/particle_stub.cpp b/test/unit/ui/stubs/particle_stub.cpp deleted file mode 100644 index 34cf973..0000000 --- a/test/unit/ui/stubs/particle_stub.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "graphics/engine/particle.h" - -#include "common/logger.h" - - -// Graphics module namespace -namespace Gfx { - - -CParticle::CParticle(CEngine* /*engine*/) -{ -} - -CParticle::~CParticle() -{ -} - -void CParticle::SetDevice(CDevice* /*device*/) -{ -} - -void CParticle::FlushParticle() -{ -} - -void CParticle::FlushParticle(int /*sheet*/) -{ -} - -int CParticle::CreateParticle(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, - ParticleType /*type*/, float /*duration*/, float /*mass*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateFrag(Math::Vector /*pos*/, Math::Vector /*speed*/, EngineTriangle */*triangle*/, - ParticleType /*type*/, float /*duration*/, float /*mass*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreatePart(Math::Vector /*pos*/, Math::Vector /*speed*/, ParticleType /*type*/, - float /*duration*/, float /*mass*/, float /*weight*/, - float /*windSensitivity*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, Math::Point /*dim*/, - float /*duration*/, int /*sheet*/) -{ - return 0; -} - -int CParticle::CreateTrack(Math::Vector /*pos*/, Math::Vector /*speed*/, Math::Point /*dim*/, ParticleType /*type*/, - float /*duration*/, float /*mass*/, float /*length*/, float /*width*/) -{ - return 0; -} - -void CParticle::CreateWheelTrace(const Math::Vector &/*p1*/, const Math::Vector &/*p2*/, const Math::Vector &/*p3*/, - const Math::Vector &/*p4*/, ParticleType /*type*/) -{ -} - -void CParticle::DeleteParticle(ParticleType /*type*/) -{ -} - -void CParticle::DeleteParticle(int /*channel*/) -{ -} - -void CParticle::SetObjectLink(int /*channel*/, CObject */*object*/) -{ -} - -void CParticle::SetObjectFather(int /*channel*/, CObject */*object*/) -{ -} - -void CParticle::SetPosition(int /*channel*/, Math::Vector /*pos*/) -{ -} - -void CParticle::SetDimension(int /*channel*/, Math::Point /*dim*/) -{ -} - -void CParticle::SetZoom(int /*channel*/, float /*zoom*/) -{ -} - -void CParticle::SetAngle(int /*channel*/, float /*angle*/) -{ -} - -void CParticle::SetIntensity(int /*channel*/, float /*intensity*/) -{ -} - -void CParticle::SetParam(int /*channel*/, Math::Vector /*pos*/, Math::Point /*dim*/, float /*zoom*/, float /*angle*/, float /*intensity*/) -{ -} - -void CParticle::SetPhase(int /*channel*/, ParticlePhase /*phase*/, float /*duration*/) -{ -} - -bool CParticle::GetPosition(int /*channel*/, Math::Vector &/*pos*/) -{ - return true; -} - -Color CParticle::GetFogColor(Math::Vector /*pos*/) -{ - return Color(); -} - -void CParticle::SetFrameUpdate(int /*sheet*/, bool /*update*/) -{ -} - -void CParticle::FrameParticle(float /*rTime*/) -{ -} - -void CParticle::DrawParticle(int /*sheet*/) -{ -} - -bool CParticle::WriteWheelTrace(const char */*filename*/, int /*width*/, int /*height*/, Math::Vector /*dl*/, Math::Vector /*ur*/) -{ - return true; -} - -void CParticle::DeleteRank(int /*rank*/) -{ -} - -bool CParticle::CheckChannel(int &/*channel*/) -{ - return true; -} - -void CParticle::DrawParticleTriangle(int /*i*/) -{ -} - -void CParticle::DrawParticleNorm(int /*i*/) -{ -} - -void CParticle::DrawParticleFlat(int /*i*/) -{ -} - -void CParticle::DrawParticleFog(int /*i*/) -{ -} - -void CParticle::DrawParticleRay(int /*i*/) -{ -} - -void CParticle::DrawParticleSphere(int /*i*/) -{ -} - -void CParticle::DrawParticleCylinder(int /*i*/) -{ -} - -void CParticle::DrawParticleWheel(int /*i*/) -{ -} - -CObject* CParticle::SearchObjectGun(Math::Vector /*old*/, Math::Vector /*pos*/, ParticleType /*type*/, CObject */*father*/) -{ - return nullptr; -} - -CObject* CParticle::SearchObjectRay(Math::Vector /*pos*/, Math::Vector /*goal*/, ParticleType /*type*/, CObject */*father*/) -{ - return nullptr; -} - -void CParticle::Play(Sound /*sound*/, Math::Vector /*pos*/, float /*amplitude*/) -{ -} - -bool CParticle::TrackMove(int /*i*/, Math::Vector /*pos*/, float /*progress*/) -{ - return true; -} - -void CParticle::TrackDraw(int /*i*/, ParticleType /*type*/) -{ -} - - -} // namespace Gfx - diff --git a/test/unit/ui/stubs/restext_stub.cpp b/test/unit/ui/stubs/restext_stub.cpp deleted file mode 100644 index fa47da6..0000000 --- a/test/unit/ui/stubs/restext_stub.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "common/restext.h" - -bool GetResource(ResType /* type */, int /* num */, std::string& /* text */) -{ - return true; -} - -bool SearchKey(const char * /* cmd */, InputSlot & /* key */) -{ - return true; -} - diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp deleted file mode 100644 index 692f67f..0000000 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "object/robotmain.h" - - -template<> CRobotMain* CSingleton::m_instance = nullptr; - -CRobotMain::CRobotMain(CApplication* app, bool loadProfile) -{ -} - -CRobotMain::~CRobotMain() -{ -} - -bool CRobotMain::GetGlint() -{ - return false; -} - -const InputBinding& CRobotMain::GetInputBinding(InputSlot slot) -{ - unsigned int index = static_cast(slot); - assert(index >= 0 && index < INPUT_SLOT_MAX); - return m_inputBindings[index]; -} - -- 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 +++++++++++++++++++------------------- test/unit/common/profile_test.cpp | 12 +-- 6 files changed, 203 insertions(+), 203 deletions(-) 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); } diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp index 1a4f239..2d21a90 100644 --- a/test/unit/common/profile_test.cpp +++ b/test/unit/common/profile_test.cpp @@ -17,23 +17,23 @@ protected: TEST_F(CProfileTest, ReadTest) { - m_profile.SetUseLocalDirectory(true); + m_profile.SetUseCurrentDirectory(true); - ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file + ASSERT_TRUE(m_profile.Init()); // load colobot.ini file std::string result; - ASSERT_TRUE(m_profile.GetLocalProfileString("test_string", "string_value", result)); + ASSERT_TRUE(m_profile.GetStringProperty("test_string", "string_value", result)); ASSERT_STREQ("Hello world", result.c_str()); int int_value; - ASSERT_TRUE(m_profile.GetLocalProfileInt("test_int", "int_value", int_value)); + ASSERT_TRUE(m_profile.GetIntProperty("test_int", "int_value", int_value)); ASSERT_EQ(42, int_value); float float_value; - ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value)); + ASSERT_TRUE(m_profile.GetFloatProperty("test_float", "float_value", float_value)); ASSERT_FLOAT_EQ(1.5, float_value); std::vector list; - list = m_profile.GetLocalProfileSection("test_multi", "entry"); + list = m_profile.GetSection("test_multi", "entry"); ASSERT_EQ(5u, list.size()); } -- cgit v1.2.3-1-g7c22 From 80bb5857784b4b2085c4bba7a22cc9627ca66725 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sun, 24 Aug 2014 20:56:12 +0200 Subject: Add po4a to the command installing dependencies There is an one-line command in the INSTALL.md for Ubuntu/Debian users which installs all dependencies. po4a was listed above it, but it wasn't in the command itself. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 81037c5..e61d4f0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -119,7 +119,7 @@ You will need: On Ubuntu (and probably any other Debian-based system), you can use the following command to install all required packages: ``` - $ apt-get install build-essential cmake libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev git + $ apt-get install build-essential cmake libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev git po4a ``` Make sure you install the packages along with header files (often distributed in separate *-dev packages). If you miss any requirements, -- cgit v1.2.3-1-g7c22 From 7557b888bc8cb1b1de4dd1b330a81cd5ac50af04 Mon Sep 17 00:00:00 2001 From: koocotte Date: Tue, 2 Sep 2014 21:02:40 +0200 Subject: Add missing dependency "gettext" for Ubuntu Conflicts: INSTALL.md --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index e61d4f0..ec7b152 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -119,7 +119,7 @@ You will need: On Ubuntu (and probably any other Debian-based system), you can use the following command to install all required packages: ``` - $ apt-get install build-essential cmake libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev git po4a + $ apt-get install build-essential cmake libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev gettext git po4a ``` Make sure you install the packages along with header files (often distributed in separate *-dev packages). If you miss any requirements, -- 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 --- data | 2 +- src/object/brain.cpp | 16 ++++++++++++++-- src/object/brain.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/data b/data index a521070..559797f 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit a521070bb17737e1d3990ba09d09d036749635ab +Subproject commit 559797f35b88a2d5e882119034923b2ab75817e2 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