From 0f2adf05fd2b2b38c2b84aa8d72b3fd756dcfcd4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 26 Nov 2013 18:17:33 +0100 Subject: Corrected markdown formatting in INSTALL --- INSTALL-MXE.md | 2 +- INSTALL.md | 79 +++++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/INSTALL-MXE.md b/INSTALL-MXE.md index 2074de0..89bec0e 100644 --- a/INSTALL-MXE.md +++ b/INSTALL-MXE.md @@ -69,7 +69,7 @@ To cross-compile Colobot using MXE: on external DLLs. However, the resulting binary will be huge with all these libraries, so you might want to do: `strip colobot.exe`. -6. If you want to create a Colobot installer, you need to additionally build 'nsis' +6. If you want to create a Colobot installer, you need to additionally build `nsis` in MXE. Then you can create the NSIS installer that way: `PATH=/path/to/mxe/binaries:$PATH make package` where `/path/to/mxe/binaries` is path to cross-compiled MXE binaries available diff --git a/INSTALL.md b/INSTALL.md index d33a224..0ff56f1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -58,31 +58,44 @@ so you have regular bash commands but can specify paths using Windows syntax: "C CMake should automatically detect this build environment and use the Windows options to compile. To compile colobot, change the directory to where you have downloaded the source files: - $ cd "C:\path\to\colobot\sources" - +``` + $ cd "C:\path\to\colobot\sources" +``` It is recommended that you create a build directory: - $ mkdir build - $ cd build - +``` + $ mkdir build + $ cd build +``` Then you have to configure CMake. You should specify the following options: +``` $ cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="C:\some\directory" .. -where "C:\some\directory" is the directory you want to run colobot from. It can be a proper installation path if you want -to install it in system, or some temporary directory like "..\colobot-temporary-install" if you just want to try the game. -You can also skip this argument and use the default install path: "C:\Program Files\colobot". +``` +where `C:\some\directory` is the directory you want to run colobot from. It can be a proper installation path if you want +to install it in system, or some temporary directory like `..\colobot-temporary-install` if you just want to try the game. +You can also skip this argument and use the default install path: `C:\Program Files\colobot`. Make sure you specify "MSYS Makefiles" as the CMake generator because otherwise, the default for Windows is to use MSVC nmake and it will not work. Then to compile: - $ make - +``` + $ make +``` Everything should compile just fine. If you see any errors, it most likely means missing libraries or invalid installation. Warnings may occur, but are mostly harmless. Now you need to perform the installation: - $ make install - +``` + $ make install +``` You should get all files ready to use under the installation prefix you specified. Run `colobot.exe` and enjoy the game. +As of 0.1.2-alpha, you can also create a Windows installer package using NSIS (http://nsis.sourceforge.net/). To create +a package, make sure you have the NSIS utilities (makensis) in your system path (or set `$PATH` accordingly), and invoke: +``` + $ make package +``` + + ### Compiling on Linux Since there are so many Linux flavors, it is difficult to write generic instructions. However, here is the general gist of what @@ -108,38 +121,48 @@ Make sure you install the packages along with header files (often distributed in CMake should warn you. To compile colobot, run your favorite shell and change the directory to where you downloaded colobot source files: - $ cd /path/to/colobot/sources - +``` + $ cd /path/to/colobot/sources +``` It is recommended that you create a build directory: - $ mkdir build - $ cd build - +``` + $ mkdir build + $ cd build +``` Now to configure CMake: - $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/some/prefix .. -where "/some/prefix" is installation prefix where you want to put the game files. It could be a proper installation directory -if you want to install colobot in the system or simply temporary directory like "/tmp/colobot-temporary-install" if you just want to try it. +``` + $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/some/prefix .. +``` +where `/some/prefix` is installation prefix where you want to put the game files. It could be a proper installation directory +if you want to install colobot in the system or simply temporary directory like `/tmp/colobot-temporary-install` if you just want to try it. You can also use clang as the compiler. In that case, before issuing cmake, set the following variables: - $ export CC=clang CXX=clang++ - +``` + $ export CC=clang CXX=clang++ +``` Then to compile: - $ make - +``` + $ make +``` Everything should compile just fine. If you see any errors, it most likely means missing libraries. Warnings may occur, but are mostly harmless. Now you need to install the game files: - $ make install - +``` + $ make install +``` You can now run the game from the prefix you specified. Note that colobot binary is installed in `games/` subdirectory. So if you provided prefix "/some/prefix", you can run: - $ /some/prefix/games/colobot +``` + $ /some/prefix/games/colobot +``` ### Compiling on MacOS X As of 0.1.2-alpha, we have added MacOS X support. See [INSTALL-MacOSX.md](https://github.com/colobot/colobot/blob/master/INSTALL-MacOSX.md) file for details. -## Other platforms + +### Other platforms The code isn't particularly tied to any compiler or platform, so in theory it should work on any platform provided you have the required libraries there. Also, other compilers than currently supported GCC >= 4.6 and Clang may happen to work with our code. -- cgit v1.2.3-1-g7c22 From 047db22d4a34db3fa3e41f41ccdab6f02174b78f Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 26 Nov 2013 18:17:33 +0100 Subject: Corrected markdown formatting in INSTALL --- INSTALL-MXE.md | 2 +- INSTALL.md | 79 +++++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/INSTALL-MXE.md b/INSTALL-MXE.md index 2074de0..89bec0e 100644 --- a/INSTALL-MXE.md +++ b/INSTALL-MXE.md @@ -69,7 +69,7 @@ To cross-compile Colobot using MXE: on external DLLs. However, the resulting binary will be huge with all these libraries, so you might want to do: `strip colobot.exe`. -6. If you want to create a Colobot installer, you need to additionally build 'nsis' +6. If you want to create a Colobot installer, you need to additionally build `nsis` in MXE. Then you can create the NSIS installer that way: `PATH=/path/to/mxe/binaries:$PATH make package` where `/path/to/mxe/binaries` is path to cross-compiled MXE binaries available diff --git a/INSTALL.md b/INSTALL.md index d33a224..0ff56f1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -58,31 +58,44 @@ so you have regular bash commands but can specify paths using Windows syntax: "C CMake should automatically detect this build environment and use the Windows options to compile. To compile colobot, change the directory to where you have downloaded the source files: - $ cd "C:\path\to\colobot\sources" - +``` + $ cd "C:\path\to\colobot\sources" +``` It is recommended that you create a build directory: - $ mkdir build - $ cd build - +``` + $ mkdir build + $ cd build +``` Then you have to configure CMake. You should specify the following options: +``` $ cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="C:\some\directory" .. -where "C:\some\directory" is the directory you want to run colobot from. It can be a proper installation path if you want -to install it in system, or some temporary directory like "..\colobot-temporary-install" if you just want to try the game. -You can also skip this argument and use the default install path: "C:\Program Files\colobot". +``` +where `C:\some\directory` is the directory you want to run colobot from. It can be a proper installation path if you want +to install it in system, or some temporary directory like `..\colobot-temporary-install` if you just want to try the game. +You can also skip this argument and use the default install path: `C:\Program Files\colobot`. Make sure you specify "MSYS Makefiles" as the CMake generator because otherwise, the default for Windows is to use MSVC nmake and it will not work. Then to compile: - $ make - +``` + $ make +``` Everything should compile just fine. If you see any errors, it most likely means missing libraries or invalid installation. Warnings may occur, but are mostly harmless. Now you need to perform the installation: - $ make install - +``` + $ make install +``` You should get all files ready to use under the installation prefix you specified. Run `colobot.exe` and enjoy the game. +As of 0.1.2-alpha, you can also create a Windows installer package using NSIS (http://nsis.sourceforge.net/). To create +a package, make sure you have the NSIS utilities (makensis) in your system path (or set `$PATH` accordingly), and invoke: +``` + $ make package +``` + + ### Compiling on Linux Since there are so many Linux flavors, it is difficult to write generic instructions. However, here is the general gist of what @@ -108,38 +121,48 @@ Make sure you install the packages along with header files (often distributed in CMake should warn you. To compile colobot, run your favorite shell and change the directory to where you downloaded colobot source files: - $ cd /path/to/colobot/sources - +``` + $ cd /path/to/colobot/sources +``` It is recommended that you create a build directory: - $ mkdir build - $ cd build - +``` + $ mkdir build + $ cd build +``` Now to configure CMake: - $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/some/prefix .. -where "/some/prefix" is installation prefix where you want to put the game files. It could be a proper installation directory -if you want to install colobot in the system or simply temporary directory like "/tmp/colobot-temporary-install" if you just want to try it. +``` + $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/some/prefix .. +``` +where `/some/prefix` is installation prefix where you want to put the game files. It could be a proper installation directory +if you want to install colobot in the system or simply temporary directory like `/tmp/colobot-temporary-install` if you just want to try it. You can also use clang as the compiler. In that case, before issuing cmake, set the following variables: - $ export CC=clang CXX=clang++ - +``` + $ export CC=clang CXX=clang++ +``` Then to compile: - $ make - +``` + $ make +``` Everything should compile just fine. If you see any errors, it most likely means missing libraries. Warnings may occur, but are mostly harmless. Now you need to install the game files: - $ make install - +``` + $ make install +``` You can now run the game from the prefix you specified. Note that colobot binary is installed in `games/` subdirectory. So if you provided prefix "/some/prefix", you can run: - $ /some/prefix/games/colobot +``` + $ /some/prefix/games/colobot +``` ### Compiling on MacOS X As of 0.1.2-alpha, we have added MacOS X support. See [INSTALL-MacOSX.md](https://github.com/colobot/colobot/blob/master/INSTALL-MacOSX.md) file for details. -## Other platforms + +### Other platforms The code isn't particularly tied to any compiler or platform, so in theory it should work on any platform provided you have the required libraries there. Also, other compilers than currently supported GCC >= 4.6 and Clang may happen to work with our code. -- cgit v1.2.3-1-g7c22 From 343fa8f0cbad19402a2533651acc53149be1fcf5 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 27 Nov 2013 18:53:28 +0100 Subject: Add a PLATFORM_GNU global variable matching all GNU systems such as Debian's Linux, kFreeBSD and Hurd --- CMakeLists.txt | 16 +++++++++++++++- desktop/CMakeLists.txt | 8 ++++---- lib/clipboard/CMakeLists.txt | 2 -- src/CMakeLists.txt | 2 ++ src/common/config.h.cmake | 1 + test/unit/CMakeLists.txt | 2 ++ test/unit/ui/CMakeLists.txt | 2 -- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff30513..c4c3e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ message(STATUS "Building Colobot \"${COLOBOT_VERSION_CODENAME}\" (${COLOBOT_VERS if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") message(STATUS "Build for Windows system") set(PLATFORM_WINDOWS 1) + set(PLATFORM_GNU 0) set(PLATFORM_LINUX 0) set(PLATFORM_MACOSX 0) set(PLATFORM_OTHER 0) @@ -52,15 +53,27 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") message(STATUS "Build for Linux system") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 1) + set(PLATFORM_GNU 1) set(PLATFORM_MACOSX 0) set(PLATFORM_OTHER 0) # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_linux.cpp") +elseif("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU") + message(STATUS "Build for kFreeBSD system") + set(PLATFORM_WINDOWS 0) + set(PLATFORM_LINUX 0) + set(PLATFORM_GNU 1) + set(PLATFORM_MACOSX 0) + set(PLATFORM_OTHER 0) + + # Platform-dependent implementation of system.h + set(SYSTEM_CPP_MODULE "system_other.cpp") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") message(STATUS "Build for Mac OSX system") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 0) + set(PLATFORM_GNU 0) set(PLATFORM_MACOSX 1) set(PLATFORM_OTHER 0) @@ -72,6 +85,7 @@ else() message(STATUS "Build for other system") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 0) + set(PLATFORM_GNU 0) set(PLATFORM_MACOSX 0) set(PLATFORM_OTHER 1) @@ -226,7 +240,7 @@ include("${colobot_SOURCE_DIR}/cmake/msys.cmake") ## # Clipboard support needs X11 libraries ## -if(PLATFORM_LINUX OR PLATFORM_MACOSX) +if(PLATFORM_GNU OR PLATFORM_MACOSX) find_package(X11 REQUIRED) if(PLATFORM_MACOSX) # Add the includes for X11 diff --git a/desktop/CMakeLists.txt b/desktop/CMakeLists.txt index 9fa0c5e..87c8a4b 100644 --- a/desktop/CMakeLists.txt +++ b/desktop/CMakeLists.txt @@ -4,7 +4,7 @@ set(COLOBOT_ICON_FILE colobot.svg) # Render SVG icon in various sizes find_program(RSVG_CONVERT rsvg-convert) -if(RSVG_CONVERT AND (PLATFORM_LINUX OR PLATFORM_MACOSX)) +if(RSVG_CONVERT AND (PLATFORM_GNU OR PLATFORM_MACOSX)) add_custom_target(png-icons ALL) foreach(PNGSIZE 512 256 128 48 32 16) add_custom_command( @@ -15,7 +15,7 @@ if(RSVG_CONVERT AND (PLATFORM_LINUX OR PLATFORM_MACOSX)) add_custom_target(png-icon-${PNGSIZE} ALL DEPENDS ${PNGSIZE}/colobot.png) add_dependencies(png-icons png-icon-${PNGSIZE}) - if(PLATFORM_LINUX) + if(PLATFORM_GNU) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGSIZE}/colobot.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/${PNGSIZE}x${PNGSIZE}/apps/ @@ -37,7 +37,7 @@ if(RSVG_CONVERT AND (PLATFORM_LINUX OR PLATFORM_MACOSX)) endif() -if(PLATFORM_LINUX) +if(PLATFORM_GNU) # Install Desktop Entry file set(COLOBOT_DESKTOP_FILE colobot.desktop) add_custom_command( @@ -112,7 +112,7 @@ if(PLATFORM_LINUX) endforeach() endif() endif() -endif(PLATFORM_LINUX) +endif(PLATFORM_GNU) if(PLATFORM_MACOSX) configure_file(Info.plist.cmake ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) diff --git a/lib/clipboard/CMakeLists.txt b/lib/clipboard/CMakeLists.txt index a189ec4..7999cc1 100644 --- a/lib/clipboard/CMakeLists.txt +++ b/lib/clipboard/CMakeLists.txt @@ -7,8 +7,6 @@ add_definitions(-DLIB_COMPILE=1) if(PLATFORM_WINDOWS) set(CLIPBOARD_SRC src/clipboardWin32.c) -elseif(PLATFORM_LINUX) - set(CLIPBOARD_SRC src/clipboardX11.c) else() set(CLIPBOARD_SRC src/clipboardX11.c) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef59973..c32f054 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,8 @@ if(MXE) # MXE requires special treatment 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") diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 63cd93b..6408b6e 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -3,6 +3,7 @@ // Macros set by CMake #cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ +#cmakedefine PLATFORM_GNU @PLATFORM_GNU@ #cmakedefine PLATFORM_MACOSX @PLATFORM_MACOSX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 38bffda..278519f 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -6,6 +6,8 @@ if(MXE) # MXE requires special treatment 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") diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 8086967..503f84b 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -10,8 +10,6 @@ ${CLIPBOARD_INCLUDE_DIR} # Platform-dependent implementation of CSystemUtils if(PLATFORM_WINDOWS) -elseif(PLATFORM_LINUX) - set(ADDITIONAL_LIB "-lX11") elseif(PLATFORM_MACOSX) set(ADDITIONAL_LIB "${X11_X11_LIB}") else() -- cgit v1.2.3-1-g7c22 From 8deb1305726966b3b583865dec1ba7ba1327d8cb Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 3 Dec 2013 00:11:26 +0100 Subject: Changed char[] to std::string in restext Experimental changes --- src/common/restext.cpp | 32 +++++++++++------------------ src/common/restext.h | 2 +- src/common/stringutils.cpp | 34 +++++++++++++++++++++++++++++++ src/common/stringutils.h | 11 ++++++---- src/object/auto/auto.cpp | 2 +- src/object/brain.cpp | 12 ++++++----- src/object/object.cpp | 4 ++-- src/object/object.h | 2 +- src/object/robotmain.cpp | 27 +++++++++++++------------ src/object/robotmain.h | 4 ++-- src/script/script.cpp | 29 +++++++++++++++------------ src/script/script.h | 2 +- src/ui/button.cpp | 7 +------ src/ui/check.cpp | 7 +------ src/ui/color.cpp | 7 +------ src/ui/control.cpp | 26 ++++++++++++++++-------- src/ui/control.h | 2 ++ src/ui/displayinfo.cpp | 50 +++++++++++++++++++++------------------------- src/ui/displaytext.cpp | 8 +++----- src/ui/edit.cpp | 12 ++++++++--- src/ui/group.cpp | 7 +------ src/ui/image.cpp | 7 +------ src/ui/key.cpp | 28 ++++++++++++++++---------- src/ui/maindialog.cpp | 39 ++++++++++++++++++++---------------- src/ui/mainshort.cpp | 8 ++++---- src/ui/studio.cpp | 48 ++++++++++++++++++++++---------------------- src/ui/window.cpp | 12 +++++------ 27 files changed, 232 insertions(+), 197 deletions(-) diff --git a/src/common/restext.cpp b/src/common/restext.cpp index d61fa63..c5d0ceb 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -776,9 +776,7 @@ static KeyDesc keyTable[22] = bool SearchKey(const char *cmd, InputSlot &key) { - int i; - - for ( i=0 ; i<22 ; i++ ) + for (int i = 0; i < 22 ;i++) { if ( strstr(cmd, keyTable[i].name) == cmd ) { @@ -791,14 +789,11 @@ bool SearchKey(const char *cmd, InputSlot &key) // Replaces the commands "\key name;" in a text. -static void PutKeyName(char* dst, const char* src) +static void PutKeyName(std::string& dst, const char* src) { - InputSlot key; - char name[50]; - int s, d, n; - unsigned int res; + dst.clear(); - s = d = 0; + int s = 0; while ( src[s] != 0 ) { if ( src[s+0] == '\\' && @@ -807,18 +802,16 @@ static void PutKeyName(char* dst, const char* src) src[s+3] == 'y' && src[s+4] == ' ' ) { + InputSlot key; if ( SearchKey(src+s+5, key) ) { - res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary; + unsigned int res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary; if (res != KEY_INVALID) { - if ( GetResource(RES_KEY, res, name) ) + std::string keyName; + if ( GetResource(RES_KEY, res, keyName) ) { - n = 0; - while ( name[n] != 0 ) - { - dst[d++] = name[n++]; - } + dst.append(keyName); while ( src[s++] != ';' ); continue; } @@ -826,9 +819,8 @@ static void PutKeyName(char* dst, const char* src) } } - dst[d++] = src[s++]; + dst.append(1, src[s++]); } - dst[d++] = 0; } // Returns the translated text of a resource that needs key substitution @@ -905,13 +897,13 @@ static const char* GetResourceBase(ResType type, int num) // Returns the text of a resource. -bool GetResource(ResType type, int num, char* text) +bool GetResource(ResType type, int num, std::string& text) { const char *tmpl = GetResourceBase(type, num); if (!tmpl) { - text[0] = 0; + text.clear(); return false; } diff --git a/src/common/restext.h b/src/common/restext.h index e4659e2..b5a3415 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -157,5 +157,5 @@ void InitializeRestext(); void SetGlobalGamerName(std::string name); bool SearchKey(const char *cmd, InputSlot& slot); -bool GetResource(ResType type, int num, char* text); +bool GetResource(ResType type, int num, std::string& text); diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp index 953abba..37169a5 100644 --- a/src/common/stringutils.cpp +++ b/src/common/stringutils.cpp @@ -17,6 +17,40 @@ #include "common/stringutils.h" +#include +#include + + +static std::string VFormat(const char *fmt, va_list ap) +{ + size_t size = 1024; + char stackbuf[1024]; + std::vector dynamicbuf; + char *buf = &stackbuf[0]; + + while (1) + { + int needed = vsnprintf (buf, size, fmt, ap); + + if (needed <= static_cast(size) && needed >= 0) + { + return std::string(buf, static_cast(needed)); + } + + size = (needed > 0) ? (needed+1) : (size*2); + dynamicbuf.resize(size); + buf = &dynamicbuf[0]; + } +} + +std::string StrUtils::Format(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + std::string buf = VFormat(fmt, ap); + va_end(ap); + return buf; +} std::string StrUtils::Replace(const std::string &str, const std::string &oldStr, const std::string &newStr) { diff --git a/src/common/stringutils.h b/src/common/stringutils.h index c60bfb0..e80163a 100644 --- a/src/common/stringutils.h +++ b/src/common/stringutils.h @@ -31,11 +31,11 @@ namespace StrUtils { /** If given, \a ok is set to true/false on success/failure. Warning: To avoid unnecessary problems, *always* give full template qualifier e.g. ToString\ */ template -std::string ToString(T value, bool *ok = NULL) +std::string ToString(T value, bool *ok = nullptr) { std::ostringstream s; s << value; - if (ok != NULL) + if (ok != nullptr) *ok = !s.fail(); return s.str(); } @@ -44,17 +44,20 @@ std::string ToString(T value, bool *ok = NULL) /** If given, \a ok is set to true/false on success/failure. Warning: To avoid unnecessary problems, *always* give full template qualifier e.g. FromString\ */ template -T FromString(const std::string &str, bool *ok = NULL) +T FromString(const std::string &str, bool *ok = nullptr) { std::istringstream s; s.str(str); T value; s >> value; - if (ok != NULL) + if (ok != nullptr) *ok = !s.fail(); return value; } +//! Replacement for sprintf() +std::string Format(const char *fmt, ...); + //! Returns a string with every occurence of \a oldStr in \a str replaced to \a newStr std::string Replace(const std::string &str, const std::string &oldStr, const std::string &newStr); diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index 0aeaa0a..9e593a9 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -175,7 +175,6 @@ bool CAuto::CreateInterface(bool bSelect) Ui::CWindow* pw; Math::Point pos, dim, ddim; float ox, oy, sx, sy; - char name[100]; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw != nullptr ) @@ -195,6 +194,7 @@ bool CAuto::CreateInterface(bool bSelect) pw = static_cast(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw == 0 ) return false; + std::string name; m_object->GetTooltipName(name); pos.x = 0.0f; pos.y = 64.0f/480.0f; diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 1b1565a..b27acd1 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1238,7 +1238,6 @@ bool CBrain::CreateInterface(bool bSelect) Ui::CLabel* pl; Math::Point pos, dim, ddim; float ox, oy, sx, sy; - char name[100]; pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw != 0 ) @@ -1259,13 +1258,14 @@ bool CBrain::CreateInterface(bool bSelect) pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw == 0 ) return false; - m_object->GetTooltipName(name); + std::string tooltipLabel; + m_object->GetTooltipName(tooltipLabel); pos.x = 0.0f; pos.y = 64.0f/480.0f; ddim.x = 540.0f/640.0f; if ( !m_main->GetShowMap() ) ddim.x = 640.0f/640.0f; ddim.y = 16.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, name); + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, tooltipLabel); dim.x = 33.0f/640.0f; dim.y = 33.0f/480.0f; @@ -1674,8 +1674,10 @@ bool CBrain::CreateInterface(bool bSelect) pos.y = oy+sy*1.2f; ddim.x = dim.x*2.2f; ddim.y = dim.y*0.4f; - GetResource(RES_TEXT, RT_INTERFACE_REC, name); - pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name); + + std::string recordLabel; + GetResource(RES_TEXT, RT_INTERFACE_REC, recordLabel); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, recordLabel); pl->SetFontSize(9.0f); pos.x = ox+sx*7.0f; diff --git a/src/object/object.cpp b/src/object/object.cpp index 5a709e6..f1de424 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -7263,10 +7263,10 @@ int CObject::GetDefRank() // Getes the object name for the tooltip. -bool CObject::GetTooltipName(char* name) +bool CObject::GetTooltipName(std::string& name) { GetResource(RES_OBJECT, m_type, name); - return ( name[0] != 0 ); + return !name.empty(); } diff --git a/src/object/object.h b/src/object/object.h index e8b83d9..b5c0385 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -639,7 +639,7 @@ public: void SetDefRank(int rank); int GetDefRank(); - bool GetTooltipName(char* name); + bool GetTooltipName(std::string& name); void AddDeselList(CObject* pObj); CObject* SubDeselList(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 26fa827..35ffe97 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -690,7 +690,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_movieInfoIndex = -1; m_tooltipPos = Math::Point(0.0f, 0.0f); - m_tooltipName[0] = 0; + m_tooltipName.clear(); m_tooltipTime = 0.0f; m_endingWinRank = 0; @@ -3025,7 +3025,7 @@ bool CRobotMain::DeleteObject() void CRobotMain::HiliteClear() { ClearTooltip(); - m_tooltipName[0] = 0; // really removes the tooltip + m_tooltipName.clear(); // really removes the tooltip if (!m_hilite) return; @@ -3059,11 +3059,11 @@ void CRobotMain::HiliteObject(Math::Point pos) CObject* obj = m_short->DetectShort(pos); - std::string nameStr; - if (m_dialog->GetTooltip() && m_interface->GetTooltip(pos, nameStr)) + std::string interfaceTooltipName; + if (m_dialog->GetTooltip() && m_interface->GetTooltip(pos, interfaceTooltipName)) { m_tooltipPos = pos; - strcpy(m_tooltipName, nameStr.c_str()); + m_tooltipName = interfaceTooltipName; m_tooltipTime = 0.0f; if (obj == nullptr) return; } @@ -3086,13 +3086,13 @@ void CRobotMain::HiliteObject(Math::Point pos) } } - char name[100]; if (obj != nullptr) { - if (m_dialog->GetTooltip() && obj->GetTooltipName(name)) + std::string objectTooltipName; + if (m_dialog->GetTooltip() && obj->GetTooltipName(objectTooltipName)) { m_tooltipPos = pos; - strcpy(m_tooltipName, name); + m_tooltipName = objectTooltipName; m_tooltipTime = 0.0f; } @@ -3117,15 +3117,14 @@ void CRobotMain::HiliteFrame(float rTime) ClearTooltip(); - if (m_tooltipTime >= 0.2f && - m_tooltipName[0] != 0) + if (m_tooltipTime >= 0.2f && !m_tooltipName.empty()) { CreateTooltip(m_tooltipPos, m_tooltipName); } } //! Creates a tooltip -void CRobotMain::CreateTooltip(Math::Point pos, const char* text) +void CRobotMain::CreateTooltip(Math::Point pos, const std::string& text) { Math::Point corner; corner.x = pos.x+0.022f; @@ -3949,7 +3948,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_dialog->BuildResumeName(m_title, base, rank); m_dialog->BuildResumeName(m_resume, base, rank); - GetResource(RES_TEXT, RT_SCRIPT_NEW, m_scriptName); + std::string scriptNameStr; + GetResource(RES_TEXT, RT_SCRIPT_NEW, scriptNameStr); + strcpy(m_scriptName, scriptNameStr.c_str()); m_scriptFile[0] = 0; m_beginObject = false; @@ -7504,7 +7505,7 @@ void CRobotMain::StartMusic() void CRobotMain::ClearInterface() { HiliteClear(); // removes setting evidence - m_tooltipName[0] = 0; // really removes the tooltip + m_tooltipName.clear(); // really removes the tooltip } void CRobotMain::SetNumericLocale() diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 035698c..76535de 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -398,7 +398,7 @@ protected: void HiliteClear(); void HiliteObject(Math::Point pos); void HiliteFrame(float rTime); - void CreateTooltip(Math::Point pos, const char* text); + void CreateTooltip(Math::Point pos, const std::string& text); void ClearTooltip(); CObject* DetectObject(Math::Point pos); void ChangeCamera(); @@ -506,7 +506,7 @@ protected: char m_mapFilename[100]; Math::Point m_tooltipPos; - char m_tooltipName[100]; + std::string m_tooltipName; float m_tooltipTime; char m_infoFilename[SATCOM_MAX][100]; // names of text files diff --git a/src/script/script.cpp b/src/script/script.cpp index ca6ce25..5cd21f9 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -22,6 +22,7 @@ #include "common/global.h" #include "common/iman.h" #include "common/restext.h" +#include "common/stringutils.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" @@ -3898,9 +3899,9 @@ bool CScript::Continue(const Event &event) if ( m_error != 0 && m_errMode == ERM_STOP ) { - char s[100]; + std::string s; GetError(s); - m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR); + m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR); } m_engine->SetPause(true); // gives pause return true; @@ -3931,9 +3932,9 @@ bool CScript::Continue(const Event &event) if ( m_error != 0 && m_errMode == ERM_STOP ) { - char s[100]; + std::string s; GetError(s); - m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR); + m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR); } return true; } @@ -3973,9 +3974,9 @@ bool CScript::Step(const Event &event) if ( m_error != 0 && m_errMode == ERM_STOP ) { - char s[100]; + std::string s; GetError(s); - m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR); + m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR); } return true; } @@ -4347,27 +4348,27 @@ int CScript::GetError() // Returns the text of the error. -void CScript::GetError(char* buffer) +void CScript::GetError(std::string& error) { if ( m_error == 0 ) { - buffer[0] = 0; + error.clear(); } else { if ( m_error == ERR_OBLIGATORYTOKEN ) { - char s[100]; + std::string s; GetResource(RES_ERR, m_error, s); - sprintf(buffer, s, m_token); + error = StrUtils::Format(s.c_str(), m_token); } else if ( m_error < 1000 ) { - GetResource(RES_ERR, m_error, buffer); + GetResource(RES_ERR, m_error, error); } else { - GetResource(RES_CBOT, m_error, buffer); + GetResource(RES_CBOT, m_error, error); } } } @@ -4385,7 +4386,9 @@ void CScript::New(Ui::CEdit* edit, const char* name) char *sf; int cursor1, cursor2, len, i, j; - GetResource(RES_TEXT, RT_SCRIPT_NEW, res); + std::string resStr; + GetResource(RES_TEXT, RT_SCRIPT_NEW, resStr); + strcpy(res, resStr.c_str()); if ( name[0] == 0 ) strcpy(text, res); else strcpy(text, name); diff --git a/src/script/script.h b/src/script/script.h index 7fd5555..3641dd9 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -74,7 +74,7 @@ public: bool IntroduceVirus(); int GetError(); - void GetError(char* buffer); + void GetError(std::string& error); void New(Ui::CEdit* edit, const char* name); bool SendScript(const char* text); diff --git a/src/ui/button.cpp b/src/ui/button.cpp index 348382d..810d365 100644 --- a/src/ui/button.cpp +++ b/src/ui/button.cpp @@ -60,12 +60,7 @@ bool CButton::Create(Math::Point pos, Math::Point dim, int icon, EventType event if ( icon == -1 ) { - char name[100]; - char* p; - - GetResource(RES_EVENT, eventType, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; + std::string name = GetResourceName(eventType); SetName(name); } diff --git a/src/ui/check.cpp b/src/ui/check.cpp index 362c930..6a92554 100644 --- a/src/ui/check.cpp +++ b/src/ui/check.cpp @@ -47,16 +47,11 @@ CCheck::~CCheck() bool CCheck::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) { - char name[100]; - char* p; - if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventType); - GetResource(RES_EVENT, eventType, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; + std::string name = GetResourceName(eventType); SetName(name); return true; diff --git a/src/ui/color.cpp b/src/ui/color.cpp index 623ff89..cbbc0dc 100644 --- a/src/ui/color.cpp +++ b/src/ui/color.cpp @@ -64,12 +64,7 @@ bool CColor::Create(Math::Point pos, Math::Point dim, int icon, EventType eventT if ( icon == -1 ) { - char name[100]; - char* p; - - GetResource(RES_EVENT, eventType, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; + std::string name = GetResourceName(eventType); SetName(name); } diff --git a/src/ui/control.cpp b/src/ui/control.cpp index bed84dd..501350e 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -57,9 +57,6 @@ CControl::~CControl() bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) { - char text[200]; - std::string str_text; - if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -72,17 +69,17 @@ bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType even pos.y = m_pos.y + m_dim.y; GlintCreate(pos); + std::string text; GetResource(RES_EVENT, m_eventType, text); - str_text = std::string(text); - auto p = str_text.find("\\"); - if ( p == std::string::npos ) + auto p = text.find("\\"); + if (p == std::string::npos) { if ( icon != -1 ) - m_tooltip = str_text; + m_tooltip = text; } else { - m_tooltip = str_text.substr(p + 1); + m_tooltip = text.substr(p + 1); } return true; @@ -837,5 +834,18 @@ bool CControl::Detect(Math::Point pos) pos.y <= m_pos.y + m_dim.y ); } +std::string CControl::GetResourceName(EventType eventType) +{ + std::string name; + GetResource(RES_EVENT, eventType, name); + auto index = name.find('\\'); + if (index != std::string::npos) + { + name = name.substr(0, index); + } + return name; +} + + } diff --git a/src/ui/control.h b/src/ui/control.h index aee7d1c..1ca07cf 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -112,6 +112,8 @@ protected: void DrawShadow(Math::Point pos, Math::Point dim, float deep=1.0f); virtual bool Detect(Math::Point pos); + std::string GetResourceName(EventType eventType); + protected: Gfx::CEngine* m_engine; Gfx::CParticle* m_particle; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 3aa3d73..bd20452 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -972,7 +972,6 @@ void ObjectAdd(ObjectList list[], ObjectType type) void ObjectWrite(FILE* file, ObjectList list[], int i) { char line[100]; - char res[100]; char* p; if ( list[i].total < 10 ) @@ -984,12 +983,14 @@ void ObjectWrite(FILE* file, ObjectList list[], int i) sprintf(line, "\\c;%dx \\n;\\l;", list[i].total); } + std::string res; GetResource(RES_OBJECT, list[i].type, res); - if ( res[0] == 0 ) return; - strcat(line, res); + if (res.empty()) return; + strcat(line, res.c_str()); strcat(line, "\\u "); - p = const_cast(GetHelpFilename(list[i].type).c_str()); + std::string helpFilename = GetHelpFilename(list[i].type); + p = const_cast(helpFilename.c_str()); if ( p[0] == 0 ) return; strcat(line, p+7); // skip "help\?\" p = strstr(line, ".txt"); @@ -1006,7 +1007,7 @@ void CDisplayInfo::CreateObjectsFile() CObject* pObj; ObjectType type; ObjectList list[200]; - char line[100]; + std::string line; int i; bool bRadar, bAtLeast; @@ -1038,7 +1039,7 @@ void CDisplayInfo::CreateObjectsFile() if ( bRadar ) { GetResource(RES_TEXT, RT_SATCOM_LIST, line); - fputs(line, file); + fputs(line.c_str(), file); bAtLeast = false; for ( i=0 ; i<200 ; i++ ) { @@ -1054,13 +1055,12 @@ void CDisplayInfo::CreateObjectsFile() if ( !bAtLeast ) { GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line, file); + fputs(line.c_str(), file); } - strcpy(line, "\n"); - fputs(line, file); + fputs("\n", file); GetResource(RES_TEXT, RT_SATCOM_BOT, line); - fputs(line, file); + fputs(line.c_str(), file); bAtLeast = false; for ( i=0 ; i<200 ; i++ ) { @@ -1101,13 +1101,12 @@ void CDisplayInfo::CreateObjectsFile() if ( !bAtLeast ) { GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line, file); + fputs(line.c_str(), file); } - strcpy(line, "\n"); - fputs(line, file); + fputs("\n", file); GetResource(RES_TEXT, RT_SATCOM_BUILDING, line); - fputs(line, file); + fputs(line.c_str(), file); bAtLeast = false; for ( i=0 ; i<200 ; i++ ) { @@ -1142,13 +1141,12 @@ void CDisplayInfo::CreateObjectsFile() if ( !bAtLeast ) { GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line, file); + fputs(line.c_str(), file); } - strcpy(line, "\n"); - fputs(line, file); + fputs("\n", file); GetResource(RES_TEXT, RT_SATCOM_FRET, line); - fputs(line, file); + fputs(line.c_str(), file); bAtLeast = false; for ( i=0 ; i<200 ; i++ ) { @@ -1170,13 +1168,12 @@ void CDisplayInfo::CreateObjectsFile() if ( !bAtLeast ) { GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line, file); + fputs(line.c_str(), file); } - strcpy(line, "\n"); - fputs(line, file); + fputs("\n", file); GetResource(RES_TEXT, RT_SATCOM_ALIEN, line); - fputs(line, file); + fputs(line.c_str(), file); bAtLeast = false; for ( i=0 ; i<200 ; i++ ) { @@ -1195,19 +1192,18 @@ void CDisplayInfo::CreateObjectsFile() if ( !bAtLeast ) { GetResource(RES_TEXT, RT_SATCOM_NULL, line); - fputs(line, file); + fputs(line.c_str(), file); } } else { GetResource(RES_TEXT, RT_SATCOM_ERROR1, line); - fputs(line, file); + fputs(line.c_str(), file); GetResource(RES_TEXT, RT_SATCOM_ERROR2, line); - fputs(line, file); + fputs(line.c_str(), file); } - strcpy(line, "\n"); - fputs(line, file); + fputs("\n", file); fclose(file); } diff --git a/src/ui/displaytext.cpp b/src/ui/displaytext.cpp index d88674a..5b3144d 100644 --- a/src/ui/displaytext.cpp +++ b/src/ui/displaytext.cpp @@ -127,9 +127,6 @@ void CDisplayText::DisplayError(Error err, CObject* pObj, float time) void CDisplayText::DisplayError(Error err, Math::Vector goal, float height, float dist, float time) { - TextType type; - char text[100]; - if ( err == ERR_OK ) return; #if 0 @@ -148,7 +145,7 @@ void CDisplayText::DisplayError(Error err, Math::Vector goal, float height, type = TT_WARNING; } #else - type = TT_WARNING; + TextType type = TT_WARNING; if ( err >= INFO_FIRST ) { type = TT_INFO; @@ -164,8 +161,9 @@ void CDisplayText::DisplayError(Error err, Math::Vector goal, float height, } #endif + std::string text; GetResource(RES_ERR, err, text); - DisplayText(text, goal, height, dist, time, type); + DisplayText(text.c_str(), goal, height, dist, time, type); } // Displays text. diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index a187688..271a8e7 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1798,8 +1798,10 @@ bool CEdit::ReadText(std::string filename, int addSize) res = main->GetInputBinding(slot).primary; if ( res != 0 ) { - if ( GetResource(RES_KEY, res, iName) ) + std::string iNameStr; + if ( GetResource(RES_KEY, res, iNameStr) ) { + strcpy(iName, iNameStr.c_str()); m_text[j] = ' '; m_format[j] = font; j ++; @@ -1817,9 +1819,13 @@ bool CEdit::ReadText(std::string filename, int addSize) res = main->GetInputBinding(slot).secondary; if ( res != 0 ) { - if ( GetResource(RES_KEY, res, iName) ) + if ( GetResource(RES_KEY, res, iNameStr) ) { - GetResource(RES_TEXT, RT_KEY_OR, text); + strcpy(iName, iNameStr.c_str()); + + std::string textStr; + GetResource(RES_TEXT, RT_KEY_OR, textStr); + strcpy(text, textStr.c_str()); n = 0; while ( text[n] != 0 ) { diff --git a/src/ui/group.cpp b/src/ui/group.cpp index 908ac19..64495e0 100644 --- a/src/ui/group.cpp +++ b/src/ui/group.cpp @@ -52,12 +52,7 @@ bool CGroup::Create(Math::Point pos, Math::Point dim, int icon, EventType eventT if ( icon == -1 ) { - char name[100]; - char* p; - - GetResource(RES_EVENT, eventType, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; + std::string name = GetResourceName(eventType); SetName(name); } diff --git a/src/ui/image.cpp b/src/ui/image.cpp index 9a14789..8f9b5ca 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -58,12 +58,7 @@ bool CImage::Create(Math::Point pos, Math::Point dim, int icon, EventType eventT if ( icon == -1 ) { - char name[100]; - char* p; - - GetResource(RES_EVENT, eventType, name); - p = strchr(name, '\\'); - if ( p != 0 ) *p = 0; + std::string name = GetResourceName(eventType); SetName(name); } diff --git a/src/ui/key.cpp b/src/ui/key.cpp index 1f8cff5..aacc8d8 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -19,16 +19,19 @@ #include "ui/key.h" #include "common/global.h" +#include "common/stringutils.h" #include namespace Ui { -void GetKeyName(char* name, unsigned int key) +static void GetKeyName(std::string& name, unsigned int key) { if (!GetResource(RES_KEY, key, name)) - sprintf(name, "Code %d", key); + { + name = StrUtils::Format("Code %d", key); + } } @@ -51,9 +54,9 @@ bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg CControl::Create(pos, dim, icon, eventMsg); - char name[100]; + std::string name; GetResource(RES_EVENT, eventMsg, name); - SetName(std::string(name)); + SetName(name); return true; } @@ -176,19 +179,24 @@ void CKey::Draw() float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; - char text[100]; - GetKeyName(text, m_binding.primary); + std::string keyName; + GetKeyName(keyName, m_binding.primary); if (m_binding.secondary != KEY_INVALID) { - GetResource(RES_TEXT, RT_KEY_OR, text+strlen(text)); - GetKeyName(text+strlen(text), m_binding.secondary); + std::string orText; + GetResource(RES_TEXT, RT_KEY_OR, orText); + keyName.append(orText); + + std::string secondaryKeyName; + GetKeyName(secondaryKeyName, m_binding.secondary); + keyName.append(secondaryKeyName); } Math::Point pos; pos.x = m_pos.x + m_dim.x * 0.5f; pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; - m_engine->GetText()->DrawText(std::string(text), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_CENTER, 0); + m_engine->GetText()->DrawText(keyName, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_CENTER, 0); m_dim = iDim; @@ -199,7 +207,7 @@ void CKey::Draw() pos.x = m_pos.x + (214.0f / 640.0f); pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; - m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0); + m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0); } void CKey::SetBinding(InputBinding b) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 407f8da..e07e40c 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -26,7 +26,7 @@ #include "common/misc.h" #include "common/profile.h" #include "common/restext.h" -#include "common/logger.h" +#include "common/stringutils.h" #include "object/robotmain.h" @@ -215,7 +215,7 @@ void CMainDialog::ChangePhase(Phase phase) CImage* pi; Math::Point pos, dim, ddim; float ox, oy, sx, sy; - char name[100]; + std::string name; char* gamer; int res, i, j; @@ -458,10 +458,10 @@ pb->SetState(STATE_SHADOW); } else { - strcpy(name, gamer); + name = gamer; } - pe->SetText(name); - pe->SetCursor(strlen(name), 0); + pe->SetText(name.c_str()); + pe->SetCursor(name.length(), 0); pe->SetFocus(true); pos.x = 380.0f/640.0f; @@ -4019,7 +4019,7 @@ void CMainDialog::UpdatePerso() CColor* pc; CSlider* ps; Gfx::Color color; - char name[100]; + std::string name; int i; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -4434,8 +4434,9 @@ void CMainDialog::IOReadList() // invalid index if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) { - GetResource(RES_TEXT, RT_IO_NEW, name); - pl->SetItemName(m_saveList.size(), name); + std::string nameStr; + GetResource(RES_TEXT, RT_IO_NEW, nameStr); + pl->SetItemName(m_saveList.size(), nameStr.c_str()); } pl->SetSelect(m_saveList.size()); @@ -6026,7 +6027,7 @@ void CMainDialog::StartAbort() CWindow* pw; CButton* pb; Math::Point pos, dim; - char name[100]; + std::string name; StartDialog(Math::Point(0.3f, 0.8f), true, false, false); m_bDialogDelete = false; @@ -6105,7 +6106,7 @@ void CMainDialog::StartDeleteObject() CWindow* pw; CButton* pb; Math::Point pos, dim; - char name[100]; + std::string name; StartDialog(Math::Point(0.7f, 0.3f), false, true, true); m_bDialogDelete = true; @@ -6139,21 +6140,22 @@ void CMainDialog::StartDeleteGame(char *gamer) CWindow* pw; CButton* pb; Math::Point pos, dim; - char name[100]; - char text[100]; StartDialog(Math::Point(0.7f, 0.3f), false, true, true); m_bDialogDelete = true; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); - if ( pw == 0 ) return; + if (pw == nullptr) + return; + + std::string name; pos.x = 0.00f; pos.y = 0.50f; dim.x = 1.00f; dim.y = 0.05f; GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); - sprintf(text, name, gamer); + std::string text = StrUtils::Format(name.c_str(), gamer); pw->CreateLabel(pos, dim, -1, EVENT_DIALOG_LABEL, text); pb = static_cast(pw->SearchControl(EVENT_DIALOG_OK)); @@ -6175,12 +6177,14 @@ void CMainDialog::StartQuit() CWindow* pw; CButton* pb; Math::Point pos, dim; - char name[100]; StartDialog(Math::Point(0.6f, 0.3f), false, true, true); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); - if ( pw == 0 ) return; + if (pw == nullptr) + return; + + std::string name; pos.x = 0.00f; pos.y = 0.50f; @@ -6208,7 +6212,6 @@ void CMainDialog::StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCance CWindow* pw; CButton* pb; Math::Point pos, ddim; - char name[100]; StartSuspend(); @@ -6247,6 +6250,8 @@ void CMainDialog::StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCance m_bDialogFire = bFire; + std::string name; + pos.x = (1.0f-dim.x)/2.0f; pos.y = (1.0f-dim.y)/2.0f; pw = m_interface->CreateWindows(pos, dim, bFire?12:8, EVENT_WINDOW9); diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index d33482c..f6dce4b 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -97,7 +97,6 @@ bool CMainShort::CreateShortcuts() ObjectType type; Math::Point pos, dim; int i, rank, icon; - char name[100]; if ( m_main->GetFixScene() ) return false; @@ -208,10 +207,11 @@ bool CMainShort::CreateShortcuts() m_shortcuts[rank] = pObj; pc = m_interface->SearchControl(table_sc_em[rank]); - if ( pc != 0 ) + if ( pc != nullptr ) { - pObj->GetTooltipName(name); - pc->SetTooltip(name); + std::string tooltipName; + pObj->GetTooltipName(tooltipName); + pc->SetTooltip(tooltipName); } rank ++; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index e44a465..ba28a0a 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -97,7 +97,6 @@ bool CStudio::EventProcess(const Event &event) CWindow* pw; CEdit* edit; CSlider* slider; - char res[100]; if ( m_dialog != SD_NULL ) // dialogue exists? { @@ -184,17 +183,17 @@ bool CStudio::EventProcess(const Event &event) if ( event.type == EVENT_STUDIO_COMPILE ) // compile? { - char buffer[100]; - if ( m_script->GetScript(edit) ) // compile { + std::string res; GetResource(RES_TEXT, RT_STUDIO_COMPOK, res); SetInfoText(res, false); } else { - m_script->GetError(buffer); - SetInfoText(buffer, false); + std::string error; + m_script->GetError(error); + SetInfoText(error, false); } } @@ -218,9 +217,9 @@ bool CStudio::EventProcess(const Event &event) } else { - char buffer[100]; - m_script->GetError(buffer); - SetInfoText(buffer, false); + std::string error; + m_script->GetError(error); + SetInfoText(error, false); } } } @@ -344,7 +343,6 @@ bool CStudio::EventFrame(const Event &event) CList* list; float time; int cursor1, cursor2, iCursor1, iCursor2; - char res[100]; m_time += event.rTime; m_fixInfoTextTime -= event.rTime; @@ -363,6 +361,7 @@ bool CStudio::EventFrame(const Event &event) m_bRunning = false; UpdateFlux(); // stop AdjustEditScript(); + std::string res; GetResource(RES_TEXT, RT_STUDIO_PROGSTOP, res); SetInfoText(res, false); @@ -558,7 +557,6 @@ void CStudio::StartEditScript(CScript *script, std::string name, int rank) CButton* button; CSlider* slider; CList* list; - char res[100]; m_script = script; m_rank = rank; @@ -575,28 +573,33 @@ void CStudio::StartEditScript(CScript *script, std::string name, int rank) m_script->SetStepMode(!m_bRealTime); button = static_cast< CButton* >(m_interface->SearchControl(EVENT_BUTTON_QUIT)); - if ( button != 0 ) - { + if (button != nullptr) button->ClearState(STATE_VISIBLE); - } pos = m_editFinalPos = m_editActualPos = m_main->GetWindowPos(); dim = m_editFinalDim = m_editActualDim = m_main->GetWindowDim(); pw = m_interface->CreateWindows(pos, dim, 8, EVENT_WINDOW3); - if ( pw == nullptr ) return; + if (pw == nullptr) + return; + pw->SetState(STATE_SHADOW); pw->SetRedim(true); // before SetName! pw->SetMovable(true); pw->SetClosable(true); + + std::string res; GetResource(RES_TEXT, RT_STUDIO_TITLE, res); pw->SetName(res); + pw->SetMinDim(Math::Point(0.49f, 0.50f)); pw->SetMaximized(m_bEditMaximized); pw->SetMinimized(m_bEditMinimized); m_main->SetEditFull(m_bEditMaximized); edit = pw->CreateEdit(pos, dim, 0, EVENT_STUDIO_EDIT); - if ( edit == 0 ) return; + if (edit == nullptr) + return; + edit->SetState(STATE_SHADOW); edit->SetInsideScroll(false); //? if ( m_bRunning ) edit->SetEdit(false); @@ -851,7 +854,6 @@ bool CStudio::StopEditScript(bool bCancel) CWindow* pw; CEdit* edit; CButton* button; - char buffer[100]; pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); if ( pw == nullptr ) return false; @@ -863,8 +865,9 @@ bool CStudio::StopEditScript(bool bCancel) { if ( !m_script->GetScript(edit) ) // compile { - m_script->GetError(buffer); - SetInfoText(buffer, false); + std::string error; + m_script->GetError(error); + SetInfoText(error, false); return false; } } @@ -892,8 +895,6 @@ bool CStudio::StopEditScript(bool bCancel) void CStudio::SetInfoText(std::string text, bool bClickable) { - char res[100]; - if ( bClickable && m_fixInfoTextTime > 0.0f ) return; if ( !bClickable ) m_fixInfoTextTime = 8.0f; @@ -911,6 +912,7 @@ void CStudio::SetInfoText(std::string text, bool bClickable) if ( bClickable ) { + std::string res; GetResource(RES_TEXT, RT_STUDIO_LISTTT, res); list->SetTooltip(res); list->SetState(STATE_ENABLE); @@ -1029,7 +1031,7 @@ void CStudio::StartDialog(StudioDialog type) CList* pli; CEdit* pe; Math::Point pos, dim; - char name[100]; + std::string name; m_dialog = type; @@ -1476,8 +1478,6 @@ void CStudio::UpdateDialogPublic() CWindow* pw; CCheck* pc; CLabel* pl; - char name[100]; - //char text[MAX_FNAME+100]; pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == nullptr ) return; @@ -1497,7 +1497,7 @@ void CStudio::UpdateDialogPublic() pl = static_cast< CLabel* >(pw->SearchControl(EVENT_DIALOG_LABEL1)); if ( pl != 0 ) { - GetResource(RES_TEXT, RT_IO_LIST, name); + //? GetResource(RES_TEXT, RT_IO_LIST, name); pl->SetName(SearchDirectory(false).c_str(), false); } } diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 6e082e6..ed18ce4 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -788,7 +788,7 @@ bool CWindow::GetFixed() void CWindow::AdjustButtons() { - char res[100]; + std::string res; if ( m_buttonFull != 0 ) { @@ -796,13 +796,13 @@ void CWindow::AdjustButtons() { m_buttonFull->SetIcon(54); GetResource(RES_TEXT, RT_WINDOW_STANDARD, res); - m_buttonFull->SetTooltip(std::string(res)); + m_buttonFull->SetTooltip(res); } else { m_buttonFull->SetIcon(52); GetResource(RES_TEXT, RT_WINDOW_MAXIMIZED, res); - m_buttonFull->SetTooltip(std::string(res)); + m_buttonFull->SetTooltip(res); } } @@ -812,13 +812,13 @@ void CWindow::AdjustButtons() { m_buttonReduce->SetIcon(54); GetResource(RES_TEXT, RT_WINDOW_STANDARD, res); - m_buttonReduce->SetTooltip(std::string(res)); + m_buttonReduce->SetTooltip(res); } else { m_buttonReduce->SetIcon(51); GetResource(RES_TEXT, RT_WINDOW_MINIMIZED, res); - m_buttonReduce->SetTooltip(std::string(res)); + m_buttonReduce->SetTooltip(res); } } @@ -826,7 +826,7 @@ void CWindow::AdjustButtons() { m_buttonClose->SetIcon(11); // x GetResource(RES_TEXT, RT_WINDOW_CLOSE, res); - m_buttonClose->SetTooltip(std::string(res)); + m_buttonClose->SetTooltip(res); } } -- cgit v1.2.3-1-g7c22 From 114cbec8a9859f19d4234659bd4951f540825dd3 Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Mon, 9 Dec 2013 09:51:56 +0100 Subject: Never cache Data, Sound and Music paths Let them always be either auto-detected, defined on the command-line or written in the configuration file --- src/app/app.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 09fb233..d332931 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -423,11 +423,6 @@ bool CApplication::Create() return false; } -#if !defined(PLATFORM_MACOSX) - // On Mac OSX, the bundle can potentially change place, it doesn't make sense to cache it to the configuration file - GetProfile().SetLocalProfileString("Resources", "Data", m_dataPath); -#endif - SetLanguage(m_language); //Create the sound instance. @@ -440,17 +435,6 @@ bool CApplication::Create() m_sound->Create(true); -#if !defined(PLATFORM_MACOSX) - // On Mac OSX, the bundle can potentially change place, it doesn't make sense to cache it to the configuration file - - // Cache sound files - if (defaultValues) - { - GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND)); - GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC)); - } -#endif - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Sound", path)) { m_sound->CacheAll(path); -- cgit v1.2.3-1-g7c22 From fe3f9ea38cfae89fdd83d4c3fe79ea355f50bce9 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 19 Dec 2013 22:41:16 +0100 Subject: Sound support changes * removed 2d sound * fixed listener orientation (propably issue #235) * removed unused code and minor refactoring --- src/app/app.cpp | 2 +- src/sound/oalsound/alsound.cpp | 153 ++++------------------------------------- src/sound/oalsound/alsound.h | 26 ++----- src/sound/oalsound/channel.cpp | 14 +--- src/sound/oalsound/channel.h | 4 +- src/sound/sound.cpp | 32 +++------ src/sound/sound.h | 34 +++------ src/ui/maindialog.cpp | 26 ------- 8 files changed, 42 insertions(+), 249 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index d332931..32fec89 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -433,7 +433,7 @@ bool CApplication::Create() m_sound = new CSoundInterface(); #endif - m_sound->Create(true); + m_sound->Create(); if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Sound", path)) { diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 992b8b2..7f325c1 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -26,7 +26,6 @@ ALSound::ALSound() { m_enabled = false; - m_3D = false; m_audioVolume = 1.0f; m_musicVolume = 1.0f; m_currentMusic = nullptr; @@ -77,7 +76,7 @@ void ALSound::CleanUp() } -bool ALSound::Create(bool b3D) +bool ALSound::Create() { CleanUp(); @@ -109,25 +108,6 @@ bool ALSound::Create(bool b3D) } -void ALSound::SetSound3D(bool bMode) -{ - m_3D = bMode; -} - - -bool ALSound::GetSound3D() -{ - return m_3D; -} - - -bool ALSound::GetSound3DCap() -{ - // TODO stub! need to be implemented - return true; -} - - bool ALSound::GetEnable() { return m_enabled; @@ -168,7 +148,7 @@ int ALSound::GetMusicVolume() } -bool ALSound::Cache(Sound sound, std::string filename) +bool ALSound::Cache(Sound sound, const std::string &filename) { Buffer *buffer = new Buffer(); if (buffer->LoadFromFile(filename, sound)) @@ -179,7 +159,7 @@ bool ALSound::Cache(Sound sound, std::string filename) return false; } -bool ALSound::CacheMusic(std::string filename) +bool ALSound::CacheMusic(const std::string &filename) { if (m_music.find(filename) == m_music.end()) { @@ -337,7 +317,7 @@ int ALSound::Play(Sound sound, float amplitude, float frequency, bool bLoop) } -int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequency, bool bLoop) +int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float frequency, bool bLoop) { if (!m_enabled) { @@ -364,14 +344,7 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc } Position(channel, pos); - if (!m_3D) - { - ComputeVolumePan2D(channel, pos); - } - else - { - m_channels[channel]->SetVolumeAtrib(1.0f); - } + m_channels[channel]->SetVolumeAtrib(1.0f); // setting initial values m_channels[channel]->SetStartAmplitude(amplitude); @@ -421,7 +394,7 @@ bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float t } -bool ALSound::Position(int channel, Math::Vector pos) +bool ALSound::Position(int channel, const Math::Vector &pos) { if (!m_enabled) return false; @@ -431,20 +404,7 @@ bool ALSound::Position(int channel, Math::Vector pos) return false; } - if (m_3D) - { - m_channels[channel]->SetPan(pos); - } - else - { - ComputeVolumePan2D(channel, pos); - - if (!m_channels[channel]->HasEnvelope()) - { - float volume = m_channels[channel]->GetStartAmplitude(); - m_channels[channel]->SetVolume(powf(volume * m_channels[channel]->GetVolumeAtrib(), 0.2f) * m_audioVolume); - } - } + m_channels[channel]->SetPosition(pos); return true; } @@ -585,38 +545,16 @@ void ALSound::FrameMove(float delta) } -void ALSound::SetListener(Math::Vector eye, Math::Vector lookat) +void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) { m_eye = eye; m_lookat = lookat; - if (m_3D) - { - float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f}; - alListener3f(AL_POSITION, eye.x, eye.y, eye.z); - alListenerfv(AL_ORIENTATION, orientation); - } - else - { - float orientation[] = {0.0f, 0.0f, 0.0f, 0.f, 1.f, 0.f}; - alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); - alListenerfv(AL_ORIENTATION, orientation); + Math::Vector forward = lookat - eye; + forward.Normalize(); + float orientation[] = {forward.x, forward.y, forward.z, 0.f, -1.0f, 0.0f}; - // recalculate sound position - for (auto it : m_channels) - { - if (it.second->IsPlaying()) - { - Math::Vector pos = it.second->GetPosition(); - ComputeVolumePan2D(it.first, pos); - - if (!it.second->HasEnvelope()) - { - float volume = it.second->GetStartAmplitude(); - it.second->SetVolume(powf(volume * it.second->GetVolumeAtrib(), 0.2f) * m_audioVolume); - } - } - } - } + alListener3f(AL_POSITION, eye.x, eye.y, eye.z); + alListenerfv(AL_ORIENTATION, orientation); } bool ALSound::PlayMusic(int rank, bool bRepeat) @@ -626,7 +564,7 @@ bool ALSound::PlayMusic(int rank, bool bRepeat) return PlayMusic(filename.str(), bRepeat); } -bool ALSound::PlayMusic(std::string filename, bool bRepeat) +bool ALSound::PlayMusic(const std::string &filename, bool bRepeat) { if (!m_enabled) { @@ -706,66 +644,3 @@ void ALSound::SuspendMusic() m_currentMusic->Stop(); } - - -void ALSound::ComputeVolumePan2D(int channel, Math::Vector &pos) -{ - float dist, a, g; - m_channels[channel]->SetPosition(pos); - - if (VectorsEqual(pos, m_eye)) - { - m_channels[channel]->SetVolumeAtrib(1.0f); // maximum volume - m_channels[channel]->SetPan(Math::Vector()); // at the center - return; - } - - dist = Distance(pos, m_eye); - if ( dist >= 110.0f ) // very far? - { - m_channels[channel]->SetVolumeAtrib(0.0f); // silence - m_channels[channel]->SetPan(Math::Vector()); // at the center - return; - } - else if ( dist <= 10.0f ) // very close? - { - m_channels[channel]->SetVolumeAtrib(1.0f); // maximum volume - m_channels[channel]->SetPan(Math::Vector()); // at the center - return; - } - m_channels[channel]->SetVolumeAtrib(1.0f - ((dist - 10.0f) / 100.0f)); - - Math::Vector one = Math::Vector(1.0f, 0.0f, 0.0f); - float angle_a = Angle(Math::Vector(m_lookat.x - m_eye.x, m_lookat.z - m_eye.z, 0.0f), one); - float angle_g = Angle(Math::Vector(pos.x - m_eye.x, pos.z - m_eye.z, 0.0f), one); - - a = fmodf(angle_a, Math::PI * 2.0f); - g = fmodf(angle_g, Math::PI * 2.0f); - - if ( a < 0.0f ) - { - a += Math::PI * 2.0f; - } - if ( g < 0.0f ) - { - g += Math::PI * 2.0f; - } - - if ( a < g ) - { - if (a + Math::PI * 2.0f - g < g - a ) - { - a += Math::PI * 2.0f; - } - } - else - { - if ( g + Math::PI * 2.0f - a < a - g ) - { - g += Math::PI * 2.0f; - } - } - - m_channels[channel]->SetPan( Math::Vector(0.0f, 0.0f, sinf(g - a)) ); -} - diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index cd44ae9..2fdcff5 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -41,55 +41,43 @@ public: ALSound(); ~ALSound(); - bool Create(bool b3D); - bool Cache(Sound, std::string); - bool CacheMusic(std::string); + bool Create(); + bool Cache(Sound, const std::string &); + bool CacheMusic(const std::string &); bool GetEnable(); - void SetSound3D(bool bMode); - bool GetSound3D(); - bool GetSound3DCap(); - void SetAudioVolume(int volume); int GetAudioVolume(); void SetMusicVolume(int volume); int GetMusicVolume(); - void SetListener(Math::Vector eye, Math::Vector lookat); + void SetListener(const Math::Vector &eye, const Math::Vector &lookat); void FrameMove(float rTime); int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); - int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); + int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); bool FlushEnvelope(int channel); bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper); - bool Position(int channel, Math::Vector pos); + bool Position(int channel, const Math::Vector &pos); bool Frequency(int channel, float frequency); bool Stop(int channel); bool StopAll(); bool MuteAll(bool bMute); bool PlayMusic(int rank, bool bRepeat); - bool PlayMusic(std::string filename, bool bRepeat); + bool PlayMusic(const std::string &filename, bool bRepeat); bool RestartMusic(); void SuspendMusic(); void StopMusic(); bool IsPlayingMusic(); - // plugin interface - std::string PluginName(); - int PluginVersion(); - void InstallPlugin(); - bool UninstallPlugin(std::string &); - private: void CleanUp(); int GetPriority(Sound); bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded); - void ComputeVolumePan2D(int channel, Math::Vector &pos); bool m_enabled; - bool m_3D; float m_audioVolume; float m_musicVolume; ALCdevice* m_device; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 4d89df5..b053316 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -75,7 +75,7 @@ bool Channel::Play() } -bool Channel::SetPan(Math::Vector pos) +bool Channel::SetPosition(const Math::Vector &pos) { if (!m_ready || m_buffer == nullptr) { @@ -92,18 +92,6 @@ bool Channel::SetPan(Math::Vector pos) } -void Channel::SetPosition(Math::Vector pos) -{ - m_position = pos; -} - - -Math::Vector Channel::GetPosition() -{ - return m_position; -} - - bool Channel::SetFrequency(float freq) { if (!m_ready || m_buffer == nullptr) diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 2930f26..0c6cafc 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -52,9 +52,7 @@ public: bool Play(); bool Stop(); - bool SetPan(Math::Vector); - void SetPosition(Math::Vector); - Math::Vector GetPosition(); + bool SetPosition(const Math::Vector &); bool SetFrequency(float); float GetFrequency(); diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index d392612..d197b81 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -36,12 +36,12 @@ CSoundInterface::~CSoundInterface() { } -bool CSoundInterface::Create(bool b3D) +bool CSoundInterface::Create() { return true; } -void CSoundInterface::CacheAll(std::string path) +void CSoundInterface::CacheAll(const std::string &path) { for ( int i = 1; i < SOUND_MAX; i++ ) { @@ -52,7 +52,7 @@ void CSoundInterface::CacheAll(std::string path) } } -void CSoundInterface::AddMusicFiles(std::string path) +void CSoundInterface::AddMusicFiles(const std::string &path) { m_soundPath = path; CacheMusic("Intro1.ogg"); @@ -61,12 +61,12 @@ void CSoundInterface::AddMusicFiles(std::string path) CacheMusic("music011.ogg"); } -bool CSoundInterface::Cache(Sound bSound, std::string bFile) +bool CSoundInterface::Cache(Sound bSound, const std::string &bFile) { return true; } -bool CSoundInterface::CacheMusic(std::string bFile) +bool CSoundInterface::CacheMusic(const std::string &bFile) { return true; } @@ -76,20 +76,6 @@ bool CSoundInterface::GetEnable() return true; } -void CSoundInterface::SetSound3D(bool bMode) -{ -} - -bool CSoundInterface::GetSound3D() -{ - return true; -} - -bool CSoundInterface::GetSound3DCap() -{ - return true; -} - void CSoundInterface::SetAudioVolume(int volume) { } @@ -108,7 +94,7 @@ int CSoundInterface::GetMusicVolume() return 0; } -void CSoundInterface::SetListener(Math::Vector eye, Math::Vector lookat) +void CSoundInterface::SetListener(const Math::Vector &eye, const Math::Vector &lookat) { } @@ -121,7 +107,7 @@ int CSoundInterface::Play(Sound sound, float amplitude, float frequency, bool bL return 0; } -int CSoundInterface::Play(Sound sound, Math::Vector pos, float amplitude, float frequency, bool bLoop) +int CSoundInterface::Play(Sound sound, const Math::Vector &pos, float amplitude, float frequency, bool bLoop) { return 0; } @@ -136,7 +122,7 @@ bool CSoundInterface::AddEnvelope(int channel, float amplitude, float frequency, return true; } -bool CSoundInterface::Position(int channel, Math::Vector pos) +bool CSoundInterface::Position(int channel, const Math::Vector &pos) { return true; } @@ -166,7 +152,7 @@ bool CSoundInterface::PlayMusic(int rank, bool bRepeat) return true; } -bool CSoundInterface::PlayMusic(std::string filename, bool bRepeat) +bool CSoundInterface::PlayMusic(const std::string &filename, bool bRepeat) { return true; } diff --git a/src/sound/sound.h b/src/sound/sound.h index 9ccc1b6..eee0b82 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -153,17 +153,16 @@ public: virtual ~CSoundInterface(); /** Function to initialize sound device - * \param b3D - enable support for 3D sound */ - virtual bool Create(bool b3D); + virtual bool Create(); /** Function called to cache all sound effect files. * Function calls \link CSoundInterface::Cache() \endlink for each file */ - void CacheAll(std::string path); + void CacheAll(const std::string &path); /** Function called to add all music files to list */ - void AddMusicFiles(std::string path); + void AddMusicFiles(const std::string &path); /** Function called to cache sound effect file. * This function is called by plugin interface for each file. @@ -171,35 +170,20 @@ public: * \param bFile - file to load * \return return true on success */ - virtual bool Cache(Sound bSound, std::string bFile); + virtual bool Cache(Sound bSound, const std::string &bFile); /** Function called to cache music file. * This function is called by CRobotMain for each file used in the mission. * \param bFile - file to load * \return return true on success */ - virtual bool CacheMusic(std::string bFile); + virtual bool CacheMusic(const std::string &bFile); /** Return if plugin is enabled * \return return true if plugin is enabled */ virtual bool GetEnable(); - /** Change sound mode to 2D/3D - * \param bMode - true to enable 3D sound - */ - virtual void SetSound3D(bool bMode); - - /** Return if we use 3D sound - * \return true if we have 3D sound enabled - */ - virtual bool GetSound3D(); - - /** Return if we have 3D sound capable card - * \return true for 3D sound support - */ - virtual bool GetSound3DCap(); - /** Change global sound volume * \param volume - range from 0 to MAXVOLUME */ @@ -224,7 +208,7 @@ public: * \param eye - position of listener * \param lookat - direction listener is looking at */ - virtual void SetListener(Math::Vector eye, Math::Vector lookat); + virtual void SetListener(const Math::Vector &eye, const Math::Vector &lookat); /** Update data each frame * \param rTime - time since last update @@ -248,7 +232,7 @@ public: * \param bLoop - loop sound * \return identifier of channel that sound will be played on */ - virtual int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); + virtual int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false); /** Remove all operations that would be made on sound in channel. * \param channel - channel to work on @@ -271,7 +255,7 @@ public: * \param pos - new positino of a sound * \return return true on success */ - virtual bool Position(int channel, Math::Vector pos); + virtual bool Position(int channel, const Math::Vector &pos); /** Set sound frequency * \param channel - channel to work on @@ -309,7 +293,7 @@ public: * \param bRepeat - repeat playing * \return return true on success */ - virtual bool PlayMusic(std::string filename, bool bRepeat); + virtual bool PlayMusic(const std::string &filename, bool bRepeat); /** Restart music * @return return true on success diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 407f8da..720eb66 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -1522,13 +1522,6 @@ pos.y -= 0.048f; pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); // #endif - ddim.x = dim.x*6; - ddim.y = dim.y*0.5f; - pos.x = ox+sx*10; - pos.y = 0.55f; - pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_SOUND3D); - pc->SetState(STATE_SHADOW); - ddim.x = dim.x*3; ddim.y = dim.y*1; pos.x = ox+sx*10; @@ -2913,12 +2906,6 @@ bool CMainDialog::EventProcess(const Event &event) ChangeSetupButtons(); break; - case EVENT_INTERFACE_SOUND3D: - m_sound->SetSound3D(!m_sound->GetSound3D()); - ChangeSetupButtons(); - UpdateSetupButtons(); - break; - case EVENT_INTERFACE_SILENT: m_sound->SetAudioVolume(0); m_sound->SetMusicVolume(0); @@ -5456,13 +5443,6 @@ void CMainDialog::UpdateSetupButtons() value = static_cast(m_sound->GetMusicVolume()); ps->SetVisibleValue(value); } - - pc = static_cast(pw->SearchControl(EVENT_INTERFACE_SOUND3D)); - if ( pc != 0 ) - { - pc->SetState(STATE_CHECK, m_sound->GetSound3D()); - pc->SetState(STATE_ENABLE, m_sound->GetSound3DCap()); - } } // Updates the engine function of the buttons after the setup phase. @@ -5564,7 +5544,6 @@ void CMainDialog::SetupMemorize() GetProfile().SetLocalProfileInt("Setup", "TotoMode", m_engine->GetTotoMode()); GetProfile().SetLocalProfileInt("Setup", "AudioVolume", m_sound->GetAudioVolume()); GetProfile().SetLocalProfileInt("Setup", "MusicVolume", m_sound->GetMusicVolume()); - GetProfile().SetLocalProfileInt("Setup", "Sound3D", m_sound->GetSound3D()); GetProfile().SetLocalProfileInt("Setup", "EditIndentMode", m_engine->GetEditIndentMode()); GetProfile().SetLocalProfileInt("Setup", "EditIndentValue", m_engine->GetEditIndentValue()); @@ -5802,11 +5781,6 @@ void CMainDialog::SetupRecall() m_sound->SetMusicVolume(iValue); } - if ( GetProfile().GetLocalProfileInt("Setup", "Sound3D", iValue) ) - { - m_sound->SetSound3D(iValue == 1); - } - if ( GetProfile().GetLocalProfileInt("Setup", "EditIndentMode", iValue) ) { m_engine->SetEditIndentMode(iValue); -- cgit v1.2.3-1-g7c22 From 95661918ce5da32cce84055e80fcc15343591638 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 20 Dec 2013 20:18:30 +0100 Subject: Some further refactoring and test corrections --- src/ui/displayinfo.cpp | 38 +++++++++++++++++++++++-------------- src/ui/studio.cpp | 2 +- test/unit/ui/edit_test.cpp | 3 ++- test/unit/ui/mocks/text_mock.h | 16 +++++++++++++--- test/unit/ui/stubs/restext_stub.cpp | 2 +- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index bd20452..79eb38a 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -23,6 +23,7 @@ #include "common/iman.h" #include "common/misc.h" #include "common/restext.h" +#include "common/stringutils.h" #include "graphics/core/light.h" #include "graphics/engine/engine.h" @@ -971,32 +972,41 @@ void ObjectAdd(ObjectList list[], ObjectType type) void ObjectWrite(FILE* file, ObjectList list[], int i) { - char line[100]; - char* p; + std::string line; if ( list[i].total < 10 ) { - sprintf(line, "\\c; %dx \\n;\\l;", list[i].total); + line = StrUtils::Format("\\c; %dx \\n;\\l;", list[i].total); } else { - sprintf(line, "\\c;%dx \\n;\\l;", list[i].total); + line = StrUtils::Format("\\c;%dx \\n;\\l;", list[i].total); } std::string res; GetResource(RES_OBJECT, list[i].type, res); - if (res.empty()) return; - strcat(line, res.c_str()); + if (res.empty()) + return; + + line += res; + + line += "\\u "; - strcat(line, "\\u "); std::string helpFilename = GetHelpFilename(list[i].type); - p = const_cast(helpFilename.c_str()); - if ( p[0] == 0 ) return; - strcat(line, p+7); // skip "help\?\" - p = strstr(line, ".txt"); - if ( p != 0 ) *p = 0; - strcat(line, ";\n"); - fputs(line, file); + if (helpFilename.empty()) + return; + + line += helpFilename.substr(7); // skip "help\?\" + + auto pos = line.find(".txt"); + if (pos != std::string::npos) + { + line = line.substr(0, pos); + } + + line += ";\n"; + + fputs(line.c_str(), file); } // Creates the file containing the list of objects. diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index ba28a0a..fb4dd3d 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1497,7 +1497,7 @@ void CStudio::UpdateDialogPublic() pl = static_cast< CLabel* >(pw->SearchControl(EVENT_DIALOG_LABEL1)); if ( pl != 0 ) { - //? GetResource(RES_TEXT, RT_IO_LIST, name); + // GetResource(RES_TEXT, RT_IO_LIST, name); // TODO: unused? pl->SetName(SearchDirectory(false).c_str(), false); } } diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index 21af00f..4a4063e 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -51,6 +51,7 @@ protected: }; using ::testing::_; +using ::testing::An; using ::testing::Return; TEST_F(CEditTest, WriteTest) @@ -58,7 +59,7 @@ 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(_, _, _, _)).WillOnce(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); diff --git a/test/unit/ui/mocks/text_mock.h b/test/unit/ui/mocks/text_mock.h index f38b977..b9af6d3 100644 --- a/test/unit/ui/mocks/text_mock.h +++ b/test/unit/ui/mocks/text_mock.h @@ -15,11 +15,21 @@ public: { }; - MOCK_METHOD4(GetCharWidth, float(Gfx::UTF8Char, Gfx::FontType, float, float)); + 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(const std::string &, Gfx::FontType, float)); + 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/restext_stub.cpp b/test/unit/ui/stubs/restext_stub.cpp index 004da19..fa47da6 100644 --- a/test/unit/ui/stubs/restext_stub.cpp +++ b/test/unit/ui/stubs/restext_stub.cpp @@ -1,6 +1,6 @@ #include "common/restext.h" -bool GetResource(ResType /* type */, int /* num */, char* /* text */) +bool GetResource(ResType /* type */, int /* num */, std::string& /* text */) { return true; } -- cgit v1.2.3-1-g7c22 From d9283e2afa4cea4790bbcaf4fec3e645d15452b2 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 20 Dec 2013 20:19:21 +0100 Subject: Fix problem with gtest and pthread on some systems --- CMakeLists.txt | 3 +++ test/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4c3e39..482186f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,9 @@ set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS} set(COLOBOT_CXX_FLAGS_RELEASE "-O2") set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") +# Flags for gtest +set(COLOBOT_GTEST_CXX_FLAGS "-pthread") + # Asserts can be enabled/disabled regardless of build type option(ASSERTS "Enable assert()s" ON) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2618698..e6c67d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ # Compile flags as defined in global CMakeLists -set(CMAKE_CXX_FLAGS "${COLOBOT_CXX_FLAGS} ${MXE_CFLAGS}") +set(CMAKE_CXX_FLAGS "${COLOBOT_CXX_FLAGS} ${MXE_CFLAGS} ${COLOBOT_GTEST_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE ${COLOBOT_CXX_FLAGS_RELEASE}) set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) -- cgit v1.2.3-1-g7c22 From 99668cb4d152bd753e7673380f4e52929d46942d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 22 Dec 2013 21:18:45 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 5641495..b40048a 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5641495ff106199c1e564a4b60d3fca6bbf948a3 +Subproject commit b40048ad6a5a3257ee9390ff15e1addcaec733ab -- cgit v1.2.3-1-g7c22 From 813a1a7a13c5e03a1b6a58d8ffb3502cdf5ea863 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 24 Dec 2013 22:24:20 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b40048a..3ea02f8 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b40048ad6a5a3257ee9390ff15e1addcaec733ab +Subproject commit 3ea02f8481b98e37cb79c1545a9db2720c909521 -- cgit v1.2.3-1-g7c22 From d0285d688615beb62a5b9e742b8d4103371695c5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 18:53:32 +0100 Subject: Fixed AudioChange --- .gitignore | 3 +++ src/object/robotmain.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 122663d..6a031c6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ Makefile # Ignore KDevelop files .kdev4 *.kdev4 + +# Ignore gedit temp files +*~ diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 35ffe97..4b45a20 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4110,12 +4110,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (i < 10) { m_audioChange[i].pos = OpPos(line, "pos")*g_unit; - m_audioChange[i].dist = OpFloat(line, "dist", 8.0f)*g_unit; + m_audioChange[i].dist = OpFloat(line, "dist", 1000.0f)*g_unit; m_audioChange[i].type = OpTypeObject(line, "type", OBJECT_NULL); m_audioChange[i].min = OpInt(line, "min", 1); m_audioChange[i].max = OpInt(line, "max", 9999); - m_audioChange[i].powermin = OpInt(line, "powermin", -1); - m_audioChange[i].powermax = OpInt(line, "powermax", 100); + m_audioChange[i].powermin = OpFloat(line, "powermin", -1); + m_audioChange[i].powermax = OpFloat(line, "powermax", 100); OpString(line, "filename", m_audioChange[i].music); m_audioChange[i].repeat = OpInt(line, "repeat", 1); m_audioChange[i].changed = false; @@ -4911,14 +4911,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (i < 10) { m_endTake[i].pos = OpPos(line, "pos")*g_unit; - m_endTake[i].dist = OpFloat(line, "dist", 8.0f)*g_unit; + m_endTake[i].dist = OpFloat(line, "dist", (m_version < 2 ? 8.0f : 100.0f))*g_unit; m_endTake[i].type = OpTypeObject(line, "type", OBJECT_NULL); m_endTake[i].min = OpInt(line, "min", 1); m_endTake[i].max = OpInt(line, "max", 9999); if (m_version >= 2) { - m_endTake[i].powermin = OpInt(line, "powermin", -1); - m_endTake[i].powermax = OpInt(line, "powermax", 100); + m_endTake[i].powermin = OpFloat(line, "powermin", -1); + m_endTake[i].powermax = OpFloat(line, "powermax", 100); } else { @@ -6923,7 +6923,8 @@ void CRobotMain::UpdateAudio(bool frame) energyLevel = power->GetEnergy(); if (power->GetType() == OBJECT_ATOMIC) energyLevel *= 100; } - if (energyLevel < m_audioChange[t].powermin || energyLevel > m_audioChange[t].powermax) continue; + if (energyLevel < m_audioChange[t].powermin || energyLevel > m_audioChange[t].powermax) + continue; if (obj->GetTruck() == 0) oPos = obj->GetPosition(0); @@ -6939,7 +6940,7 @@ void CRobotMain::UpdateAudio(bool frame) if (nb >= m_audioChange[t].min && nb <= m_audioChange[t].max) { - CLogger::GetInstancePointer()->Debug("Changing music...\n"); + CLogger::GetInstancePointer()->Info("Changing music to \"%s\"\n", m_audioChange[t].music); m_sound->StopMusic(); m_sound->PlayMusic(std::string(m_audioChange[t].music), m_audioChange[t].repeat); m_audioChange[t].changed = true; -- cgit v1.2.3-1-g7c22 From f1e267b18e89efde079421b8907f8f793998da3e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 19:13:15 +0100 Subject: Fixed bug #240 - CAuto in produce() --- src/script/script.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 5cd21f9..1a70699 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1916,7 +1916,14 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user result->SetValInt(1); // error return true; } - object->SetActivity(false); + object->SetActivity(true); + + CAuto* automat = object->GetAuto(); + if (automat != nullptr) + { + automat->Init(); + } + script->m_main->CreateShortcuts(); } else if ( type == OBJECT_FLAGb || -- cgit v1.2.3-1-g7c22 From 55fd03ade36f30c5ac18b5e9037622d0872d9bf3 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 19:34:34 +0100 Subject: Added WSAD as secondary controls (#231) --- src/object/robotmain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 4b45a20..ba6e1c4 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -987,6 +987,10 @@ void CRobotMain::SetDefaultInputBindings() m_inputBindings[INPUT_SLOT_RIGHT ].primary = KEY(RIGHT); m_inputBindings[INPUT_SLOT_UP ].primary = KEY(UP); m_inputBindings[INPUT_SLOT_DOWN ].primary = KEY(DOWN); + m_inputBindings[INPUT_SLOT_LEFT ].secondary = KEY(a); + m_inputBindings[INPUT_SLOT_RIGHT ].secondary = KEY(d); + m_inputBindings[INPUT_SLOT_UP ].secondary = KEY(w); + m_inputBindings[INPUT_SLOT_DOWN ].secondary = KEY(s); m_inputBindings[INPUT_SLOT_GUP ].primary = VIRTUAL_KMOD(SHIFT); m_inputBindings[INPUT_SLOT_GDOWN ].primary = VIRTUAL_KMOD(CTRL); m_inputBindings[INPUT_SLOT_CAMERA ].primary = KEY(SPACE); -- cgit v1.2.3-1-g7c22 From 5661f5a413836307c7a2943ba32cfd17f92480ea Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 19:41:15 +0100 Subject: Fixed "default controls" button (#263) --- src/ui/maindialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 5e95685..7cbcef5 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -2881,7 +2881,7 @@ bool CMainDialog::EventProcess(const Event &event) break; case EVENT_INTERFACE_KDEF: - m_app->ResetKeyStates(); + m_main->SetDefaultInputBindings(); UpdateKey(); break; -- cgit v1.2.3-1-g7c22 From c8ec3f2020151543f2ebe61e94ea5d985927d20c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 19:43:11 +0100 Subject: Added "E" as a secondary action button As requested by @Emxx52 on IRC --- src/object/robotmain.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index ba6e1c4..22e8152 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -994,19 +994,20 @@ void CRobotMain::SetDefaultInputBindings() m_inputBindings[INPUT_SLOT_GUP ].primary = VIRTUAL_KMOD(SHIFT); m_inputBindings[INPUT_SLOT_GDOWN ].primary = VIRTUAL_KMOD(CTRL); m_inputBindings[INPUT_SLOT_CAMERA ].primary = KEY(SPACE); - m_inputBindings[INPUT_SLOT_CAMERA ].secondary = VIRTUAL_JOY(2); +// m_inputBindings[INPUT_SLOT_CAMERA ].secondary = VIRTUAL_JOY(2); m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP0); - m_inputBindings[INPUT_SLOT_DESEL ].secondary = VIRTUAL_JOY(6); +// m_inputBindings[INPUT_SLOT_DESEL ].secondary = VIRTUAL_JOY(6); m_inputBindings[INPUT_SLOT_ACTION ].primary = KEY(RETURN); - m_inputBindings[INPUT_SLOT_ACTION ].secondary = VIRTUAL_JOY(1); +// m_inputBindings[INPUT_SLOT_ACTION ].secondary = VIRTUAL_JOY(1); + m_inputBindings[INPUT_SLOT_ACTION ].secondary = KEY(e); m_inputBindings[INPUT_SLOT_NEAR ].primary = KEY(KP_PLUS); - m_inputBindings[INPUT_SLOT_NEAR ].secondary = VIRTUAL_JOY(5); +// m_inputBindings[INPUT_SLOT_NEAR ].secondary = VIRTUAL_JOY(5); m_inputBindings[INPUT_SLOT_AWAY ].primary = KEY(KP_MINUS); - m_inputBindings[INPUT_SLOT_AWAY ].secondary = VIRTUAL_JOY(4); +// m_inputBindings[INPUT_SLOT_AWAY ].secondary = VIRTUAL_JOY(4); m_inputBindings[INPUT_SLOT_NEXT ].primary = KEY(TAB); - m_inputBindings[INPUT_SLOT_NEXT ].secondary = VIRTUAL_JOY(3); +// m_inputBindings[INPUT_SLOT_NEXT ].secondary = VIRTUAL_JOY(3); m_inputBindings[INPUT_SLOT_HUMAN ].primary = KEY(HOME); - m_inputBindings[INPUT_SLOT_HUMAN ].secondary = VIRTUAL_JOY(7); +// m_inputBindings[INPUT_SLOT_HUMAN ].secondary = VIRTUAL_JOY(7); m_inputBindings[INPUT_SLOT_QUIT ].primary = KEY(ESCAPE); m_inputBindings[INPUT_SLOT_HELP ].primary = KEY(F1); m_inputBindings[INPUT_SLOT_PROG ].primary = KEY(F2); -- cgit v1.2.3-1-g7c22 From a79bd6c5c780d8f63dff49a0abc78a5c59318fe4 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Dec 2013 23:41:50 +0100 Subject: Fixed build of stringutils.cpp /var/www/colobot_compiled/colobot/dev/colobot/src/common/stringutils.cpp:33:51: error: 'vsnprintf' was not declared in this scope --- src/common/stringutils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp index 37169a5..03a0f0b 100644 --- a/src/common/stringutils.cpp +++ b/src/common/stringutils.cpp @@ -18,6 +18,7 @@ #include "common/stringutils.h" #include +#include #include -- cgit v1.2.3-1-g7c22 From bd4f77986a025132b2b335ee34a6681c469439b1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 18:14:44 +0100 Subject: Fix for #264 - some translations not working --- po/pl.po | 5 ----- 1 file changed, 5 deletions(-) diff --git a/po/pl.po b/po/pl.po index 4cbfe60..dfd6f4d 100644 --- a/po/pl.po +++ b/po/pl.po @@ -89,15 +89,12 @@ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" msgid "<< Back \\Back to the previous screen" msgstr "<< Wstecz \\Wraca do poprzedniego ekranu" -#, fuzzy msgid "<<< Sorry; mission failed >>>" msgstr "<<< Niestety, misja nie powiodła się >>>" -#, fuzzy msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Dobra robota, misja wypełniona >>>" -#, fuzzy msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "Po etykiecie musi wystąpić \"for\", \"while\", \"do\" lub \"switch\"" @@ -340,7 +337,6 @@ msgstr "Camera to left" msgid "Camera to right" msgstr "Camera to right" -#, fuzzy msgid "Can not create this; there are too many objects" msgstr "Nie można tego utworzyć, za dużo obiektów" @@ -702,7 +698,6 @@ msgstr "Nieodpowiedni rodzaj ogniw" msgid "Incorrect index type" msgstr "Nieprawidłowy typ indeksu" -#, fuzzy msgid "Infected by a virus; temporarily out of order" msgstr "Zainfekowane wirusem, chwilowo niesprawne" -- cgit v1.2.3-1-g7c22 From 0d31f59b124658155bf93ca78eb427a98c664572 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 18:50:05 +0100 Subject: .takeoff() for SpaceShip (#265) --- src/object/auto/autobase.cpp | 99 ++++++++++++++++++++++++-------------------- src/object/auto/autobase.h | 2 + src/object/robotmain.cpp | 1 + src/script/cbottoken.cpp | 9 ++-- src/script/script.cpp | 49 ++++++++++++++++++++++ src/script/script.h | 1 + 6 files changed, 113 insertions(+), 48 deletions(-) diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 6d61bc2..06b5dbb 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -121,7 +121,6 @@ bool CAutoBase::EventProcess(const Event &event) CObject* pObj; Math::Vector pos, speed, vibCir, iPos; Math::Point dim, p; - Error err; float angle, dist, time, h, len, vSpeed; int i, max; @@ -313,50 +312,7 @@ begin: if ( event.type == EVENT_OBJECT_BTAKEOFF ) { - err = CheckCloseDoor(); - if ( err != ERR_OK ) - { - m_main->DisplayError(err, m_object); - return false; - } - - err = m_main->CheckEndMission(false); - if ( err != ERR_OK ) - { - m_main->DisplayError(err, m_object); - return false; - } - - FreezeCargo(true); // freeze whole cargo - m_main->SetMovieLock(true); // blocks everything until the end - m_main->DeselectAll(); - - newEvent.type = EVENT_UPDINTERFACE; - m_eventQueue->AddEvent(newEvent); - - m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); - - pos = m_pos; - pos.x -= 110.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); - m_posSound = pos; - - pos = m_object->GetPosition(0); - pos.y += 50.0f; - m_camera->SetScriptLookat(pos); - - m_engine->SetFocus(1.0f); - - m_soundChannel = m_sound->Play(SOUND_MANIP, m_posSound, 0.3f, 1.5f, true); - m_sound->AddEnvelope(m_soundChannel, 0.3f, 1.5f, BASE_DOOR_TIME2, SOPER_CONTINUE); - m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.5f, 0.5f, SOPER_STOP); - - m_phase = ABP_CLOSE2; - m_progress = 0.0f; - m_speed = 1.0f/BASE_DOOR_TIME2; - return true; + return TakeOff(true); } if ( event.type != EVENT_FRAME ) return true; @@ -1444,3 +1400,56 @@ void CAutoBase::EndTransit() m_main->StartMusic(); } +Error CAutoBase::TakeOff(bool printMsg) +{ + + Event newEvent; + Math::Vector pos; + Error err; + + err = CheckCloseDoor(); + if ( err != ERR_OK ) + { + if(printMsg) m_main->DisplayError(err, m_object); + return err; + } + + err = m_main->CheckEndMission(false); + if ( err != ERR_OK ) + { + if(printMsg) m_main->DisplayError(err, m_object); + return err; + } + + FreezeCargo(true); // freeze whole cargo + m_main->SetMovieLock(true); // blocks everything until the end + m_main->DeselectAll(); + + newEvent.type = EVENT_UPDINTERFACE; + m_eventQueue->AddEvent(newEvent); + + m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); + + pos = m_pos; + pos.x -= 110.0f; + m_terrain->AdjustToFloor(pos); + pos.y += 10.0f; + m_camera->SetScriptEye(pos); + m_posSound = pos; + + pos = m_object->GetPosition(0); + pos.y += 50.0f; + m_camera->SetScriptLookat(pos); + + m_engine->SetFocus(1.0f); + + m_soundChannel = m_sound->Play(SOUND_MANIP, m_posSound, 0.3f, 1.5f, true); + m_sound->AddEnvelope(m_soundChannel, 0.3f, 1.5f, BASE_DOOR_TIME2, SOPER_CONTINUE); + m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.5f, 0.5f, SOPER_STOP); + + m_phase = ABP_CLOSE2; + m_progress = 0.0f; + m_speed = 1.0f/BASE_DOOR_TIME2; + return ERR_OK; +} + diff --git a/src/object/auto/autobase.h b/src/object/auto/autobase.h index 422f340..967e43d 100644 --- a/src/object/auto/autobase.h +++ b/src/object/auto/autobase.h @@ -77,6 +77,8 @@ public: Error GetError(); bool CreateInterface(bool bSelect); + + Error TakeOff(bool printMsg); protected: void UpdateInterface(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 22e8152..47f06b3 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -881,6 +881,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) bc->AddFunction("busy", CScript::rBusy, CScript::cBusy); bc->AddFunction("factory", CScript::rFactory, CScript::cFactory); bc->AddFunction("research", CScript::rResearch, CScript::cClassOneFloat); + bc->AddFunction("takeoff", CScript::rTakeOff, CScript::cClassNull); bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull); // Initializes the class FILE. diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 505228e..9f99752 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -253,10 +253,11 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "getresearchenable" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresen.txt"); if ( strcmp(token, "getresearchdone" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresdo.txt"); if ( strcmp(token, "retobject" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/retobj.txt"); - if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); - if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt"); - if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); + if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); + if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt"); + if ( strcmp(token, "takeoff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/takeoff.txt"); if ( strcmp(token, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.txt"); + if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); if ( strcmp(token, "destroy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/destroy.txt"); if ( strcmp(token, "search" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/search.txt"); if ( strcmp(token, "radar" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/radar.txt"); @@ -384,6 +385,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "busy" ) == 0 ) return true; if ( strcmp(token, "factory" ) == 0 ) return true; if ( strcmp(token, "research" ) == 0 ) return true; + if ( strcmp(token, "takeoff" ) == 0 ) return true; if ( strcmp(token, "destroy" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; @@ -477,6 +479,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( );"; if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat, program );"; if ( strcmp(token, "research" ) == 0 ) return "object.research ( type );"; + if ( strcmp(token, "takeoff" ) == 0 ) return "object.takeoff ( );"; if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );"; if ( strcmp(token, "search" ) == 0 ) return "search ( );"; if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 1a70699..05e2626 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -38,6 +38,7 @@ #include "object/auto/auto.h" #include "object/auto/autofactory.h" +#include "object/auto/autobase.h" #include "physics/physics.h" @@ -901,6 +902,54 @@ bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& return true; } +// Instruction "object.takeoff()" + +bool CScript::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + CBotVar* classVars = thisclass->GetItemList(); // "category" + ObjectType thisType = static_cast(classVars->GetValInt()); + classVars = classVars->GetNext(); // "position" + classVars = classVars->GetNext(); // "orientation" + classVars = classVars->GetNext(); // "pitch" + classVars = classVars->GetNext(); // "roll" + classVars = classVars->GetNext(); // "energyLevel" + classVars = classVars->GetNext(); // "shieldLevel" + classVars = classVars->GetNext(); // "temperature" + classVars = classVars->GetNext(); // "altitude" + classVars = classVars->GetNext(); // "lifeTime" + classVars = classVars->GetNext(); // "material" + classVars = classVars->GetNext(); // "energyCell" + classVars = classVars->GetNext(); // "load" + classVars = classVars->GetNext(); // "id" + int rank = classVars->GetValInt(); + CObject* center = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = center->GetAuto(); + + if ( thisType == OBJECT_BASE ) + { + err = (static_cast(automat))->TakeOff(false); + } else + err = ERR_WRONG_OBJ; + + if ( err != ERR_OK ) + { + result->SetValInt(err); // return error +//TODO: if ( script->m_errMode == ERM_STOP ) + if( true ) + { + exception = err; + return false; + } + return true; + } + + return true; +} + // Compilation of the instruction "delete(rank[, exploType[, force]])". CBotTypResult CScript::cDelete(CBotVar* &var, void* user) diff --git a/src/script/script.h b/src/script/script.h index 3641dd9..9d8d372 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -200,6 +200,7 @@ public: static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); + static bool rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); private: -- cgit v1.2.3-1-g7c22 From cf856fe77db96398a82ba8e493f5627237bdf5b9 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 19:18:32 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 3ea02f8..253977d 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 3ea02f8481b98e37cb79c1545a9db2720c909521 +Subproject commit 253977dfdf45fbfbcac1ce5b4df94ff6630a71c2 -- cgit v1.2.3-1-g7c22 From 46a7aa98b092592a1d886ef60c662ffcf826611a Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 19:36:17 +0100 Subject: Added error message when unable to load script from file specified in CreateObject --- src/object/robotmain.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 47f06b3..8b79c89 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4546,13 +4546,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "MissionController") && read[0] == 0 && m_version >= 2) { - /* TODO: ??? - if (!m_beginObject) - { - GetLogger()->Error("Syntax error in file '%s' (line %d): MissionController before BeginObject\n", filename, lineNum); - continue; - }*/ - m_controller = CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, 1.0f, 0.0f, OBJECT_CONTROLLER, 100.0f, false, false, 0); m_controller->SetMagnifyDamage(100.0f); CBrain* brain = m_controller->GetBrain(); @@ -6021,7 +6014,9 @@ void CRobotMain::CompileScript(bool soluce) char* name = brain->GetScriptName(j); if (name[0] != 0) { - brain->ReadProgram(j, name); + if(! brain->ReadProgram(j, name)) { + CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name); + } if (!brain->GetCompile(j)) nbError++; } } -- cgit v1.2.3-1-g7c22 From 8b121910c1f762cb83f438c9595ba98f6b4cbc2e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 19:39:32 +0100 Subject: Indentation fixes --- src/object/auto/autobase.cpp | 4 ++-- src/object/robotmain.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 06b5dbb..25320d3 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -312,7 +312,7 @@ begin: if ( event.type == EVENT_OBJECT_BTAKEOFF ) { - return TakeOff(true); + return TakeOff(true); } if ( event.type != EVENT_FRAME ) return true; @@ -1405,7 +1405,7 @@ Error CAutoBase::TakeOff(bool printMsg) Event newEvent; Math::Vector pos; - Error err; + Error err; err = CheckCloseDoor(); if ( err != ERR_OK ) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 8b79c89..87b8311 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -6015,7 +6015,7 @@ void CRobotMain::CompileScript(bool soluce) if (name[0] != 0) { if(! brain->ReadProgram(j, name)) { - CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name); + CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name); } if (!brain->GetCompile(j)) nbError++; } -- cgit v1.2.3-1-g7c22 From 3eec21895efe3812758d022233fd817faf1529c1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 19:48:44 +0100 Subject: Renamed "New player" to "Change player" (#220) --- po/colobot.pot | 2 +- po/de.po | 7 +++---- po/fr.po | 7 +++---- po/pl.po | 7 +++---- po/ru.po | 6 +++--- src/common/restext.cpp | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 8ce386f..3e7464c 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -279,7 +279,7 @@ msgstr "" msgid "Proto\\Prototypes under development" msgstr "" -msgid "New player\\Choose player's name" +msgid "Change player\\Change player" msgstr "" msgid "Options\\Preferences" diff --git a/po/de.po b/po/de.po index d0943ab..4a0032d 100644 --- a/po/de.po +++ b/po/de.po @@ -363,6 +363,9 @@ msgstr "Challenges\\Herausforderungen" msgid "Change camera\\Switches between onboard camera and following camera" msgstr "Andere Kamera\\Sichtpunkt einstellen" +msgid "Change player\\Change player" +msgstr "Anderer Spieler\\Spielername ändern" + msgid "Checkpoint" msgstr "Checkpoint" @@ -847,9 +850,6 @@ msgstr "Neu ..." msgid "New bot available" msgstr "Neuer Roboter verfügbar" -msgid "New player\\Choose player's name" -msgstr "Anderer Spieler\\Spielername ändern" - msgid "Next" msgstr "Nächster" @@ -2053,4 +2053,3 @@ msgstr "www.epsitec.com" #~ msgid "Zoom" #~ msgstr "Zoom" - diff --git a/po/fr.po b/po/fr.po index 343458d..44d64ad 100644 --- a/po/fr.po +++ b/po/fr.po @@ -363,6 +363,9 @@ msgstr "Défis\\Défis de programmation" msgid "Change camera\\Switches between onboard camera and following camera" msgstr "Changement de caméra\\Autre de point de vue" +msgid "Change player\\Change player" +msgstr "Autre joueur\\Choix du nom du joueur" + msgid "Checkpoint" msgstr "Indicateur" @@ -848,9 +851,6 @@ msgstr "Nouveau ..." msgid "New bot available" msgstr "Nouveau robot disponible" -msgid "New player\\Choose player's name" -msgstr "Autre joueur\\Choix du nom du joueur" - msgid "Next" msgstr "Suivant" @@ -2055,4 +2055,3 @@ msgstr "www.epsitec.com" #~ msgid "Zoom" #~ msgstr "Zoom" - diff --git a/po/pl.po b/po/pl.po index dfd6f4d..248ba29 100644 --- a/po/pl.po +++ b/po/pl.po @@ -361,6 +361,9 @@ msgstr "Wyzwania\\Wyzwania programistyczne" msgid "Change camera\\Switches between onboard camera and following camera" msgstr "Zmień kamerę\\Przełącza pomiędzy kamerą pokładową i śledzącą" +msgid "Change player\\Change player" +msgstr "Zmień gracza\\Zmień gracza" + msgid "Checkpoint" msgstr "Punkt kontrolny" @@ -847,9 +850,6 @@ msgstr "Nowy ..." msgid "New bot available" msgstr "Dostępny nowy robot" -msgid "New player\\Choose player's name" -msgstr "Nowy gracz\\Wybierz imię gracza" - msgid "Next" msgstr "Następny" @@ -2058,4 +2058,3 @@ msgstr "www.epsitec.com" #~ msgid "Zoom" #~ msgstr "Powiększenie" - diff --git a/po/ru.po b/po/ru.po index 012395a..3e9e745 100644 --- a/po/ru.po +++ b/po/ru.po @@ -366,6 +366,9 @@ msgstr "Задания\\Практика программирования" msgid "Change camera\\Switches between onboard camera and following camera" msgstr "Изменить вид\\Переключение между бортовой камерой и следящей камерой" +msgid "Change player\\Change player" +msgstr "Новый игрок\\Выберите имя для игрока" + msgid "Checkpoint" msgstr "Контрольная точка" @@ -849,9 +852,6 @@ msgstr "Новый ..." msgid "New bot available" msgstr "Доступен новый бот" -msgid "New player\\Choose player's name" -msgstr "Новый игрок\\Выберите имя для игрока" - msgid "Next" msgstr "Следующий" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c5d0ceb..a63c4ca 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -156,7 +156,7 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_TEEN] = "Free game\\Free game without a specific goal"; stringsEvent[EVENT_INTERFACE_USER] = "User\\User levels"; stringsEvent[EVENT_INTERFACE_PROTO] = "Proto\\Prototypes under development"; - stringsEvent[EVENT_INTERFACE_NAME] = "New player\\Choose player's name"; + stringsEvent[EVENT_INTERFACE_NAME] = "Change player\\Change player"; stringsEvent[EVENT_INTERFACE_SETUP] = "Options\\Preferences"; stringsEvent[EVENT_INTERFACE_AGAIN] = "Restart\\Restart the mission from the beginning"; stringsEvent[EVENT_INTERFACE_WRITE] = "Save\\Save the current mission "; -- cgit v1.2.3-1-g7c22 From 07901341a66675b42277ec0948d6460b67e9d37a Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 20:37:39 +0100 Subject: Fix for #71 - infinite energy --- src/physics/physics.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 2c5f95e..e20e726 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -786,6 +786,10 @@ void CPhysics::MotorUpdate(float aTime, float rTime) type = m_object->GetType(); + if(isnan(m_motorSpeed.x)) m_motorSpeed.x = 0.f; + if(isnan(m_motorSpeed.y)) m_motorSpeed.y = 0.f; + if(isnan(m_motorSpeed.z)) m_motorSpeed.z = 0.f; + motorSpeed = m_motorSpeed; if ( type == OBJECT_MOTHER || -- cgit v1.2.3-1-g7c22 From fcda183b96098e9ed388cad6257049a44d6bbbed Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 21:05:58 +0100 Subject: Hide userlevels menu in release version Userlevels aren't working right now (issue #219) --- src/ui/maindialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 7cbcef5..7540f3d 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -351,6 +351,7 @@ pb->SetState(STATE_SHADOW); pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_QUIT); pb->SetState(STATE_SHADOW); + #if DEV_BUILD // TODO: #if !_DEMO & !_SCHOOL if ( m_accessEnable && m_accessUser ) { @@ -365,6 +366,7 @@ pb->SetState(STATE_SHADOW); pb->SetState(STATE_SHADOW); } // #endif + #endif // TODO: remove? if (m_app->GetProtoMode()) -- cgit v1.2.3-1-g7c22 From 16842b5e837e26f27962a36cd5f29f79ab588505 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 21:09:19 +0100 Subject: Changed default loglevel on dev builds to Debug --- src/common/logger.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/logger.cpp b/src/common/logger.cpp index a02854d..7fc8fb0 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -26,7 +26,11 @@ template<> CLogger* CSingleton::m_instance = nullptr; CLogger::CLogger() { m_file = NULL; + #if DEV_BUILD + m_logLevel = LOG_DEBUG; + #else m_logLevel = LOG_INFO; + #endif } -- cgit v1.2.3-1-g7c22 From 32c55297c4a2cdec553ea6319b36eff0cf7302b6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 21:14:36 +0100 Subject: Fix for building physics.cpp on some systems Why is it working on my local machine but it's crashing on MXE on my server? --- src/physics/physics.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index e20e726..85dd3a2 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -786,9 +786,9 @@ void CPhysics::MotorUpdate(float aTime, float rTime) type = m_object->GetType(); - if(isnan(m_motorSpeed.x)) m_motorSpeed.x = 0.f; - if(isnan(m_motorSpeed.y)) m_motorSpeed.y = 0.f; - if(isnan(m_motorSpeed.z)) m_motorSpeed.z = 0.f; + if(std::isnan(m_motorSpeed.x)) m_motorSpeed.x = 0.f; + if(std::isnan(m_motorSpeed.y)) m_motorSpeed.y = 0.f; + if(std::isnan(m_motorSpeed.z)) m_motorSpeed.z = 0.f; motorSpeed = m_motorSpeed; -- cgit v1.2.3-1-g7c22 From 3a78d587bd781d7bd5429dc777522d43129952c1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 21:54:05 +0100 Subject: Exit the game after finishing the mission while using -runscene --- src/object/robotmain.cpp | 8 ++++++++ src/object/robotmain.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 87b8311..da2ccc4 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -696,6 +696,8 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_endingWinRank = 0; m_endingLostRank = 0; m_winTerminate = false; + + m_exitAfterMission = true; m_joystickDeadzone = 0.2f; SetDefaultInputBindings(); @@ -945,6 +947,7 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() void CRobotMain::LoadSceneOnStart(const std::string& name, int rank) { + m_exitAfterMission = true; // TODO: fix this ugly dependency :( m_dialog->SetSceneName(name.c_str()); m_dialog->SetSceneRank(rank); @@ -1747,10 +1750,14 @@ bool CRobotMain::ProcessEvent(Event &event) case EVENT_WIN: ChangePhase(PHASE_WIN); + if(m_exitAfterMission) + m_eventQueue->AddEvent(Event(EVENT_QUIT)); break; case EVENT_LOST: ChangePhase(PHASE_LOST); + if(m_exitAfterMission) + m_eventQueue->AddEvent(Event(EVENT_QUIT)); break; default: @@ -1787,6 +1794,7 @@ bool CRobotMain::ProcessEvent(Event &event) ChangePhase(PHASE_INIT); else ChangePhase(PHASE_TERM); + break; default: diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 76535de..1a79457 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -522,6 +522,8 @@ protected: int m_endingWinRank; int m_endingLostRank; bool m_winTerminate; + + bool m_exitAfterMission; float m_fontSize; Math::Point m_windowPos; -- cgit v1.2.3-1-g7c22 From 0f57809f5112a6e4acbc2cb95d92be2cf6108a0c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 22:13:04 +0100 Subject: Added scene test mode ... and fixed a "small" bug in previous commit ;) --- src/app/app.cpp | 15 ++++++++++++++- src/app/app.h | 5 +++++ src/object/robotmain.cpp | 5 ++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 32fec89..80d0480 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -153,6 +153,8 @@ CApplication::CApplication() m_runSceneName = ""; m_runSceneRank = 0; + + m_sceneTest = false; m_language = LANGUAGE_ENV; @@ -186,7 +188,6 @@ CApplication::~CApplication() m_eventQueue = nullptr; delete m_profile; - m_profile = nullptr; delete m_iMan; m_iMan = nullptr; @@ -225,6 +226,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_HELP = 1, OPT_DEBUG, OPT_RUNSCENE, + OPT_SCENETEST, OPT_LOGLEVEL, OPT_LANGUAGE, OPT_DATADIR, @@ -239,6 +241,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "help", no_argument, nullptr, OPT_HELP }, { "debug", required_argument, nullptr, OPT_DEBUG }, { "runscene", required_argument, nullptr, OPT_RUNSCENE }, + { "scenetest", no_argument, nullptr, OPT_SCENETEST }, { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, { "datadir", required_argument, nullptr, OPT_DATADIR }, @@ -280,6 +283,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -help this help\n"); GetLogger()->Message(" -debug modes enable debug modes (more info printed in logs; see code for reference of modes)\n"); GetLogger()->Message(" -runscene sceneNNN run given scene on start\n"); + GetLogger()->Message(" -scenetest win every mission right after it's loaded\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); @@ -318,6 +322,11 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Info("Running scene '%s%d' on start\n", m_runSceneName.c_str(), m_runSceneRank); break; } + case OPT_SCENETEST: + { + m_sceneTest = true; + break; + } case OPT_LOGLEVEL: { LogLevel logLevel; @@ -1859,3 +1868,7 @@ bool CApplication::GetProtoMode() const return m_protoMode; } +bool CApplication::GetSceneTestMode() +{ + return m_sceneTest; +} diff --git a/src/app/app.h b/src/app/app.h index 6b02f67..789ee3e 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -362,6 +362,8 @@ public: //@} bool GetProtoMode() const; + + bool GetSceneTestMode(); protected: //! Creates the window's SDL_Surface @@ -494,6 +496,9 @@ protected: std::string m_runSceneName; int m_runSceneRank; //@} + + //! Scene test mode + bool m_sceneTest; const char* m_standardDataDirs[DIR_MAX]; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index da2ccc4..0ed5d07 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -697,7 +697,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_endingLostRank = 0; m_winTerminate = false; - m_exitAfterMission = true; + m_exitAfterMission = false; m_joystickDeadzone = 0.2f; SetDefaultInputBindings(); @@ -5082,6 +5082,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_dialog->SetStackRead(""); RestoreNumericLocale(); + + if(m_app->GetSceneTestMode()) + m_eventQueue->AddEvent(Event(EVENT_WIN)); } //! Creates an object of decoration mobile or stationary -- cgit v1.2.3-1-g7c22 From 01cbc4177e9e5071a451633dbed311bc3f125491 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 22:14:53 +0100 Subject: Whoops --- src/app/app.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/app.cpp b/src/app/app.cpp index 80d0480..c470ede 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -188,6 +188,7 @@ CApplication::~CApplication() m_eventQueue = nullptr; delete m_profile; + m_profile = nullptr; delete m_iMan; m_iMan = nullptr; -- cgit v1.2.3-1-g7c22 From 555c486fc63600dd5527346d1689a706dc33a45d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 22:33:17 +0100 Subject: Disable immediat SatCom when scene test is enabled --- src/object/robotmain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 0ed5d07..0fc17f3 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4064,6 +4064,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_immediatSatCom = OpInt(line, "immediat", 0); if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0); + if (m_app->GetSceneTestMode()) m_immediatSatCom = false; continue; } -- cgit v1.2.3-1-g7c22 From 3b1efc6558a7524bdcaca3232c377444aa43ce19 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Dec 2013 22:33:45 +0100 Subject: Added tool for loading every level in scene test mode --- tools/check-levels.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 tools/check-levels.sh diff --git a/tools/check-levels.sh b/tools/check-levels.sh new file mode 100755 index 0000000..22544fb --- /dev/null +++ b/tools/check-levels.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Runs every level in scenetest mode + +levels=`ls /usr/local/share/games/colobot/levels | cut -d "." -f 1` +for level in $levels; do + echo $level + colobot -runscene $level -scenetest -loglevel warn +done -- cgit v1.2.3-1-g7c22 From 8b5b2eeaa152129dd23a9c127bd59ec260956c42 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 10:50:52 +0100 Subject: Added error message when CEdit is unable to read a file --- src/ui/edit.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 271a8e7..67ed6a1 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1466,7 +1466,10 @@ bool CEdit::ReadText(std::string filename, int addSize) } file = fopen(fs::path(path).make_preferred().string().c_str(), "rb"); - if ( file == NULL ) return false; + if ( file == NULL ) { + CLogger::GetInstancePointer()->Error("Unable to read text from file \"%s\"\n", path.c_str()); + return false; + } fseek(file, 0, SEEK_END); len = ftell(file); -- cgit v1.2.3-1-g7c22 From 9a741a66a4982cf324834dc2f1e5cff6e6038ade Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 11:15:36 +0100 Subject: Changed version display in bottom-right corner to be actually version number instead of date --- CMakeLists.txt | 25 ++++++++++++++++--------- src/common/config.h.cmake | 1 + src/ui/maindialog.cpp | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 482186f..c4405d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,15 +21,22 @@ set(COLOBOT_VERSION_REVISION 2) set(COLOBOT_VERSION_UNRELEASED "+alpha") # Append git characteristics to version -if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git") - find_package(Git) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD - OUTPUT_VARIABLE GIT_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") +if(DEFINED COLOBOT_VERSION_UNRELEASED) + if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + find_package(Git) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") + set(COLOBOT_VERSION_DISPLAY "git-${GIT_BRANCH}~r${GIT_REVISION}") + else() + set(COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_CODENAME}-${COLOBOT_VERSION_UNRELEASED}") + endif() +else() + set(COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_RELEASE_CODENAME}") endif() set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}${COLOBOT_VERSION_RELEASE_CODENAME}") diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 6408b6e..98ccefe 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -27,6 +27,7 @@ #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" #define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" #define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" +#define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@" #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 7540f3d..f9ca09c 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -20,6 +20,7 @@ #include "app/app.h" #include "app/system.h" +#include "common/config.h" #include "common/global.h" #include "common/event.h" #include "common/logger.h" @@ -1976,7 +1977,7 @@ ddim.y = 9.0f/480.0f; ddim.y = 10.0f/480.0f; //#endif //GetResource(RES_TEXT, RT_VERSION_ID, name); - pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, __DATE__); + pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, COLOBOT_VERSION_DISPLAY); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(9.0f); } -- cgit v1.2.3-1-g7c22 From ad9b53a02f06abb94b4e2099c90285868836a90d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 19:58:50 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 253977d..11df498 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 253977dfdf45fbfbcac1ce5b4df94ff6630a71c2 +Subproject commit 11df4981bab65959dce5c71253b7ded9470ea2c3 -- cgit v1.2.3-1-g7c22 From 246b7e107e058e9da972e038e28ccdb7085c09cc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 20:36:11 +0100 Subject: Removed prototypes support --- po/colobot.pot | 9 --------- po/de.po | 14 -------------- po/fr.po | 9 --------- po/pl.po | 11 +---------- po/ru.po | 12 +----------- src/app/app.cpp | 15 +-------------- src/app/app.h | 2 -- src/common/event.cpp | 1 - src/common/event.h | 1 - src/common/restext.cpp | 4 ---- src/common/restext.h | 3 --- src/object/robotmain.h | 1 - src/ui/maindialog.cpp | 48 +++++++++++------------------------------------- 13 files changed, 14 insertions(+), 116 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 3e7464c..c302f7e 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -68,9 +68,6 @@ msgstr "" msgid "User levels" msgstr "" -msgid "Prototypes" -msgstr "" - msgid "Options" msgstr "" @@ -110,9 +107,6 @@ msgstr "" msgid " Missions on this level:" msgstr "" -msgid " Prototypes on this planet:" -msgstr "" - msgid " Free game on this chapter:" msgstr "" @@ -276,9 +270,6 @@ msgstr "" msgid "User\\User levels" msgstr "" -msgid "Proto\\Prototypes under development" -msgstr "" - msgid "Change player\\Change player" msgstr "" diff --git a/po/de.po b/po/de.po index 4a0032d..f6b81f5 100644 --- a/po/de.po +++ b/po/de.po @@ -39,9 +39,6 @@ msgstr " Liste der Missionen des Planeten:" msgid " Planets:" msgstr " Liste der Planeten:" -msgid " Prototypes on this planet:" -msgstr " Liste der Prototypen des Planeten:" - msgid " Resolution:" msgstr " Auflösung:" @@ -88,15 +85,12 @@ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" msgid "<< Back \\Back to the previous screen" msgstr "<< Zurück \\Zurück zum Hauptmenü" -#, fuzzy msgid "<<< Sorry; mission failed >>>" msgstr "<<< Mission gescheitert >>>" -#, fuzzy msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Bravo, Mission vollendet >>>" -#, fuzzy msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" msgstr "" "Ein Label kann nur vor den Anweisungen \"for\", \"while\", \"do\" oder " @@ -338,7 +332,6 @@ msgstr "Kamera links" msgid "Camera to right" msgstr "Kamera rechts" -#, fuzzy msgid "Can not create this; there are too many objects" msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" @@ -702,7 +695,6 @@ msgstr "Falscher Batterietyp" msgid "Incorrect index type" msgstr "Falscher Typ für einen Index" -#, fuzzy msgid "Infected by a virus; temporarily out of order" msgstr "Von Virus infiziert, zeitweise außer Betrieb" @@ -1114,12 +1106,6 @@ msgstr "Hilfe CBOT-Sprache\\Hilfe über die Programmiersprache CBOT" msgid "Programs dispatched by Houston" msgstr "Von Houston übermittelte Programme" -msgid "Proto\\Prototypes under development" -msgstr "Proto\\In Entwicklung befindliche Prototypen" - -msgid "Prototypes" -msgstr "Prototypen" - msgid "Public required" msgstr "Hier muss das Wort \"public\" stehen" diff --git a/po/fr.po b/po/fr.po index 44d64ad..b4f94d0 100644 --- a/po/fr.po +++ b/po/fr.po @@ -44,9 +44,6 @@ msgstr " Liste des missions du chapitre :" msgid " Planets:" msgstr " Liste des planètes :" -msgid " Prototypes on this planet:" -msgstr " Liste des prototypes du chapitre :" - msgid " Resolution:" msgstr " Résolutions :" @@ -1115,12 +1112,6 @@ msgstr "Instructions programmation\\Explication sur la programmation" msgid "Programs dispatched by Houston" msgstr "Programmes envoyés par Houston" -msgid "Proto\\Prototypes under development" -msgstr "Proto\\Prototypes en cours d'élaboration" - -msgid "Prototypes" -msgstr "Prototypes" - msgid "Public required" msgstr "Public requis" diff --git a/po/pl.po b/po/pl.po index 248ba29..05da29f 100644 --- a/po/pl.po +++ b/po/pl.po @@ -26,7 +26,7 @@ msgid " Exercises in the chapter:" msgstr " Ćwiczenia w tym rozdziale:" msgid " Free game on this chapter:" -msgstr " Prototypy na tej planecie:" +msgstr " Swobodna gra na tej planecie:" msgid " Free game on this planet:" msgstr " Swobodna gra na tej planecie:" @@ -40,9 +40,6 @@ msgstr " Misje na tej planecie:" msgid " Planets:" msgstr " Planety:" -msgid " Prototypes on this planet:" -msgstr " Prototypy na tej planecie:" - msgid " Resolution:" msgstr " Rozdzielczość:" @@ -1116,12 +1113,6 @@ msgstr "Podręcznik programowania\\Dostarcza szczegółową pomoc w programowani msgid "Programs dispatched by Houston" msgstr "Program dostarczony z Houston" -msgid "Proto\\Prototypes under development" -msgstr "Prototypy\\Prototypy w trakcie rozwijania" - -msgid "Prototypes" -msgstr "Prototypy" - msgid "Public required" msgstr "Wymagany publiczny" diff --git a/po/ru.po b/po/ru.po index 3e9e745..7531fca 100644 --- a/po/ru.po +++ b/po/ru.po @@ -49,9 +49,6 @@ msgstr "Миссии на этой планете:" msgid " Planets:" msgstr " Планеты:" -msgid " Prototypes on this planet:" -msgstr "Прототипы на этой планете:" - msgid " Resolution:" msgstr " Разрешение:" @@ -1113,18 +1110,11 @@ msgid "Programming help (\\key prog;)" msgstr "Помощь в программировании (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" -msgstr "" -"Помощь в программировании\\Дает более детальную помощь в программировании" +msgstr "Помощь в программировании\\Дает более детальную помощь в программировании" msgid "Programs dispatched by Houston" msgstr "Программы переданные с Хьюстона" -msgid "Proto\\Prototypes under development" -msgstr "Прототипы\\Прототипы в стадии разработки" - -msgid "Prototypes" -msgstr "Прототипы" - msgid "Public required" msgstr "Требуется общественное" diff --git a/src/app/app.cpp b/src/app/app.cpp index c470ede..566be33 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -233,8 +233,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_DATADIR, OPT_LANGDIR, OPT_TEXPACK, - OPT_VBO, - OPT_PROTO + OPT_VBO }; option options[] = @@ -250,7 +249,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "langdir", required_argument, nullptr, OPT_LANGDIR }, { "texpack", required_argument, nullptr, OPT_TEXPACK }, { "vbo", required_argument, nullptr, OPT_VBO }, - { "proto", no_argument, nullptr, OPT_PROTO }, { nullptr, 0, nullptr, 0} }; @@ -292,7 +290,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -langdir path set custom language directory path\n"); GetLogger()->Message(" -texpack path set path to custom texture pack\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); - GetLogger()->Message(" -proto show prototype levels\n"); return PARSE_ARGS_HELP; } case OPT_DEBUG: @@ -391,11 +388,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) break; } - case OPT_PROTO: - { - m_protoMode = true; - break; - } default: assert(false); // should never get here } @@ -1864,11 +1856,6 @@ void CApplication::UpdatePerformanceCountersData() } } -bool CApplication::GetProtoMode() const -{ - return m_protoMode; -} - bool CApplication::GetSceneTestMode() { return m_sceneTest; diff --git a/src/app/app.h b/src/app/app.h index 789ee3e..3d61081 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -360,8 +360,6 @@ public: void StopPerformanceCounter(PerformanceCounter counter); float GetPerformanceCounterData(PerformanceCounter counter) const; //@} - - bool GetProtoMode() const; bool GetSceneTestMode(); diff --git a/src/common/event.cpp b/src/common/event.cpp index 7acac77..9dc3943 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -161,7 +161,6 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_INTERFACE_DEFI] = "EVENT_INTERFACE_DEFI"; EVENT_TYPE_TEXT[EVENT_INTERFACE_MISSION] = "EVENT_INTERFACE_MISSION"; EVENT_TYPE_TEXT[EVENT_INTERFACE_FREE] = "EVENT_INTERFACE_FREE"; - EVENT_TYPE_TEXT[EVENT_INTERFACE_PROTO] = "EVENT_INTERFACE_PROTO"; EVENT_TYPE_TEXT[EVENT_INTERFACE_NAME] = "EVENT_INTERFACE_NAME"; EVENT_TYPE_TEXT[EVENT_INTERFACE_SETUP] = "EVENT_INTERFACE_SETUP"; EVENT_TYPE_TEXT[EVENT_INTERFACE_QUIT] = "EVENT_INTERFACE_QUIT"; diff --git a/src/common/event.h b/src/common/event.h index 9405660..c5eb615 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -184,7 +184,6 @@ enum EventType EVENT_INTERFACE_DEFI = 401, EVENT_INTERFACE_MISSION = 402, EVENT_INTERFACE_FREE = 403, - EVENT_INTERFACE_PROTO = 404, EVENT_INTERFACE_NAME = 405, EVENT_INTERFACE_SETUP = 406, EVENT_INTERFACE_QUIT = 407, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index a63c4ca..6533c7c 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -63,7 +63,6 @@ void InitializeRestext() stringsText[RT_TITLE_FREE] = "Free game"; stringsText[RT_TITLE_TEEN] = "Free game"; stringsText[RT_TITLE_USER] = "User levels"; - stringsText[RT_TITLE_PROTO] = "Prototypes"; stringsText[RT_TITLE_SETUP] = "Options"; stringsText[RT_TITLE_NAME] = "Player's name"; stringsText[RT_TITLE_PERSO] = "Customize your appearance"; @@ -75,14 +74,12 @@ void InitializeRestext() stringsText[RT_PLAY_CHAPm] = " Planets:"; stringsText[RT_PLAY_CHAPf] = " Planets:"; stringsText[RT_PLAY_CHAPu] = " User levels:"; - stringsText[RT_PLAY_CHAPp] = " Planets:"; stringsText[RT_PLAY_CHAPte] = " Chapters:"; stringsText[RT_PLAY_LISTt] = " Exercises in the chapter:"; stringsText[RT_PLAY_LISTd] = " Challenges in the chapter:"; stringsText[RT_PLAY_LISTm] = " Missions on this planet:"; stringsText[RT_PLAY_LISTf] = " Free game on this planet:"; stringsText[RT_PLAY_LISTu] = " Missions on this level:"; - stringsText[RT_PLAY_LISTp] = " Prototypes on this planet:"; stringsText[RT_PLAY_LISTk] = " Free game on this chapter:"; stringsText[RT_PLAY_RESUME] = " Summary:"; @@ -155,7 +152,6 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_FREE] = "Free game\\Free game without a specific goal"; stringsEvent[EVENT_INTERFACE_TEEN] = "Free game\\Free game without a specific goal"; stringsEvent[EVENT_INTERFACE_USER] = "User\\User levels"; - stringsEvent[EVENT_INTERFACE_PROTO] = "Proto\\Prototypes under development"; stringsEvent[EVENT_INTERFACE_NAME] = "Change player\\Change player"; stringsEvent[EVENT_INTERFACE_SETUP] = "Options\\Preferences"; stringsEvent[EVENT_INTERFACE_AGAIN] = "Restart\\Restart the mission from the beginning"; diff --git a/src/common/restext.h b/src/common/restext.h index b5a3415..cde7203 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -66,7 +66,6 @@ enum ResTextType RT_TITLE_DEFI = 43, RT_TITLE_MISSION = 44, RT_TITLE_FREE = 45, - RT_TITLE_PROTO = 46, RT_TITLE_SETUP = 47, RT_TITLE_NAME = 48, RT_TITLE_PERSO = 49, @@ -79,12 +78,10 @@ enum ResTextType RT_PLAY_CHAPd = 61, RT_PLAY_CHAPm = 62, RT_PLAY_CHAPf = 63, - RT_PLAY_CHAPp = 64, RT_PLAY_LISTt = 65, RT_PLAY_LISTd = 66, RT_PLAY_LISTm = 67, RT_PLAY_LISTf = 68, - RT_PLAY_LISTp = 69, RT_PLAY_RESUME = 70, RT_PLAY_CHAPu = 71, RT_PLAY_LISTu = 72, diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 1a79457..b25a0a4 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -44,7 +44,6 @@ enum Phase PHASE_FREE, PHASE_TEEN, PHASE_USER, - PHASE_PROTO, PHASE_LOADING, PHASE_SIMUL, PHASE_MODEL, diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index f9ca09c..4726933 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -369,15 +369,11 @@ pb->SetState(STATE_SHADOW); // #endif #endif - // TODO: remove? - if (m_app->GetProtoMode()) - { - pos.x = 139.0f/640.0f; - pos.y = 313.0f/480.0f; - ddim.x = 0.09f; - pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PROTO); - pb->SetState(STATE_SHADOW); - } + /*pos.x = 139.0f/640.0f; + pos.y = 313.0f/480.0f; + ddim.x = 0.09f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PROTO); + pb->SetState(STATE_SHADOW);*/ pos.x = 0.40f; ddim.x = 0.20f; @@ -773,15 +769,13 @@ pb->SetState(STATE_SHADOW); m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { if ( m_phase == PHASE_TRAINER ) m_index = 0; if ( m_phase == PHASE_DEFI ) m_index = 1; if ( m_phase == PHASE_MISSION ) m_index = 2; if ( m_phase == PHASE_FREE ) m_index = 3; if ( m_phase == PHASE_USER ) m_index = 4; - if ( m_phase == PHASE_PROTO ) m_index = 5; if ( m_phase == PHASE_TEEN ) m_index = 6; if ( m_phase == PHASE_FREE ) @@ -797,7 +791,6 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "free"); if ( m_phase == PHASE_TEEN ) strcpy(m_sceneName, "teen"); if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user"); - if ( m_phase == PHASE_PROTO ) strcpy(m_sceneName, "proto"); ReadGamerInfo(); @@ -813,7 +806,6 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) res = RT_TITLE_FREE; if ( m_phase == PHASE_TEEN ) res = RT_TITLE_TEEN; if ( m_phase == PHASE_USER ) res = RT_TITLE_USER; - if ( m_phase == PHASE_PROTO ) res = RT_TITLE_PROTO; GetResource(RES_TEXT, res, name); pw->SetName(name); @@ -862,7 +854,6 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) res = RT_PLAY_CHAPf; if ( m_phase == PHASE_TEEN ) res = RT_PLAY_CHAPte; if ( m_phase == PHASE_USER ) res = RT_PLAY_CHAPu; - if ( m_phase == PHASE_PROTO ) res = RT_PLAY_CHAPp; GetResource(RES_TEXT, res, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL11, name); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); @@ -886,7 +877,6 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) res = RT_PLAY_LISTf; if ( m_phase == PHASE_TEEN ) res = RT_PLAY_LISTk; if ( m_phase == PHASE_USER ) res = RT_PLAY_LISTu; - if ( m_phase == PHASE_PROTO ) res = RT_PLAY_LISTp; GetResource(RES_TEXT, res, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, name); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); @@ -1949,7 +1939,6 @@ pos.y -= 0.048f; m_phase == PHASE_FREE || m_phase == PHASE_TEEN || m_phase == PHASE_USER || - m_phase == PHASE_PROTO || m_phase == PHASE_SETUPd || m_phase == PHASE_SETUPg || m_phase == PHASE_SETUPp || @@ -2233,10 +2222,6 @@ bool CMainDialog::EventProcess(const Event &event) m_main->ChangePhase(PHASE_USER); break; - case EVENT_INTERFACE_PROTO: - m_main->ChangePhase(PHASE_PROTO); - break; - case EVENT_INTERFACE_SETUP: m_main->ChangePhase(m_phaseSetup); break; @@ -2440,8 +2425,7 @@ bool CMainDialog::EventProcess(const Event &event) m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) return false; @@ -2460,8 +2444,7 @@ bool CMainDialog::EventProcess(const Event &event) m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { switch( event.type ) { @@ -2488,11 +2471,6 @@ bool CMainDialog::EventProcess(const Event &event) break; case EVENT_INTERFACE_PLAY: - if ( m_phase == PHASE_PROTO && m_chap[m_index] == 0 && m_sel[m_index] == 0 ) - { - m_main->ChangePhase(PHASE_MODEL); - break; - } m_sceneRank = (m_chap[m_index]+1)*100+(m_sel[m_index]+1); m_phaseTerm = m_phase; m_main->ChangePhase(PHASE_LOADING); @@ -3109,8 +3087,7 @@ void CMainDialog::GlintMove() m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { pg = static_cast(pw->SearchControl(EVENT_INTERFACE_GLINTl)); if ( pg != 0 ) @@ -3338,7 +3315,6 @@ void CMainDialog::FrameParticle(float rTime) m_phase == PHASE_FREE || m_phase == PHASE_TEEN || m_phase == PHASE_USER || - m_phase == PHASE_PROTO || m_phase == PHASE_SETUPd || m_phase == PHASE_SETUPg || m_phase == PHASE_SETUPp || @@ -4685,8 +4661,7 @@ void CMainDialog::AllMissionUpdate() m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { UpdateSceneChap(m_chap[m_index]); UpdateSceneList(m_chap[m_index], m_sel[m_index]); @@ -4989,8 +4964,7 @@ void CMainDialog::ShowSoluceUpdate() m_phase == PHASE_MISSION || m_phase == PHASE_FREE || m_phase == PHASE_TEEN || - m_phase == PHASE_USER || - m_phase == PHASE_PROTO ) + m_phase == PHASE_USER ) { m_bSceneSoluce = false; -- cgit v1.2.3-1-g7c22 From 1b7389367897b858781790f2ada63203b4035ada Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 21:46:16 +0100 Subject: Temporary fix for #232 - don't try to show the buttons This makes SatCom usable for now --- src/ui/edit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 67ed6a1..ff06161 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1672,12 +1672,14 @@ bool CEdit::ReadText(std::string filename, int addSize) buffer[i+6] == 'n' && buffer[i+7] == ' ' ) { + /* TODO: \button X; isn't working. Issue #232 if ( m_bSoluce || !bInSoluce ) { m_text[j] = GetValueParam(buffer+i+8, 0); m_format[j] = font|Gfx::FONT_BUTTON; j ++; } + */ i += strchr(buffer+i, ';')-(buffer+i)+1; } else if ( //m_format.size() > 0 && -- cgit v1.2.3-1-g7c22 From 0ff7e55b3343fbca959fb11236a009fb3790b652 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Dec 2013 22:28:25 +0100 Subject: Fix for #177 - save list sorting --- src/common/misc.cpp | 17 +++++++++++++++++ src/common/misc.h | 1 + src/ui/maindialog.cpp | 17 ++++++++++------- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/common/misc.cpp b/src/common/misc.cpp index b96abca..65689e6 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -230,6 +230,23 @@ void TimeToAscii(time_t time, char *buffer) #endif*/ } +// Converting time to string. + +void TimeToAsciiClean(time_t time, char *buffer) +{ + struct tm when; + int year; + + when = *localtime(&time); + year = when.tm_year+1900; + if ( year < 2000 ) year -= 1900; + else year -= 2000; + + sprintf(buffer, "%.2d%.2d%.2d%.2d%.2d", + year, when.tm_mon+1, when.tm_mday, + when.tm_hour, when.tm_min); +} + // Copy a list of numbered files into the temporary folder. bool CopyFileListToTemp(char* filename, int* list, int total) diff --git a/src/common/misc.h b/src/common/misc.h index bcebf76..3c147b1 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -28,6 +28,7 @@ extern char GetToUpper(char letter); extern char GetToLower(char letter); extern void TimeToAscii(time_t time, char *buffer); +extern void TimeToAsciiClean(time_t time, char *buffer); extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, const char* ext); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 4726933..f3eca3a 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -4332,8 +4333,8 @@ void CMainDialog::IOReadName() } time(&now); - TimeToAscii(now, line); - sprintf(name, "%s %d - %s", resume, m_sel[m_index]+1, line); + TimeToAsciiClean(now, line); + sprintf(name, "%s - %s %d", line, resume, m_sel[m_index]+1); pe->SetText(name); pe->SetCursor(strlen(name), 0); pe->SetFocus(true); @@ -4349,7 +4350,7 @@ void CMainDialog::IOReadList() char line[500]; char name[100]; int i; - fs::directory_iterator end_iter; + std::vector v; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) return; @@ -4363,12 +4364,14 @@ void CMainDialog::IOReadList() if (fs::exists(saveDir) && fs::is_directory(saveDir)) { - for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) + copy(fs::directory_iterator(saveDir), fs::directory_iterator(), back_inserter(v)); + std::sort(v.begin(), v.end()); + for( std::vector::iterator iter = v.begin(); iter != v.end(); ++iter) { - if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) + if ( fs::is_directory(*iter) && fs::exists(*iter / "data.sav") ) { - file = fopen((dir_iter->path() / "data.sav").make_preferred().string().c_str(), "r"); + file = fopen((*iter / "data.sav").make_preferred().string().c_str(), "r"); if ( file == NULL ) continue; while ( fgets(line, 500, file) != NULL ) @@ -4392,7 +4395,7 @@ void CMainDialog::IOReadList() fclose(file); pl->SetItemName(m_saveList.size(), name); - m_saveList.push_back(dir_iter->path()); + m_saveList.push_back(*iter); } } } -- cgit v1.2.3-1-g7c22 From e9addb5a5e072b28eecfa1739ae38d67b68a2b23 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 Dec 2013 12:30:46 +0100 Subject: Added smooth transition in music - issue #205 --- src/object/robotmain.cpp | 8 ++--- src/sound/oalsound/alsound.cpp | 81 +++++++++++++++++++++++++++++++++--------- src/sound/oalsound/alsound.h | 14 ++++++-- src/sound/sound.cpp | 6 ++-- src/sound/sound.h | 8 +++-- 5 files changed, 87 insertions(+), 30 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 0fc17f3..1fa3058 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1072,7 +1072,7 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_SIMUL) // ends a simulation? { SaveAllScript(); - m_sound->StopMusic(); + m_sound->StopMusic(0.0f); m_camera->SetControllingObject(0); /* TODO: #if _SCHOOL @@ -1226,7 +1226,7 @@ void CRobotMain::ChangePhase(Phase phase) m_infoFilename[SATCOM_HUSTON][0] != 0) StartDisplayInfo(SATCOM_HUSTON, false); // shows the instructions - m_sound->StopMusic(); + m_sound->StopMusic(0.0f); if (!m_base || loading) StartMusic(); } @@ -6954,7 +6954,6 @@ void CRobotMain::UpdateAudio(bool frame) nb <= m_audioChange[t].max) { CLogger::GetInstancePointer()->Info("Changing music to \"%s\"\n", m_audioChange[t].music); - m_sound->StopMusic(); m_sound->PlayMusic(std::string(m_audioChange[t].music), m_audioChange[t].repeat); m_audioChange[t].changed = true; } @@ -7510,8 +7509,7 @@ void CRobotMain::StartMusic() CLogger::GetInstancePointer()->Debug("Starting music...\n"); if (m_audioTrack != "") { - m_sound->StopMusic(); - m_sound->PlayMusic(m_audioTrack, m_audioRepeat); + m_sound->PlayMusic(m_audioTrack, m_audioRepeat, 0.0f); } } diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 7f325c1..ef53236 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -57,6 +57,11 @@ void ALSound::CleanUp() { delete m_currentMusic; } + + for (auto item : m_oldMusic) + { + delete item.music; + } for (auto item : m_sounds) { @@ -101,7 +106,6 @@ bool ALSound::Create() alListenerf(AL_GAIN, m_audioVolume); alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); - m_currentMusic = new Channel(); GetLogger()->Info("Done.\n"); m_enabled = true; return true; @@ -469,13 +473,15 @@ bool ALSound::MuteAll(bool bMute) } } - if (bMute) - { - m_currentMusic->SetVolume(0.0f); - } - else - { - m_currentMusic->SetVolume(m_musicVolume); + if (m_currentMusic) { + if (bMute) + { + m_currentMusic->SetVolume(0.0f); + } + else + { + m_currentMusic->SetVolume(m_musicVolume); + } } return true; } @@ -542,6 +548,22 @@ void ALSound::FrameMove(float delta) } } } + + std::list toRemove; + + for (auto& it : m_oldMusic) + { + if (it.currentTime >= it.fadeTime) { + delete it.music; + toRemove.push_back(it); + } else { + it.currentTime += delta; + it.music->SetVolume(((it.fadeTime-it.currentTime) / it.fadeTime) * m_musicVolume); + } + } + + for (auto it : toRemove) + m_oldMusic.remove(it); } @@ -557,14 +579,23 @@ void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) alListenerfv(AL_ORIENTATION, orientation); } -bool ALSound::PlayMusic(int rank, bool bRepeat) +bool ALSound::PlayMusic(int rank, bool bRepeat, float fadeTime) { std::stringstream filename; filename << "music" << std::setfill('0') << std::setw(3) << rank << ".ogg"; - return PlayMusic(filename.str(), bRepeat); + return PlayMusic(filename.str(), bRepeat, fadeTime); } -bool ALSound::PlayMusic(const std::string &filename, bool bRepeat) +bool operator<(const OldMusic & l, const OldMusic & r) +{ + return l.currentTime < r.currentTime; +} +bool operator==(const OldMusic & l, const OldMusic & r) +{ + return l.currentTime == r.currentTime; +} + +bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTime) { if (!m_enabled) { @@ -573,6 +604,8 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat) std::stringstream file; file << m_soundPath << "/" << filename; + + Buffer *buffer; // check if we have music in cache if (m_music.find(filename) == m_music.end()) @@ -583,16 +616,26 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat) GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str()); return false; } - Buffer *buffer = new Buffer(); + + buffer = new Buffer(); buffer->LoadFromFile(file.str(), static_cast(-1)); - m_currentMusic->SetBuffer(buffer); } else { GetLogger()->Debug("Music loaded from cache\n"); - m_currentMusic->SetBuffer(m_music[filename]); + buffer = m_music[filename]; + } + + if (m_currentMusic) { + OldMusic old; + old.music = m_currentMusic; + old.fadeTime = fadeTime; + old.currentTime = 0.0f; + m_oldMusic.push_back(old); } + m_currentMusic = new Channel(); + m_currentMusic->SetBuffer(buffer); m_currentMusic->SetVolume(m_musicVolume); m_currentMusic->SetLoop(bRepeat); m_currentMusic->Play(); @@ -613,14 +656,20 @@ bool ALSound::RestartMusic() return true; } -void ALSound::StopMusic() +void ALSound::StopMusic(float fadeTime) { if (!m_enabled || !m_currentMusic) { return; } - SuspendMusic(); + OldMusic old; + old.music = m_currentMusic; + old.fadeTime = fadeTime; + old.currentTime = 0.0f; + m_oldMusic.push_back(old); + + m_currentMusic = nullptr; } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 2fdcff5..cd3bdd5 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -31,10 +31,17 @@ #include #include +#include #include +struct OldMusic { + Channel* music; + float fadeTime; + float currentTime; +}; + class ALSound : public CSoundInterface { public: @@ -65,11 +72,11 @@ public: bool StopAll(); bool MuteAll(bool bMute); - bool PlayMusic(int rank, bool bRepeat); - bool PlayMusic(const std::string &filename, bool bRepeat); + bool PlayMusic(int rank, bool bRepeat, float fadeTime=5.0f); + bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=5.0f); bool RestartMusic(); void SuspendMusic(); - void StopMusic(); + void StopMusic(float fadeTime=5.0f); bool IsPlayingMusic(); private: @@ -86,6 +93,7 @@ private: std::map m_music; std::map m_channels; Channel *m_currentMusic; + std::list m_oldMusic; Math::Vector m_eye; Math::Vector m_lookat; }; diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index d197b81..1605e2b 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -147,12 +147,12 @@ bool CSoundInterface::MuteAll(bool bMute) return true; } -bool CSoundInterface::PlayMusic(int rank, bool bRepeat) +bool CSoundInterface::PlayMusic(int rank, bool bRepeat, float fadeTime) { return true; } -bool CSoundInterface::PlayMusic(const std::string &filename, bool bRepeat) +bool CSoundInterface::PlayMusic(const std::string &filename, bool bRepeat, float fadeTime) { return true; } @@ -166,7 +166,7 @@ void CSoundInterface::SuspendMusic() { } -void CSoundInterface::StopMusic() +void CSoundInterface::StopMusic(float fadeTime) { } diff --git a/src/sound/sound.h b/src/sound/sound.h index eee0b82..d2eee9c 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -284,16 +284,18 @@ public: /** Start playing music * \param rank - track number * \param bRepeat - repeat playing + * \param fadeTime - time of transition between music * \return return true on success */ - virtual bool PlayMusic(int rank, bool bRepeat); + virtual bool PlayMusic(int rank, bool bRepeat, float fadeTime=5.0f); /** Start playing music * \param filename - name of file to play * \param bRepeat - repeat playing + * \param fadeTime - time of transition between music * \return return true on success */ - virtual bool PlayMusic(const std::string &filename, bool bRepeat); + virtual bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=5.0f); /** Restart music * @return return true on success @@ -308,7 +310,7 @@ public: /** Stop playing music * \return return true on success */ - virtual void StopMusic(); + virtual void StopMusic(float fadeTime=5.0f); /** Check if music if playing * \return return true if music is playing -- cgit v1.2.3-1-g7c22 From 9631f26270d14d3b53ce988868a8809378824dee Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 Dec 2013 16:45:11 +0100 Subject: Don't stop music when SatCom or pause menu is opened --- src/sound/oalsound/alsound.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index ef53236..7f5d1f1 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -472,17 +472,7 @@ bool ALSound::MuteAll(bool bMute) it.second->Mute(bMute); } } - - if (m_currentMusic) { - if (bMute) - { - m_currentMusic->SetVolume(0.0f); - } - else - { - m_currentMusic->SetVolume(m_musicVolume); - } - } + return true; } -- cgit v1.2.3-1-g7c22 From 213de95448df51c6062380afc645754d46f3e1bd Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 Dec 2013 17:54:51 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 11df498..b422c5e 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 11df4981bab65959dce5c71253b7ded9470ea2c3 +Subproject commit b422c5ee84bf19b7badc4d9fd3df39da1612f967 -- cgit v1.2.3-1-g7c22 From dc81cda4b1f27af6fe8abcd566ffac03255f2642 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 Dec 2013 12:08:59 +0100 Subject: Cleaned up creating objects --- src/object/objman.cpp | 7 +- src/object/objman.h | 2 +- src/object/robotmain.cpp | 350 ++--------------------------------------------- src/object/robotmain.h | 3 - src/script/script.cpp | 165 +--------------------- 5 files changed, 20 insertions(+), 507 deletions(-) diff --git a/src/object/objman.cpp b/src/object/objman.cpp index e4102b8..0471ebf 100644 --- a/src/object/objman.cpp +++ b/src/object/objman.cpp @@ -63,10 +63,9 @@ CObject* CObjectManager::SearchInstance(int id) return m_table[id]; } -CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, float zoom, float height, - ObjectType type, float power, - bool trainer, bool toy, - int option) +CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type, + float power, float zoom, float height, + bool trainer, bool toy, int option) { CObject* object = nullptr; diff --git a/src/object/objman.h b/src/object/objman.h index 3087383..1d67468 100644 --- a/src/object/objman.h +++ b/src/object/objman.h @@ -44,7 +44,7 @@ public: //! Seeks for an object CObject* SearchInstance(int id); //! Creates an object - CObject* CreateObject(Math::Vector pos, float angle, float zoom, float height, ObjectType type, float power, bool trainer, bool toy, int option); + CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.f, float zoom = 1.f, float height = 0.f, bool trainer = false, bool toy = false, int option = 0); protected: CObject* m_table[MAX_OBJECTS]; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 1fa3058..af463c7 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -2459,7 +2459,7 @@ void CRobotMain::StartDisplayVisit(EventType event) } Math::Vector goal = m_displayText->GetVisitGoal(event); - m_visitArrow = CreateObject(goal, 0.0f, 1.0f, 10.0f, OBJECT_SHOW, false, false, 0); + m_visitArrow = CObjectManager::GetInstancePointer()->CreateObject(goal, 0.0f, OBJECT_SHOW, -1.0f, 1.0f, 10.0f); m_visitPos = m_visitArrow->GetPosition(0); m_visitPosArrow = m_visitPos; @@ -4555,7 +4555,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "MissionController") && read[0] == 0 && m_version >= 2) { - m_controller = CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, 1.0f, 0.0f, OBJECT_CONTROLLER, 100.0f, false, false, 0); + m_controller = CObjectManager::GetInstancePointer()->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f); m_controller->SetMagnifyDamage(100.0f); CBrain* brain = m_controller->GetBrain(); if (brain != nullptr) @@ -4614,13 +4614,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Math::Vector pos = OpPos(line, "pos")*g_unit; float dirAngle = OpFloat(line, "dir", 0.0f)*Math::PI; - bool trainer = OpInt(line, "trainer", 0); - CObject* obj = CreateObject(pos, dirAngle, - OpFloat(line, "z", 1.0f), - OpFloat(line, "h", 0.0f), + bool trainer; + CObject* obj = CObjectManager::GetInstancePointer()->CreateObject( + pos, dirAngle, type, OpFloat(line, "power", 1.0f), - trainer, + OpFloat(line, "z", 1.0f), + OpFloat(line, "h", 0.0f), + trainer = OpInt(line, "trainer", 0), OpInt(line, "toy", 0), OpInt(line, "option", 0)); @@ -5088,339 +5089,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_eventQueue->AddEvent(Event(EVENT_WIN)); } -//! Creates an object of decoration mobile or stationary -CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, float height, - ObjectType type, float power, - bool trainer, bool toy, - int option) -{ - CObject* object = nullptr; - - if ( type == OBJECT_NULL ) return nullptr; - - if ( type == OBJECT_HUMAN || - type == OBJECT_TECH ) - { - trainer = false; // necessarily - } - - if ( type == OBJECT_PORTICO || - type == OBJECT_BASE || - type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_DESTROYER|| - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_INFO || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_PARA || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_START || - type == OBJECT_END ) - { - object = new CObject(); - object->CreateBuilding(pos, angle, height, type, power); - - CAuto* automat = object->GetAuto(); - if (automat != nullptr) - { - automat->Init(); - } - } - else - if ( type == OBJECT_FRET || - type == OBJECT_STONE || - type == OBJECT_URANIUM || - type == OBJECT_METAL || - type == OBJECT_POWER || - type == OBJECT_ATOMIC || - type == OBJECT_BULLET || - type == OBJECT_BBOX || - type == OBJECT_KEYa || - type == OBJECT_KEYb || - type == OBJECT_KEYc || - type == OBJECT_KEYd || - type == OBJECT_TNT || - type == OBJECT_SCRAP1 || - type == OBJECT_SCRAP2 || - type == OBJECT_SCRAP3 || - type == OBJECT_SCRAP4 || - type == OBJECT_SCRAP5 || - type == OBJECT_BOMB || - type == OBJECT_WAYPOINT || - type == OBJECT_SHOW || - type == OBJECT_WINFIRE || - type == OBJECT_BAG || - type == OBJECT_MARKPOWER || - type == OBJECT_MARKSTONE || - type == OBJECT_MARKURANIUM || - type == OBJECT_MARKKEYa || - type == OBJECT_MARKKEYb || - type == OBJECT_MARKKEYc || - type == OBJECT_MARKKEYd || - type == OBJECT_EGG ) - { - object = new CObject(); - object->CreateResource(pos, angle, type, power); - } - else - if ( type == OBJECT_FLAGb || - type == OBJECT_FLAGr || - type == OBJECT_FLAGg || - type == OBJECT_FLAGy || - type == OBJECT_FLAGv ) - { - object = new CObject(); - object->CreateFlag(pos, angle, type); - } - else - if ( type == OBJECT_BARRIER0 || - type == OBJECT_BARRIER1 || - type == OBJECT_BARRIER2 || - type == OBJECT_BARRIER3 || - type == OBJECT_BARRIER4 ) - { - object = new CObject(); - object->CreateBarrier(pos, angle, height, type); - } - else - if ( type == OBJECT_PLANT0 || - type == OBJECT_PLANT1 || - type == OBJECT_PLANT2 || - type == OBJECT_PLANT3 || - type == OBJECT_PLANT4 || - type == OBJECT_PLANT5 || - type == OBJECT_PLANT6 || - type == OBJECT_PLANT7 || - type == OBJECT_PLANT8 || - type == OBJECT_PLANT9 || - type == OBJECT_PLANT10 || - type == OBJECT_PLANT11 || - type == OBJECT_PLANT12 || - type == OBJECT_PLANT13 || - type == OBJECT_PLANT14 || - type == OBJECT_PLANT15 || - type == OBJECT_PLANT16 || - type == OBJECT_PLANT17 || - type == OBJECT_PLANT18 || - type == OBJECT_PLANT19 || - type == OBJECT_TREE0 || - type == OBJECT_TREE1 || - type == OBJECT_TREE2 || - type == OBJECT_TREE3 || - type == OBJECT_TREE4 || - type == OBJECT_TREE5 || - type == OBJECT_TREE6 || - type == OBJECT_TREE7 || - type == OBJECT_TREE8 || - type == OBJECT_TREE9 ) - { - object = new CObject(); - object->CreatePlant(pos, angle, height, type); - } - else - if ( type == OBJECT_MUSHROOM0 || - type == OBJECT_MUSHROOM1 || - type == OBJECT_MUSHROOM2 || - type == OBJECT_MUSHROOM3 || - type == OBJECT_MUSHROOM4 || - type == OBJECT_MUSHROOM5 || - type == OBJECT_MUSHROOM6 || - type == OBJECT_MUSHROOM7 || - type == OBJECT_MUSHROOM8 || - type == OBJECT_MUSHROOM9 ) - { - object = new CObject(); - object->CreateMushroom(pos, angle, height, type); - } - else - if ( type == OBJECT_TEEN0 || - type == OBJECT_TEEN1 || - type == OBJECT_TEEN2 || - type == OBJECT_TEEN3 || - type == OBJECT_TEEN4 || - type == OBJECT_TEEN5 || - type == OBJECT_TEEN6 || - type == OBJECT_TEEN7 || - type == OBJECT_TEEN8 || - type == OBJECT_TEEN9 || - type == OBJECT_TEEN10 || - type == OBJECT_TEEN11 || - type == OBJECT_TEEN12 || - type == OBJECT_TEEN13 || - type == OBJECT_TEEN14 || - type == OBJECT_TEEN15 || - type == OBJECT_TEEN16 || - type == OBJECT_TEEN17 || - type == OBJECT_TEEN18 || - type == OBJECT_TEEN19 || - type == OBJECT_TEEN20 || - type == OBJECT_TEEN21 || - type == OBJECT_TEEN22 || - type == OBJECT_TEEN23 || - type == OBJECT_TEEN24 || - type == OBJECT_TEEN25 || - type == OBJECT_TEEN26 || - type == OBJECT_TEEN27 || - type == OBJECT_TEEN28 || - type == OBJECT_TEEN29 || - type == OBJECT_TEEN30 || - type == OBJECT_TEEN31 || - type == OBJECT_TEEN32 || - type == OBJECT_TEEN33 || - type == OBJECT_TEEN34 || - type == OBJECT_TEEN35 || - type == OBJECT_TEEN36 || - type == OBJECT_TEEN37 || - type == OBJECT_TEEN38 || - type == OBJECT_TEEN39 || - type == OBJECT_TEEN40 || - type == OBJECT_TEEN41 || - type == OBJECT_TEEN42 || - type == OBJECT_TEEN43 || - type == OBJECT_TEEN44 || - type == OBJECT_TEEN45 || - type == OBJECT_TEEN46 || - type == OBJECT_TEEN47 || - type == OBJECT_TEEN48 || - type == OBJECT_TEEN49 ) - { - object = new CObject(); - object->SetOption(option); - object->CreateTeen(pos, angle, zoom, height, type); - } - else - if ( type == OBJECT_QUARTZ0 || - type == OBJECT_QUARTZ1 || - type == OBJECT_QUARTZ2 || - type == OBJECT_QUARTZ3 || - type == OBJECT_QUARTZ4 || - type == OBJECT_QUARTZ5 || - type == OBJECT_QUARTZ6 || - type == OBJECT_QUARTZ7 || - type == OBJECT_QUARTZ8 || - type == OBJECT_QUARTZ9 ) - { - object = new CObject(); - object->CreateQuartz(pos, angle, height, type); - } - else - if ( type == OBJECT_ROOT0 || - type == OBJECT_ROOT1 || - type == OBJECT_ROOT2 || - type == OBJECT_ROOT3 || - type == OBJECT_ROOT4 || - type == OBJECT_ROOT5 || - type == OBJECT_ROOT6 || - type == OBJECT_ROOT7 || - type == OBJECT_ROOT8 || - type == OBJECT_ROOT9 ) - { - object = new CObject(); - object->CreateRoot(pos, angle, height, type); - } - else - if ( type == OBJECT_HOME1 ) - { - object = new CObject(); - object->CreateHome(pos, angle, height, type); - } - else - if ( type == OBJECT_RUINmobilew1 || - type == OBJECT_RUINmobilew2 || - type == OBJECT_RUINmobilet1 || - type == OBJECT_RUINmobilet2 || - type == OBJECT_RUINmobiler1 || - type == OBJECT_RUINmobiler2 || - type == OBJECT_RUINfactory || - type == OBJECT_RUINdoor || - type == OBJECT_RUINsupport || - type == OBJECT_RUINradar || - type == OBJECT_RUINconvert || - type == OBJECT_RUINbase || - type == OBJECT_RUINhead ) - { - object = new CObject(); - object->CreateRuin(pos, angle, height, type); - } - else - if ( type == OBJECT_APOLLO1 || - type == OBJECT_APOLLO3 || - type == OBJECT_APOLLO4 || - type == OBJECT_APOLLO5 ) - { - object = new CObject(); - object->CreateApollo(pos, angle, type); - } - else - if ( type == OBJECT_MOTHER || - type == OBJECT_ANT || - type == OBJECT_SPIDER || - type == OBJECT_BEE || - type == OBJECT_WORM ) - { - object = new CObject(); - object->CreateInsect(pos, angle, type); // no eggs - } - else - if ( type == OBJECT_HUMAN || - type == OBJECT_TECH || - type == OBJECT_TOTO || - type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs || - type == OBJECT_MOBILEsa || - type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 || - type == OBJECT_CONTROLLER ) - { - object = new CObject(); - object->SetOption(option); - object->CreateVehicle(pos, angle, type, power, trainer, toy); - } - - if (m_fixScene && type == OBJECT_HUMAN) - { - CMotion* motion = object->GetMotion(); - if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f); - if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f); - } - - return object; -} - //! Creates a directional light int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) { @@ -6510,7 +6178,7 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) int toy = OpInt(line, "toy", 0); int option = OpInt(line, "option", 0); - CObject* obj = CreateObject(pos, dir.y, 1.0f, 0.0f, type, 0.0f, trainer, toy, option); + CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option); obj->SetDefRank(objRank); obj->SetPosition(0, pos); obj->SetAngle(0, dir); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index b25a0a4..c300b5a 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -390,9 +390,6 @@ protected: void CreateScene(bool soluce, bool fixScene, bool resetObject); Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); - CObject* CreateObject(Math::Vector pos, float angle, float zoom, - float height, ObjectType type, float power=1.0f, - bool trainer=false, bool toy=false, int option=0); int CreateLight(Math::Vector direction, Gfx::Color color); void HiliteClear(); void HiliteObject(Math::Point pos); diff --git a/src/script/script.cpp b/src/script/script.cpp index 05e2626..fbf7276 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1870,52 +1870,10 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } } - if ( type == OBJECT_FRET || - type == OBJECT_STONE || - type == OBJECT_URANIUM || - type == OBJECT_METAL || - type == OBJECT_POWER || - type == OBJECT_ATOMIC || - type == OBJECT_BULLET || - type == OBJECT_BBOX || - type == OBJECT_KEYa || - type == OBJECT_KEYb || - type == OBJECT_KEYc || - type == OBJECT_KEYd || - type == OBJECT_TNT || - type == OBJECT_SCRAP1 || - type == OBJECT_SCRAP2 || - type == OBJECT_SCRAP3 || - type == OBJECT_SCRAP4 || - type == OBJECT_SCRAP5 || - type == OBJECT_BOMB || - type == OBJECT_WAYPOINT || - type == OBJECT_SHOW || - type == OBJECT_WINFIRE || - type == OBJECT_BAG || - type == OBJECT_MARKPOWER || - type == OBJECT_MARKSTONE || - type == OBJECT_MARKURANIUM || - type == OBJECT_MARKKEYa || - type == OBJECT_MARKKEYb || - type == OBJECT_MARKKEYc || - type == OBJECT_MARKKEYd || - type == OBJECT_EGG ) - { - object = new CObject(); - if ( !object->CreateResource(pos, angle, type) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->SetActivity(false); - } - else if ( type == OBJECT_MOTHER || - type == OBJECT_ANT || - type == OBJECT_SPIDER || - type == OBJECT_BEE || - type == OBJECT_WORM ) + if ( type == OBJECT_ANT || + type == OBJECT_SPIDER || + type == OBJECT_BEE || + type == OBJECT_WORM ) { CObject* egg; @@ -1933,124 +1891,15 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user delete egg; } object->SetActivity(false); - } - else if ( type == OBJECT_PORTICO || - type == OBJECT_BASE || - type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_DESTROYER|| - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_INFO || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_PARA || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_START || - type == OBJECT_END ) - { - object = new CObject(); - if ( !object->CreateBuilding(pos, angle, 0, type) ) + } else { + object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power); + if ( object == nullptr ) { - delete object; result->SetValInt(1); // error return true; } - object->SetActivity(true); - - CAuto* automat = object->GetAuto(); - if (automat != nullptr) - { - automat->Init(); - } - script->m_main->CreateShortcuts(); } - else if ( type == OBJECT_FLAGb || - type == OBJECT_FLAGr || - type == OBJECT_FLAGg || - type == OBJECT_FLAGy || - type == OBJECT_FLAGv ) - { - object = new CObject(); - if ( !object->CreateFlag(pos, angle, type) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->SetActivity(false); - } - else if ( type == OBJECT_HUMAN || - type == OBJECT_TECH || - type == OBJECT_TOTO || - type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs || - type == OBJECT_MOBILEsa || - type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 ) - { - object = new CObject(); - if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->UpdateMapping(); - object->SetRange(30.0f); - object->SetZoom(0, 1.0f); - CPhysics* physics = object->GetPhysics(); - if ( physics != 0 ) - { - physics->SetFreeze(false); // can move - } - object->SetLock(false); // vehicle useable - // SetManual will affect bot speed - if (type == OBJECT_MOBILEdr) - { - object->SetManual(true); - } - object->SetActivity(true); - script->m_main->CreateShortcuts(); - } - else - { - result->SetValInt(1); // impossible - return true; - } if (name[0] != 0) { -- cgit v1.2.3-1-g7c22 From a36450a6dae20912ba89a9c49e8b951a20a32bfb Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 Dec 2013 15:03:21 +0100 Subject: Added tool= i drive= --- src/object/object.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ src/object/object.h | 77 +++++++++++++++++++++++++++++----------------- src/object/robotmain.cpp | 20 ++++++++++-- src/object/robotmain.h | 4 +++ src/script/cmdtoken.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- src/script/cmdtoken.h | 6 ++++ 6 files changed, 221 insertions(+), 33 deletions(-) diff --git a/src/object/object.cpp b/src/object/object.cpp index f1de424..2c32da0 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -7390,3 +7390,70 @@ void CObject::SetTraceWidth(float width) mv->SetTraceWidth(width); } +DriveType CObject::GetDriveFromObject(ObjectType type) +{ + switch(type) { + case OBJECT_MOBILEwt: + case OBJECT_MOBILEwa: + case OBJECT_MOBILEwc: + case OBJECT_MOBILEwi: + case OBJECT_MOBILEws: + return DRIVE_WHEELED; + + case OBJECT_MOBILEtt: + case OBJECT_MOBILEta: + case OBJECT_MOBILEtc: + case OBJECT_MOBILEti: + case OBJECT_MOBILEts: + return DRIVE_TRACKED; + + case OBJECT_MOBILEft: + case OBJECT_MOBILEfa: + case OBJECT_MOBILEfc: + case OBJECT_MOBILEfi: + case OBJECT_MOBILEfs: + return DRIVE_WINGED; + + case OBJECT_MOBILEit: + case OBJECT_MOBILEia: + case OBJECT_MOBILEic: + case OBJECT_MOBILEii: + case OBJECT_MOBILEis: + return DRIVE_LEGGED; + + default: + return DRIVE_OTHER; + } +} + +ToolType CObject::GetToolFromObject(ObjectType type) +{ + switch(type) { + case OBJECT_MOBILEwa: + case OBJECT_MOBILEta: + case OBJECT_MOBILEfa: + case OBJECT_MOBILEia: + return TOOL_GRABBER; + + case OBJECT_MOBILEws: + case OBJECT_MOBILEts: + case OBJECT_MOBILEfs: + case OBJECT_MOBILEis: + return TOOL_SNIFFER; + + case OBJECT_MOBILEwc: + case OBJECT_MOBILEtc: + case OBJECT_MOBILEfc: + case OBJECT_MOBILEic: + return TOOL_SHOOTER; + + case OBJECT_MOBILEwi: + case OBJECT_MOBILEti: + case OBJECT_MOBILEfi: + case OBJECT_MOBILEii: + return TOOL_ORGASHOOTER; + + default: + return TOOL_OTHER; + } +} diff --git a/src/object/object.h b/src/object/object.h index b5c0385..64689eb 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -125,34 +125,34 @@ enum ObjectType OBJECT_TREE7 = 97, //! < tree 7 OBJECT_TREE8 = 98, //! < tree 8 OBJECT_TREE9 = 99, //! < tree 9 - OBJECT_MOBILEwt = 100, //! < wheel-trainer - OBJECT_MOBILEtt = 101, //! < track-trainer - OBJECT_MOBILEft = 102, //! < fly-trainer - OBJECT_MOBILEit = 103, //! < insect-trainer - OBJECT_MOBILEwa = 110, //! < wheel-arm - OBJECT_MOBILEta = 111, //! < track-arm - OBJECT_MOBILEfa = 112, //! < fly-arm - OBJECT_MOBILEia = 113, //! < insect-arm - OBJECT_MOBILEwc = 120, //! < wheel-cannon - OBJECT_MOBILEtc = 121, //! < track-cannon - OBJECT_MOBILEfc = 122, //! < fly-cannon - OBJECT_MOBILEic = 123, //! < insect-cannon - OBJECT_MOBILEwi = 130, //! < wheel-insect-cannon - OBJECT_MOBILEti = 131, //! < track-insect-cannon - OBJECT_MOBILEfi = 132, //! < fly-insect-cannon - OBJECT_MOBILEii = 133, //! < insect-insect-cannon - OBJECT_MOBILEws = 140, //! < wheel-search - OBJECT_MOBILEts = 141, //! < track-search - OBJECT_MOBILEfs = 142, //! < fly-search - OBJECT_MOBILEis = 143, //! < insect-search - OBJECT_MOBILErt = 200, //! < roller-terraform - OBJECT_MOBILErc = 201, //! < roller-canon - OBJECT_MOBILErr = 202, //! < roller-recover - OBJECT_MOBILErs = 203, //! < roller-shield - OBJECT_MOBILEsa = 210, //! < submarine - OBJECT_MOBILEtg = 211, //! < training target - OBJECT_MOBILEdr = 212, //! < robot drawing - OBJECT_CONTROLLER = 213, //! < mission controller + OBJECT_MOBILEwt = 100, //! < PracticeBot + OBJECT_MOBILEtt = 101, //! < track-trainer (unused) + OBJECT_MOBILEft = 102, //! < fly-trainer (unused) + OBJECT_MOBILEit = 103, //! < insect-trainer (unused) + OBJECT_MOBILEwa = 110, //! < WheeledGrabber + OBJECT_MOBILEta = 111, //! < TrackedGrabber + OBJECT_MOBILEfa = 112, //! < WingedGrabber + OBJECT_MOBILEia = 113, //! < LeggedGrabber + OBJECT_MOBILEwc = 120, //! < WheeledShooter + OBJECT_MOBILEtc = 121, //! < TrackedShooter + OBJECT_MOBILEfc = 122, //! < WingedShooter + OBJECT_MOBILEic = 123, //! < LeggedShooter + OBJECT_MOBILEwi = 130, //! < WheeledOrgaShooter + OBJECT_MOBILEti = 131, //! < TrackedOrgaShooter + OBJECT_MOBILEfi = 132, //! < WingedOrgaShooter + OBJECT_MOBILEii = 133, //! < LeggedOrgaShooter + OBJECT_MOBILEws = 140, //! < WheeledSniffer + OBJECT_MOBILEts = 141, //! < TrackedSniffer + OBJECT_MOBILEfs = 142, //! < WingedSniffer + OBJECT_MOBILEis = 143, //! < LeggedSniffer + OBJECT_MOBILErt = 200, //! < Thumper + OBJECT_MOBILErc = 201, //! < PhazerShooter + OBJECT_MOBILErr = 202, //! < Recycler + OBJECT_MOBILErs = 203, //! < Shielder + OBJECT_MOBILEsa = 210, //! < Subber + OBJECT_MOBILEtg = 211, //! < TargetBot + OBJECT_MOBILEdr = 212, //! < Scribbler + OBJECT_CONTROLLER = 213, //! < MissionController OBJECT_WAYPOINT = 250, //! < waypoint OBJECT_FLAGb = 260, //! < blue flag OBJECT_FLAGr = 261, //! < red flag @@ -311,6 +311,24 @@ enum ObjectMaterial OM_MINERAL = 5, // stone }; +enum DriveType +{ + DRIVE_OTHER = 0, + DRIVE_WHEELED, + DRIVE_TRACKED, + DRIVE_WINGED, + DRIVE_LEGGED, +}; + +enum ToolType +{ + TOOL_OTHER = 0, + TOOL_GRABBER, + TOOL_SNIFFER, + TOOL_SHOOTER, + TOOL_ORGASHOOTER, +}; + struct ObjectPart { char bUsed; @@ -659,6 +677,9 @@ public: void SetTraceWidth(float width); std::string GetModelDirName(); + + static DriveType GetDriveFromObject(ObjectType type); + static ToolType GetToolFromObject(ObjectType type); protected: bool EventFrame(const Event &event); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index af463c7..0852df0 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4131,6 +4131,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_audioChange[i].max = OpInt(line, "max", 9999); m_audioChange[i].powermin = OpFloat(line, "powermin", -1); m_audioChange[i].powermax = OpFloat(line, "powermax", 100); + m_audioChange[i].tool = OpTool(line, "tool"); + m_audioChange[i].drive = OpDrive(line, "drive"); OpString(line, "filename", m_audioChange[i].music); m_audioChange[i].repeat = OpInt(line, "repeat", 1); m_audioChange[i].changed = false; @@ -4928,11 +4930,15 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { m_endTake[i].powermin = OpFloat(line, "powermin", -1); m_endTake[i].powermax = OpFloat(line, "powermax", 100); + m_endTake[i].tool = OpTool(line, "tool"); + m_endTake[i].drive = OpDrive(line, "drive"); } else { m_endTake[i].powermin = -1; m_endTake[i].powermax = 100; + m_endTake[i].tool = TOOL_OTHER; + m_endTake[i].drive = DRIVE_OTHER; } m_endTake[i].lost = OpInt(line, "lost", -1); m_endTake[i].immediat = OpInt(line, "immediat", 0); @@ -6594,8 +6600,13 @@ void CRobotMain::UpdateAudio(bool frame) { type = OBJECT_SCRAP1; } + + ToolType tool = CObject::GetToolFromObject(type); + DriveType drive = CObject::GetDriveFromObject(type); + if (m_audioChange[t].tool != TOOL_OTHER) if(tool != m_audioChange[t].tool) continue; + if (m_audioChange[t].drive != DRIVE_OTHER) if(drive != m_audioChange[t].drive) continue; - if (type != m_audioChange[t].type) continue; + if (m_audioChange[t].tool == TOOL_OTHER && m_audioChange[t].drive == DRIVE_OTHER) if (type != m_audioChange[t].type) continue; float energyLevel = -1; CObject* power = obj->GetPower(); @@ -6699,7 +6710,12 @@ Error CRobotMain::CheckEndMission(bool frame) type = OBJECT_SCRAP1; } - if (type != m_endTake[t].type) continue; + ToolType tool = CObject::GetToolFromObject(type); + DriveType drive = CObject::GetDriveFromObject(type); + if (m_endTake[t].tool != TOOL_OTHER) if(tool != m_endTake[t].tool) continue; + if (m_endTake[t].drive != DRIVE_OTHER) if(drive != m_endTake[t].drive) continue; + + if (m_endTake[t].tool == TOOL_OTHER && m_endTake[t].drive == DRIVE_OTHER) if (type != m_endTake[t].type) continue; float energyLevel = -1; CObject* power = obj->GetPower(); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index c300b5a..8d58adb 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -103,6 +103,8 @@ struct EndTake int lost; // lost if <= float powermin; // wins if energy cell >= float powermax; // wins if energy cell <= + ToolType tool; + DriveType drive; bool immediat; char message[100]; }; @@ -116,6 +118,8 @@ struct AudioChange int max; // change if < float powermin; // change if energy cell >= float powermax; // change if energy cell <= + ToolType tool; + DriveType drive; char music[100]; bool repeat; bool changed; diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index 69df68b..4508459 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -535,11 +535,11 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_INFO ) return "ExchangePost"; if ( type == OBJECT_ENERGY ) return "PowerPlant"; if ( type == OBJECT_LABO ) return "AutoLab"; -#if _GERMAN | _WG +/* TODO: #if _GERMAN | _WG if ( type == OBJECT_NUCLEAR ) return "FuelCellPlant"; -#else +#else */ if ( type == OBJECT_NUCLEAR ) return "NuclearPlant"; -#endif +/* #endif */ if ( type == OBJECT_PARA ) return "PowerCaptor"; if ( type == OBJECT_SAFE ) return "Vault"; if ( type == OBJECT_HUSTON ) return "Houston"; @@ -800,6 +800,62 @@ const char* GetCamera(Gfx::CameraType type) return "BACK"; } +// Returns the type of drive. + +DriveType GetDrive(char *line, int rank) +{ + char* p; + + p = SearchArg(line, rank); + if ( *p == 0 ) return DRIVE_OTHER; + + if ( Cmd(p, "Wheeled" ) ) return DRIVE_WHEELED; + if ( Cmd(p, "Tracked" ) ) return DRIVE_TRACKED; + if ( Cmd(p, "Winged" ) ) return DRIVE_WINGED; + if ( Cmd(p, "Legged" ) ) return DRIVE_LEGGED; + + return DRIVE_OTHER; +} + +// Returns the name of a drive. + +const char* GetDrive(DriveType type) +{ + if ( type == DRIVE_WHEELED ) return "Wheeled"; + if ( type == DRIVE_TRACKED ) return "Tracked"; + if ( type == DRIVE_WINGED ) return "Winged"; + if ( type == DRIVE_LEGGED ) return "Legged"; + return "Other"; +} + +// Returns the type of tool. + +ToolType GetTool(char *line, int rank) +{ + char* p; + + p = SearchArg(line, rank); + if ( *p == 0 ) return TOOL_OTHER; + + if ( Cmd(p, "Grabber" ) ) return TOOL_GRABBER; + if ( Cmd(p, "Sniffer" ) ) return TOOL_SNIFFER; + if ( Cmd(p, "Shooter" ) ) return TOOL_SHOOTER; + if ( Cmd(p, "OrgaShooter" ) ) return TOOL_ORGASHOOTER; + + return TOOL_OTHER; +} + +// Returns the name of a tool. + +const char* GetTool(ToolType type) +{ + if ( type == TOOL_GRABBER ) return "Grabber"; + if ( type == TOOL_SNIFFER ) return "Sniffer"; + if ( type == TOOL_SHOOTER ) return "Shooter"; + if ( type == TOOL_ORGASHOOTER ) return "OrgaShooter"; + return "Other"; +} + // Returns an integer. int OpInt(char *line, const char *op, int def) @@ -887,6 +943,24 @@ Gfx::CameraType OpCamera(char *line, const char *op) return GetCamera(line, 0); } +// Returns the type of drive. + +DriveType OpDrive(char *line, const char *op) +{ + line = SearchOp(line, op); + if ( *line == 0 ) return DRIVE_OTHER; + return GetDrive(line, 0); +} + +// Returns the type of tool. + +ToolType OpTool(char *line, const char *op) +{ + line = SearchOp(line, op); + if ( *line == 0 ) return TOOL_OTHER; + return GetTool(line, 0); +} + // Returns the type of a building. int OpBuild(char *line, const char *op) diff --git a/src/script/cmdtoken.h b/src/script/cmdtoken.h index fe831f1..24b592f 100644 --- a/src/script/cmdtoken.h +++ b/src/script/cmdtoken.h @@ -45,6 +45,10 @@ extern int GetResearch(char *line, int rank); extern Gfx::PyroType GetPyro(char *line, int rank); extern Gfx::CameraType GetCamera(char *line, int rank); extern const char* GetCamera(Gfx::CameraType type); +extern DriveType GetDrive(char *line, int rank); +extern const char* GetDrive(DriveType type); +extern ToolType GetTool(char *line, int rank); +extern const char* GetTool(ToolType type); extern int OpInt(char *line, const char *op, int def); extern float OpFloat(char *line, const char *op, float def); @@ -55,6 +59,8 @@ extern Gfx::EngineObjectType OpTypeTerrain(char *line, const char *op, Gfx::Engi extern int OpResearch(char *line, const char *op); extern Gfx::PyroType OpPyro(char *line, const char *op); extern Gfx::CameraType OpCamera(char *line, const char *op); +extern DriveType OpDrive(char *line, const char *op); +extern ToolType OpTool(char *line, const char *op); extern int OpBuild(char *line, const char *op); extern Math::Vector OpPos(char *line, const char *op); extern Math::Vector OpDir(char *line, const char *op); -- cgit v1.2.3-1-g7c22 From 12e17224b37d7db52545c00fb75c0322e0e5afad Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 Dec 2013 16:31:32 +0100 Subject: Added nullptr shecks to object.factory() Trying to fix #275 --- src/script/script.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index fbf7276..0518479 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -680,10 +680,23 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e classVars = classVars->GetNext(); // "id" int rank = classVars->GetValInt(); CObject* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank); - CAutoFactory* automat = static_cast(factory->GetAuto()); + if (factory == nullptr) { + exception = ERR_GENERIC; + result->SetValInt(ERR_GENERIC); + CLogger::GetInstancePointer()->Error("in object.factory() - factory is nullptr"); + return false; + } if ( thisType == OBJECT_FACTORY ) { + CAutoFactory* automat = static_cast(factory->GetAuto()); + if(automat == nullptr) { + exception = ERR_GENERIC; + result->SetValInt(ERR_GENERIC); + CLogger::GetInstancePointer()->Error("in object.factory() - automat is nullptr"); + return false; + } + bool bEnable = false; if ( type == OBJECT_MOBILEwa ) -- cgit v1.2.3-1-g7c22 From 3536f1c7cc52792a7d833b4f823aa515dc00d933 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 30 Dec 2013 10:51:29 +0100 Subject: Added CObjectManager::Flush() Possible fix for #275 --- src/object/objman.cpp | 16 ++++++++++++---- src/object/objman.h | 4 +++- src/object/robotmain.cpp | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/object/objman.cpp b/src/object/objman.cpp index 0471ebf..131d007 100644 --- a/src/object/objman.cpp +++ b/src/object/objman.cpp @@ -30,7 +30,7 @@ CObjectManager::CObjectManager() { m_table[i] = nullptr; } - usedCount = 0; + m_usedCount = 0; } CObjectManager::~CObjectManager() @@ -39,16 +39,16 @@ CObjectManager::~CObjectManager() bool CObjectManager::AddInstance(CObject* instance) { - if (usedCount >= MAX_OBJECTS) return false; + if (m_usedCount >= MAX_OBJECTS) return false; m_table[instance->GetID()] = instance; - usedCount++; + m_usedCount++; return true; } bool CObjectManager::DeleteInstance(CObject* instance) { - for (int i = 0; i < usedCount; i++) + for (int i = 0; i < m_usedCount; i++) { if (m_table[i] == instance) m_table[i] = nullptr; @@ -386,3 +386,11 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType return object; } +void CObjectManager::Flush() +{ + for (int i = 0; i < MAX_OBJECTS; i++) + { + m_table[i] = nullptr; + } + m_usedCount = 0; +} diff --git a/src/object/objman.h b/src/object/objman.h index 1d67468..390587b 100644 --- a/src/object/objman.h +++ b/src/object/objman.h @@ -45,9 +45,11 @@ public: CObject* SearchInstance(int id); //! Creates an object CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.f, float zoom = 1.f, float height = 0.f, bool trainer = false, bool toy = false, int option = 0); + //! Removes all objects + void Flush(); protected: CObject* m_table[MAX_OBJECTS]; - int usedCount; + int m_usedCount; }; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 0852df0..308b172 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1148,6 +1148,8 @@ void CRobotMain::ChangePhase(Phase phase) iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); Math::Point dim, pos; @@ -3869,6 +3871,8 @@ void CRobotMain::ScenePerso() iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); m_dialog->SetSceneName("perso"); m_dialog->SetSceneRank(0); @@ -6546,6 +6550,8 @@ void CRobotMain::ResetCreate() iMan->Flush(CLASS_PHYSICS); iMan->Flush(CLASS_BRAIN); iMan->Flush(CLASS_PYRO); + + CObjectManager::GetInstancePointer()->Flush(); m_camera->SetType(Gfx::CAM_TYPE_DIALOG); -- cgit v1.2.3-1-g7c22 From 4a237f5925eb0d371e097416b17dd5e919cd2258 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 31 Dec 2013 12:58:45 +0100 Subject: CPauseManager --- src/CMakeLists.txt | 1 + src/app/pausemanager.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++ src/app/pausemanager.h | 57 +++++++++++++++++++++++++++++ src/graphics/engine/engine.cpp | 13 +++---- src/graphics/engine/engine.h | 10 ++--- src/object/robotmain.cpp | 44 +++++++++++----------- src/object/robotmain.h | 6 ++- src/script/script.cpp | 11 +++--- src/script/script.h | 3 ++ src/ui/displayinfo.cpp | 11 +++--- src/ui/displayinfo.h | 19 ++++++---- src/ui/maindialog.cpp | 7 ++-- src/ui/maindialog.h | 33 +++++++++-------- src/ui/studio.cpp | 13 ++++--- src/ui/studio.h | 13 ++++--- 15 files changed, 239 insertions(+), 85 deletions(-) create mode 100644 src/app/pausemanager.cpp create mode 100644 src/app/pausemanager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c32f054..8d6b14c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,6 +65,7 @@ app/main.cpp app/system.cpp app/${SYSTEM_CPP_MODULE} app/system_other.cpp +app/pausemanager.cpp common/event.cpp common/image.cpp common/iman.cpp diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp new file mode 100644 index 0000000..847958d --- /dev/null +++ b/src/app/pausemanager.cpp @@ -0,0 +1,83 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * 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/. + +#include "app/pausemanager.h" + +#include "common/logger.h" + + +template<> CPauseManager* CSingleton::m_instance = nullptr; + + +CPauseManager::CPauseManager() +{ + m_pause = PAUSE_NONE; +} + +CPauseManager::~CPauseManager() +{ +} + +void CPauseManager::SetPause(PauseType pause) +{ + if(pause != PAUSE_NONE) { + if(m_pause != pause) + CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); + + m_pause = pause; + } else + ClearPause(); +} + +void CPauseManager::ClearPause() +{ + if(m_pause != PAUSE_NONE) + CLogger::GetInstancePointer()->Info("Game resumed\n"); + + m_pause = PAUSE_NONE; +} + +bool CPauseManager::GetPause() +{ + return m_pause != PAUSE_NONE; +} + +bool CPauseManager::GetPause(PauseType pause) +{ + return m_pause == pause; +} + +PauseType CPauseManager::GetPauseType() +{ + return m_pause; +} + +std::string CPauseManager::GetPauseName(PauseType pause) +{ + switch(pause) + { + case PAUSE_NONE: return "None"; + case PAUSE_USER: return "User"; + case PAUSE_SATCOM: return "SatCom"; + case PAUSE_DIALOG: return "Dialog"; + case PAUSE_EDITOR: return "CBot editor"; + case PAUSE_VISIT: return "Visit"; + case PAUSE_CHEAT: return "Cheat console"; + case PAUSE_PHOTO: return "Photo mode"; + default: assert(false); // Should never happen + } +} diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h new file mode 100644 index 0000000..d2c0eab --- /dev/null +++ b/src/app/pausemanager.h @@ -0,0 +1,57 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * 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/. + +/** + * \file app/pausemanager.h + * \brief Management of pause modes + */ +#pragma once + +#include "common/singleton.h" + +#include + + +enum PauseType { + PAUSE_NONE = 0, + PAUSE_USER, + PAUSE_SATCOM, + PAUSE_DIALOG, + PAUSE_EDITOR, + PAUSE_VISIT, + PAUSE_CHEAT, + PAUSE_PHOTO +}; + +class CPauseManager : public CSingleton +{ +public: + CPauseManager(); + ~CPauseManager(); + + void SetPause(PauseType pause); + void ClearPause(); + bool GetPause(); + bool GetPause(PauseType pause); + PauseType GetPauseType(); + +private: + std::string GetPauseName(PauseType pause); + + PauseType m_pause; +}; + diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5cf7b23..0ee7715 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -63,6 +63,7 @@ CEngine::CEngine(CApplication *app) m_planet = nullptr; m_sound = nullptr; m_terrain = nullptr; + m_pause = nullptr; m_showStats = false; @@ -80,7 +81,6 @@ CEngine::CEngine(CApplication *app) m_fogStart[1] = 0.75f; m_waterAddColor = Color(0.0f, 0.0f, 0.0f, 0.0f); - m_pause = false; m_render = true; m_movieLock = false; m_shadowVisible = true; @@ -179,6 +179,7 @@ CEngine::~CEngine() m_lightning = nullptr; m_planet = nullptr; m_terrain = nullptr; + m_pause = nullptr; GetSystemUtils()->DestroyTimeStamp(m_lastFrameTime); m_lastFrameTime = nullptr; @@ -252,6 +253,7 @@ bool CEngine::Create() m_cloud = new CCloud(this); m_lightning = new CLightning(this); m_planet = new CPlanet(this); + m_pause = new CPauseManager(); m_lightMan->SetDevice(m_device); m_particle->SetDevice(m_device); @@ -422,18 +424,13 @@ void CEngine::FrameUpdate() bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height) { // TODO write screenshot: not very important for now - GetLogger()->Trace("CEngine::WriteSceenShot(): stub!\n"); + GetLogger()->Debug("CEngine::WriteSceenShot(): stub!\n"); return true; } -void CEngine::SetPause(bool pause) -{ - m_pause = pause; -} - bool CEngine::GetPause() { - return m_pause; + return m_pause->GetPause(); } void CEngine::SetMovieLock(bool lock) diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 5ecde8f..d56bf38 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -24,6 +24,7 @@ #include "app/system.h" +#include "app/pausemanager.h" #include "common/event.h" #include "common/singleton.h" @@ -734,11 +735,8 @@ public: bool WriteScreenShot(const std::string& fileName, int width, int height); - //@{ - //! Management of game pause mode - void SetPause(bool pause); + //! Get pause mode TEST_VIRTUAL bool GetPause(); - //@} //@{ //! Management of lock for the duration of movie sequence @@ -1288,6 +1286,7 @@ protected: CLightning* m_lightning; CPlanet* m_planet; CTerrain* m_terrain; + CPauseManager* m_pause; //! Last encountered error std::string m_error; @@ -1300,9 +1299,6 @@ protected: //! Whether to show stats (FPS, etc) bool m_showStats; std::string m_fpsText; - - //! Pause mode - bool m_pause; //! Rendering enabled? bool m_render; //! Lock for duration of movie? diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 308b172..f1923a5 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -618,6 +618,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_cloud = m_engine->GetCloud(); m_lightning = m_engine->GetLightning(); m_planet = m_engine->GetPlanet(); + m_pause = CPauseManager::GetInstancePointer(); m_interface = new Ui::CInterface(); m_terrain = new Gfx::CTerrain(); @@ -663,7 +664,6 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_satComLock = false; m_editLock = false; m_editFull = false; - m_pause = false; m_hilite = false; m_freePhoto = false; m_showPos = false; @@ -1110,7 +1110,7 @@ void CRobotMain::ChangePhase(Phase phase) m_resetCreate = false; m_engine->SetMovieLock(m_movieLock); - ChangePause(false); + ChangePause(PAUSE_NONE); FlushDisplayInfo(); m_engine->SetRankView(0); m_terrain->FlushRelief(); @@ -1387,7 +1387,7 @@ bool CRobotMain::ProcessEvent(Event &event) MainMovieType type = m_movie->GetStopType(); if (type == MM_SATCOMopen) { - ChangePause(false); + ChangePause(PAUSE_NONE); SelectObject(m_infoObject, false); // hands over the command buttons m_map->ShowMap(m_mapShow); m_displayText->HideText(false); @@ -1419,7 +1419,7 @@ bool CRobotMain::ProcessEvent(Event &event) if (pe == nullptr) return false; pe->SetState(Ui::STATE_VISIBLE); pe->SetFocus(true); - if (m_phase == PHASE_SIMUL) ChangePause(true); + if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_CHEAT); m_cmdEdit = true; return false; } @@ -1432,7 +1432,7 @@ bool CRobotMain::ProcessEvent(Event &event) pe->GetText(cmd, 50); pe->SetText(""); pe->ClearState(Ui::STATE_VISIBLE); - if (m_phase == PHASE_SIMUL) ChangePause(false); + if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_NONE); ExecuteCmd(cmd); m_cmdEdit = false; return false; @@ -1562,7 +1562,7 @@ bool CRobotMain::ProcessEvent(Event &event) m_camera->GetType() != Gfx::CAM_TYPE_VISIT && !m_movie->IsExist()) { - ChangePause(!m_engine->GetPause()); + ChangePause(m_pause->GetPause(PAUSE_USER) ? PAUSE_NONE : PAUSE_USER); } } if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).primary || @@ -1891,12 +1891,12 @@ void CRobotMain::ExecuteCmd(char *cmd) if (m_freePhoto) { m_camera->SetType(Gfx::CAM_TYPE_FREE); - ChangePause(true); + ChangePause(PAUSE_PHOTO); } else { m_camera->SetType(Gfx::CAM_TYPE_BACK); - ChangePause(false); + ChangePause(PAUSE_NONE); } return; } @@ -1907,7 +1907,7 @@ void CRobotMain::ExecuteCmd(char *cmd) if (m_freePhoto) { m_camera->SetType(Gfx::CAM_TYPE_FREE); - ChangePause(true); + ChangePause(PAUSE_PHOTO); DeselectAll(); // removes the control buttons m_map->ShowMap(false); m_displayText->HideText(true); @@ -1915,7 +1915,7 @@ void CRobotMain::ExecuteCmd(char *cmd) else { m_camera->SetType(Gfx::CAM_TYPE_BACK); - ChangePause(false); + ChangePause(PAUSE_NONE); m_map->ShowMap(m_mapShow); m_displayText->HideText(false); } @@ -2174,7 +2174,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) { m_movieInfoIndex = index; m_movie->Start(MM_SATCOMopen, 2.5f); - ChangePause(true); + ChangePause(PAUSE_SATCOM); m_infoObject = DeselectAll(); // removes the control buttons m_displayText->HideText(true); return; @@ -2184,7 +2184,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) if (m_movie->IsExist()) { m_movie->Stop(); - ChangePause(false); + ChangePause(PAUSE_NONE); SelectObject(m_infoObject, false); // hands over the command buttons m_displayText->HideText(false); } @@ -2476,7 +2476,7 @@ void CRobotMain::StartDisplayVisit(EventType event) m_camera->StartVisit(m_displayText->GetVisitGoal(event), m_displayText->GetVisitDist(event)); m_displayText->SetVisit(event); - ChangePause(true); + ChangePause(PAUSE_VISIT); } //! Move the arrow to visit @@ -2530,7 +2530,7 @@ void CRobotMain::StopDisplayVisit() m_camera->StopVisit(); m_displayText->ClearVisit(); - ChangePause(false); + ChangePause(PAUSE_NONE); if (m_visitObject != 0) { SelectObject(m_visitObject, false); // gives the command buttons @@ -2628,7 +2628,7 @@ bool CRobotMain::SelectObject(CObject* obj, bool displayError) if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) StopDisplayVisit(); - if (m_movieLock || m_editLock || m_pause) return false; + if (m_movieLock || m_editLock || m_pause->GetPause()) return false; if (m_movie->IsExist()) return false; if (obj == nullptr || !IsSelectable(obj)) return false; @@ -3530,7 +3530,7 @@ bool CRobotMain::EventFrame(const Event &event) } // Moves edition indicator. - if (m_editLock || m_pause) // edition in progress? + if (m_editLock || m_pause->GetPause()) // edition in progress? { Ui::CControl* pc = m_interface->SearchControl(EVENT_OBJECT_EDITLOCK); if (pc != nullptr) @@ -7022,14 +7022,16 @@ float CRobotMain::GetPersoAngle() //! Changes on the pause mode -void CRobotMain::ChangePause(bool pause) +void CRobotMain::ChangePause(PauseType pause) { - m_pause = pause; - m_engine->SetPause(m_pause); + if(pause != PAUSE_NONE) + m_pause->SetPause(pause); + else + m_pause->ClearPause(); - m_sound->MuteAll(m_pause); + m_sound->MuteAll(m_pause->GetPause()); CreateShortcuts(); - if (m_pause) HiliteClear(); + if (m_pause->GetPause()) HiliteClear(); } diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 8d58adb..4fa842a 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -30,6 +30,8 @@ #include "object/object.h" #include "object/mainmovie.h" +#include "app/pausemanager.h" + #include enum Phase @@ -253,7 +255,7 @@ public: void SetTracePrecision(float factor); float GetTracePrecision(); - void ChangePause(bool pause); + void ChangePause(PauseType pause); void SetSpeed(float speed); float GetSpeed(); @@ -440,6 +442,7 @@ protected: Ui::CDisplayText* m_displayText; Ui::CDisplayInfo* m_displayInfo; CSoundInterface* m_sound; + CPauseManager* m_pause; //! Bindings for user inputs InputBinding m_inputBindings[INPUT_SLOT_MAX]; @@ -495,7 +498,6 @@ protected: bool m_satComLock; // call of SatCom is possible? bool m_editLock; // edition in progress? bool m_editFull; // edition in full screen? - bool m_pause; // simulation paused bool m_hilite; bool m_trainerPilot; // remote trainer? bool m_suspend; diff --git a/src/script/script.cpp b/src/script/script.cpp index 0518479..0b3eec4 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -3423,6 +3423,7 @@ CScript::CScript(CObject* object, CTaskManager** secondaryTask) m_secondaryTask = secondaryTask; m_interface = m_main->GetInterface(); + m_pause = CPauseManager::GetInstancePointer(); m_ipf = CBOT_IPF; m_errMode = ERM_STOP; @@ -3821,12 +3822,12 @@ bool CScript::Continue(const Event &event) GetError(s); m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR); } - m_engine->SetPause(true); // gives pause + m_pause->SetPause(PAUSE_EDITOR); // gives pause return true; } if ( !m_bContinue ) { - m_engine->SetPause(true); // gives pause + m_pause->SetPause(PAUSE_EDITOR); // gives pause } } @@ -3869,9 +3870,9 @@ bool CScript::Step(const Event &event) if ( !m_bRun ) return true; if ( !m_bStepMode ) return false; - m_engine->SetPause(false); + // ??? m_engine->SetPause(false); // TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms - m_engine->SetPause(true); + // ??? m_engine->SetPause(true); m_event = event; @@ -3901,7 +3902,7 @@ bool CScript::Step(const Event &event) if ( m_bContinue ) // instuction "move", "goto", etc. ? { - m_engine->SetPause(false); // removes the pause + m_pause->ClearPause(); // removes the pause } return false; } diff --git a/src/script/script.h b/src/script/script.h index 9d8d372..177d40a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -24,6 +24,8 @@ #include "common/event.h" +#include "app/pausemanager.h" + #include "CBot/CBotDll.h" #include @@ -217,6 +219,7 @@ protected: CTaskManager* m_primaryTask; CTaskManager** m_secondaryTask; CObject* m_object; + CPauseManager* m_pause; int m_ipf; // number of instructions/second int m_errMode; // what to do in case of error diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 79eb38a..8db53c5 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -59,6 +59,7 @@ CDisplayInfo::CDisplayInfo() m_main = CRobotMain::GetInstancePointer(); m_interface = m_main->GetInterface(); m_camera = m_main->GetCamera(); + m_pause = CPauseManager::GetInstancePointer(); m_bInfoMaximized = true; m_bInfoMinimized = false; @@ -330,13 +331,13 @@ void CDisplayInfo::HyperUpdate() void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluce) { - Gfx::Light light; + Gfx::Light light; Math::Point pos, dim; Ui::CWindow* pw; Ui::CEdit* edit; Ui::CButton* button; Ui::CSlider* slider; - CMotionToto* toto; + CMotionToto* toto; m_index = index; m_bSoluce = bSoluce; @@ -355,8 +356,8 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_main->SetEditLock(true, false); m_main->SetEditFull(false); - m_bInitPause = m_engine->GetPause(); - m_engine->SetPause(true); + m_bInitPause = m_pause->GetPauseType(); + m_pause->SetPause(PAUSE_SATCOM); m_infoCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_INFO); @@ -839,7 +840,7 @@ void CDisplayInfo::StopDisplayInfo() } else { - if ( !m_bInitPause ) m_engine->SetPause(false); + m_pause->SetPause(m_bInitPause); m_main->SetEditLock(false, false); } m_camera->SetType(m_infoCamera); diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index eea50b7..891551b 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -25,6 +25,8 @@ #include "graphics/engine/camera.h" +#include "app/pausemanager.h" + class CRobotMain; class CObject; class CEventQueue; @@ -67,13 +69,14 @@ protected: void CreateObjectsFile(); protected: - Gfx::CEngine* m_engine; - CEventQueue* m_event; - CRobotMain* m_main; - Gfx::CCamera* m_camera; - CInterface* m_interface; - Gfx::CParticle* m_particle; - Gfx::CLightManager* m_light; + Gfx::CEngine* m_engine; + CEventQueue* m_event; + CRobotMain* m_main; + Gfx::CCamera* m_camera; + CInterface* m_interface; + Gfx::CParticle* m_particle; + Gfx::CLightManager* m_light; + CPauseManager* m_pause; bool m_bInfoMaximized; bool m_bInfoMinimized; @@ -88,7 +91,7 @@ protected: Math::Point m_infoFinalDim; int m_lightSuppl; bool m_bEditLock; - bool m_bInitPause; + PauseType m_bInitPause; bool m_bSoluce; CObject* m_toto; }; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index f3eca3a..b954c71 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -120,6 +120,7 @@ CMainDialog::CMainDialog() m_camera = m_main->GetCamera(); m_engine = Gfx::CEngine::GetInstancePointer(); m_particle = m_engine->GetParticle(); + m_pause = CPauseManager::GetInstancePointer(); m_phase = PHASE_NAME; m_phaseSetup = PHASE_SETUPg; @@ -6401,8 +6402,8 @@ void CMainDialog::StartSuspend() { m_sound->MuteAll(true); m_main->ClearInterface(); - m_bInitPause = m_engine->GetPause(); - m_engine->SetPause(true); + m_bInitPause = m_pause->GetPauseType(); + m_pause->SetPause(PAUSE_DIALOG); m_engine->SetOverFront(false); // over flat behind m_main->CreateShortcuts(); m_main->StartSuspend(); @@ -6416,7 +6417,7 @@ void CMainDialog::StopSuspend() { m_sound->MuteAll(false); m_main->ClearInterface(); - if ( !m_bInitPause ) m_engine->SetPause(false); + m_pause->SetPause(m_bInitPause); m_engine->SetOverFront(true); // over flat front m_main->CreateShortcuts(); m_main->StopSuspend(); diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index 96aff2a..444a568 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -23,6 +23,8 @@ #include "object/robotmain.h" +#include "app/pausemanager.h" + #include #include @@ -186,6 +188,7 @@ protected: Gfx::CParticle* m_particle; Gfx::CCamera* m_camera; CSoundInterface* m_sound; + CPauseManager* m_pause; Phase m_phase; // copy of CRobotMain Phase m_phaseSetup; // tab selected @@ -242,26 +245,26 @@ protected: bool m_bCameraInvertY; // for CCamera bool m_bEffect; // for CCamera - Math::Point m_glintMouse; - float m_glintTime; + Math::Point m_glintMouse; + float m_glintTime; - int m_loadingCounter; + int m_loadingCounter; - bool m_bDialog; // this dialogue? - bool m_bDialogFire; // setting on fire? - bool m_bDialogDelete; - Math::Point m_dialogPos; - Math::Point m_dialogDim; - float m_dialogParti; - float m_dialogTime; - bool m_bInitPause; + bool m_bDialog; // this dialogue? + bool m_bDialogFire; // setting on fire? + bool m_bDialogDelete; + Math::Point m_dialogPos; + Math::Point m_dialogDim; + float m_dialogParti; + float m_dialogTime; + PauseType m_bInitPause; Gfx::CameraType m_initCamera; - int m_partiPhase[10]; - float m_partiTime[10]; - Math::Point m_partiPos[10]; + int m_partiPhase[10]; + float m_partiTime[10]; + Math::Point m_partiPos[10]; - SceneInfo m_sceneInfo[MAXSCENE]; + SceneInfo m_sceneInfo[MAXSCENE]; std::vector m_saveList; }; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index fb4dd3d..5a3b403 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -71,6 +71,7 @@ CStudio::CStudio() m_main = CRobotMain::GetInstancePointer(); m_interface = m_main->GetInterface(); m_camera = m_main->GetCamera(); + m_pause = CPauseManager::GetInstancePointer(); m_bEditMaximized = false; m_bEditMinimized = false; @@ -563,7 +564,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, int rank) m_main->SetEditLock(true, true); m_main->SetEditFull(false); - m_bInitPause = m_engine->GetPause(); + m_bInitPause = m_pause->GetPauseType(); m_main->SetSpeed(1.0f); m_editCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_EDIT); @@ -882,7 +883,7 @@ bool CStudio::StopEditScript(bool bCancel) button->SetState(STATE_VISIBLE); } - if ( !m_bInitPause ) m_engine->SetPause(false); + m_pause->SetPause(m_bInitPause); m_sound->MuteAll(false); m_main->SetEditLock(false, true); m_camera->SetType(m_editCamera); @@ -954,22 +955,22 @@ void CStudio::UpdateFlux() #if 1 if ( m_bRealTime ) // run? { - m_engine->SetPause(false); + m_pause->ClearPause(); m_sound->MuteAll(false); } else // step by step? { - m_engine->SetPause(true); + m_pause->SetPause(PAUSE_EDITOR); m_sound->MuteAll(true); } #else - m_engine->SetPause(false); + m_pause->ClearPause(); m_sound->MuteAll(false); #endif } else // stop? { - m_engine->SetPause(true); + m_pause->SetPause(PAUSE_EDITOR); m_sound->MuteAll(true); } } diff --git a/src/ui/studio.h b/src/ui/studio.h index 1c14124..d1c6a51 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -22,6 +22,8 @@ #include "graphics/engine/camera.h" +#include "app/pausemanager.h" + #include namespace fs = boost::filesystem; @@ -96,6 +98,7 @@ protected: CSoundInterface* m_sound; CInterface* m_interface; CApplication* m_app; + CPauseManager* m_pause; int m_rank; CScript* m_script; @@ -109,11 +112,11 @@ protected: Math::Point m_editFinalPos; Math::Point m_editFinalDim; - float m_time; - float m_fixInfoTextTime; - bool m_bRunning; - bool m_bRealTime; - bool m_bInitPause; + float m_time; + float m_fixInfoTextTime; + bool m_bRunning; + bool m_bRealTime; + PauseType m_bInitPause; std::string m_helpFilename; StudioDialog m_dialog; -- cgit v1.2.3-1-g7c22 From 999490e88bc699b671b94b88c9a4327d963db378 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 31 Dec 2013 16:58:21 +0100 Subject: Code for changing music in pause mode As requested by @Emxx52. Only code for now, we don't have the music yet. Temporairly in developements builds music will change to Prototype (in CBot editor) and Constructive Destruction (in SatCom) --- src/app/pausemanager.cpp | 49 ++++++++++++++++++++++++++++++-------- src/app/pausemanager.h | 5 ++++ src/object/robotmain.cpp | 2 +- src/sound/oalsound/alsound.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ src/sound/oalsound/alsound.h | 9 ++++--- src/sound/oalsound/channel.cpp | 15 ++++++++++++ src/sound/oalsound/channel.h | 1 + src/sound/sound.cpp | 14 +++++++++++ src/sound/sound.h | 25 +++++++++++++------ 9 files changed, 153 insertions(+), 21 deletions(-) diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index 847958d..761e158 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -15,6 +15,7 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. +#include "app/app.h" #include "app/pausemanager.h" #include "common/logger.h" @@ -25,18 +26,43 @@ template<> CPauseManager* CSingleton::m_instance = nullptr; CPauseManager::CPauseManager() { + m_sound = CApplication::GetInstancePointer()->GetSound(); + m_pause = PAUSE_NONE; } CPauseManager::~CPauseManager() { + m_sound = nullptr; } void CPauseManager::SetPause(PauseType pause) { if(pause != PAUSE_NONE) { - if(m_pause != pause) + if(m_pause != pause) { CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); + switch(pause) { + case PAUSE_EDITOR: + // TODO: We don't have this music yet + // m_sound->PlayPauseMusic(""); + #if DEV_BUILD + m_sound->PlayPauseMusic("Prototype.ogg"); + #endif + break; + + case PAUSE_SATCOM: + // TODO: We don't have this music yet + // m_sound->PlayPauseMusic(""); + #if DEV_BUILD + m_sound->PlayPauseMusic("Constructive.ogg"); + #endif + break; + + default: + // Don't change music + break; + } + } m_pause = pause; } else @@ -45,8 +71,10 @@ void CPauseManager::SetPause(PauseType pause) void CPauseManager::ClearPause() { - if(m_pause != PAUSE_NONE) + if(m_pause != PAUSE_NONE) { CLogger::GetInstancePointer()->Info("Game resumed\n"); + m_sound->StopPauseMusic(); + } m_pause = PAUSE_NONE; } @@ -70,14 +98,15 @@ std::string CPauseManager::GetPauseName(PauseType pause) { switch(pause) { - case PAUSE_NONE: return "None"; - case PAUSE_USER: return "User"; - case PAUSE_SATCOM: return "SatCom"; - case PAUSE_DIALOG: return "Dialog"; - case PAUSE_EDITOR: return "CBot editor"; - case PAUSE_VISIT: return "Visit"; - case PAUSE_CHEAT: return "Cheat console"; - case PAUSE_PHOTO: return "Photo mode"; + case PAUSE_NONE: return "None"; + case PAUSE_USER: return "User"; + case PAUSE_SATCOM: return "SatCom"; + case PAUSE_SATCOMMOVIE: return "SatCom opening animation"; + case PAUSE_DIALOG: return "Dialog"; + case PAUSE_EDITOR: return "CBot editor"; + case PAUSE_VISIT: return "Visit"; + case PAUSE_CHEAT: return "Cheat console"; + case PAUSE_PHOTO: return "Photo mode"; default: assert(false); // Should never happen } } diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h index d2c0eab..fefc4a5 100644 --- a/src/app/pausemanager.h +++ b/src/app/pausemanager.h @@ -22,6 +22,7 @@ #pragma once #include "common/singleton.h" +#include "sound/sound.h" #include @@ -30,6 +31,7 @@ enum PauseType { PAUSE_NONE = 0, PAUSE_USER, PAUSE_SATCOM, + PAUSE_SATCOMMOVIE, PAUSE_DIALOG, PAUSE_EDITOR, PAUSE_VISIT, @@ -52,6 +54,9 @@ public: private: std::string GetPauseName(PauseType pause); +private: + CSoundInterface* m_sound; + PauseType m_pause; }; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index f1923a5..f8db286 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -2174,7 +2174,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) { m_movieInfoIndex = index; m_movie->Start(MM_SATCOMopen, 2.5f); - ChangePause(PAUSE_SATCOM); + ChangePause(PAUSE_SATCOMMOVIE); m_infoObject = DeselectAll(); // removes the control buttons m_displayText->HideText(true); return; diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 7f5d1f1..5058141 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -31,6 +31,8 @@ ALSound::ALSound() m_currentMusic = nullptr; m_eye.LoadZero(); m_lookat.LoadZero(); + m_previousMusic.fadeTime = 0.0f; + m_previousMusic.music = nullptr; } @@ -62,6 +64,11 @@ void ALSound::CleanUp() { delete item.music; } + + if (m_previousMusic.music) + { + delete m_previousMusic.music; + } for (auto item : m_sounds) { @@ -552,6 +559,15 @@ void ALSound::FrameMove(float delta) } } + if (m_previousMusic.fadeTime > 0.0f) { + if (m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + m_previousMusic.music->Pause(); + } else { + m_previousMusic.currentTime += delta; + m_previousMusic.music->SetVolume(((m_previousMusic.fadeTime-m_previousMusic.currentTime) / m_previousMusic.fadeTime) * m_musicVolume); + } + } + for (auto it : toRemove) m_oldMusic.remove(it); } @@ -609,6 +625,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim buffer = new Buffer(); buffer->LoadFromFile(file.str(), static_cast(-1)); + m_music[filename] = buffer; } else { @@ -633,6 +650,43 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return true; } +bool ALSound::PlayPauseMusic(const std::string &filename) +{ + if (m_previousMusic.fadeTime > 0.0f) { + OldMusic old; + old.music = m_currentMusic; + old.fadeTime = 2.0f; + old.currentTime = 0.0f; + m_oldMusic.push_back(old); + m_currentMusic = nullptr; + } else { + if (m_currentMusic) { + m_previousMusic.music = m_currentMusic; + m_previousMusic.fadeTime = 2.0f; + m_previousMusic.currentTime = 0.0f; + m_currentMusic = nullptr; + } + } + return PlayMusic(filename, true); +} + +void ALSound::StopPauseMusic() +{ + if (m_previousMusic.fadeTime > 0.0f) { + StopMusic(); + + m_currentMusic = m_previousMusic.music; + m_previousMusic.music = nullptr; + if(m_currentMusic != nullptr) { + m_currentMusic->SetVolume(m_musicVolume); + if(m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + m_currentMusic->Play(); + } + } + m_previousMusic.fadeTime = 0.0f; + } +} + bool ALSound::RestartMusic() { diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index cd3bdd5..6fb832e 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -72,12 +72,14 @@ public: bool StopAll(); bool MuteAll(bool bMute); - bool PlayMusic(int rank, bool bRepeat, float fadeTime=5.0f); - bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=5.0f); + bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f); + bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f); bool RestartMusic(); void SuspendMusic(); - void StopMusic(float fadeTime=5.0f); + void StopMusic(float fadeTime=2.0f); bool IsPlayingMusic(); + bool PlayPauseMusic(const std::string &filename); + void StopPauseMusic(); private: void CleanUp(); @@ -94,6 +96,7 @@ private: std::map m_channels; Channel *m_currentMusic; std::list m_oldMusic; + OldMusic m_previousMusic; Math::Vector m_eye; Math::Vector m_lookat; }; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index b053316..e58ab54 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -74,6 +74,21 @@ bool Channel::Play() return true; } +bool Channel::Pause() +{ + if(!m_ready || !IsPlaying()) + { + return false; + } + + alSourcePause(m_source); + if (alCheck()) + { + GetLogger()->Warn("Could not pause audio sound source. Code: %d\n", alGetCode()); + } + return true; +} + bool Channel::SetPosition(const Math::Vector &pos) { diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 0c6cafc..f973198 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -50,6 +50,7 @@ public: ~Channel(); bool Play(); + bool Pause(); bool Stop(); bool SetPosition(const Math::Vector &); diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 1605e2b..3802611 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -59,6 +59,12 @@ void CSoundInterface::AddMusicFiles(const std::string &path) CacheMusic("Intro2.ogg"); CacheMusic("music010.ogg"); CacheMusic("music011.ogg"); + // TODO: Add pause music here + // CacheMusic(""); + #if DEV_BUILD + CacheMusic("Prototype.ogg"); + CacheMusic("Constructive.ogg"); + #endif } bool CSoundInterface::Cache(Sound bSound, const std::string &bFile) @@ -175,3 +181,11 @@ bool CSoundInterface::IsPlayingMusic() return true; } +bool CSoundInterface::PlayPauseMusic(const std::string &filename) +{ + return true; +} + +void CSoundInterface::StopPauseMusic() +{ +} diff --git a/src/sound/sound.h b/src/sound/sound.h index d2eee9c..135ee43 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -287,7 +287,7 @@ public: * \param fadeTime - time of transition between music * \return return true on success */ - virtual bool PlayMusic(int rank, bool bRepeat, float fadeTime=5.0f); + virtual bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f); /** Start playing music * \param filename - name of file to play @@ -295,27 +295,38 @@ public: * \param fadeTime - time of transition between music * \return return true on success */ - virtual bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=5.0f); + virtual bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f); /** Restart music - * @return return true on success + * \return return true on success */ virtual bool RestartMusic(); - /** Susspend paying music - * \return return true on success + /** Susspend playing music + * \return nothing */ virtual void SuspendMusic(); /** Stop playing music - * \return return true on success + * \return nothing */ - virtual void StopMusic(float fadeTime=5.0f); + virtual void StopMusic(float fadeTime=2.0f); /** Check if music if playing * \return return true if music is playing */ virtual bool IsPlayingMusic(); + + /** Start playing pause music + * \param filename - name of file to play + * \return return true on success + */ + virtual bool PlayPauseMusic(const std::string &filename); + + /** Stop playing pause music and return to the mission music + * \return nothing + */ + virtual void StopPauseMusic(); protected: std::string m_soundPath; -- cgit v1.2.3-1-g7c22 From 8d30791595cf981b08310472faa2066a99aa9595 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 31 Dec 2013 17:20:03 +0100 Subject: Ability to set language via ini file If language autodetection doesn't work, someone might want to manually force the game to use correct language without using -language parameter every time --- src/app/app.cpp | 10 ++++++++++ src/common/profile.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 566be33..8b5533e 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -425,6 +425,16 @@ bool CApplication::Create() return false; } + if (GetProfile().GetLocalProfileString("Language", "Lang", path)) { + Language language; + if (ParseLanguage(path, language)) { + m_language = language; + GetLogger()->Error("Setting language '%s' from ini file\n", path.c_str()); + } else { + GetLogger()->Error("Invalid language '%s' in ini file\n", path.c_str()); + } + } + SetLanguage(m_language); //Create the sound instance. diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 77c70c3..ee3e873 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -91,7 +91,7 @@ bool CProfile::SetLocalProfileString(std::string section, std::string key, std:: } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -106,7 +106,7 @@ bool CProfile::GetLocalProfileString(std::string section, std::string key, std:: } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -122,7 +122,7 @@ bool CProfile::SetLocalProfileInt(std::string section, std::string key, int valu } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -137,7 +137,7 @@ bool CProfile::GetLocalProfileInt(std::string section, std::string key, int &val } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -153,7 +153,7 @@ bool CProfile::SetLocalProfileFloat(std::string section, std::string key, float } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -168,7 +168,7 @@ bool CProfile::GetLocalProfileFloat(std::string section, std::string key, float } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); return false; } return true; @@ -178,7 +178,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 > ret_list; - boost::regex re(key + "[0-9]*"); //we want to match all key followed my any number + boost::regex re(key + "[0-9]*"); //we want to match all key followed by any number try { @@ -192,7 +192,7 @@ std::vector< std::string > CProfile::GetLocalProfileSection(std::string section, } catch (std::exception & e) { - GetLogger()->Error("Error on parsing profile: %s\n", e.what()); + GetLogger()->Info("Error on parsing profile: %s\n", e.what()); } return ret_list; -- cgit v1.2.3-1-g7c22 From 3d7017525bfe6563dc7cf93f5b1788e86bd98ce8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 31 Dec 2013 19:09:54 +0100 Subject: Added camerafocus() for changing camera --- src/script/cbottoken.cpp | 3 +++ src/script/script.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/script/script.h | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 9f99752..81219df 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -334,6 +334,7 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "penup" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penup.txt"); if ( strcmp(token, "pencolor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pencolor.txt"); if ( strcmp(token, "penwidth" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penwidth.txt"); + if ( strcmp(token, "camerafocus" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/camerafocus.txt"); if ( strcmp(token, "extern" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/extern.txt"); if ( strcmp(token, "class" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/class.txt"); if ( strcmp(token, "static" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/static.txt"); @@ -441,6 +442,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "penup" ) == 0 ) return true; if ( strcmp(token, "pencolor" ) == 0 ) return true; if ( strcmp(token, "penwidth" ) == 0 ) return true; + if ( strcmp(token, "camerafocus" ) == 0 ) return true; if ( strcmp(token, "sizeof" ) == 0 ) return true; return false; } @@ -535,6 +537,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "penup" ) == 0 ) return "penup ( );"; if ( strcmp(token, "pencolor" ) == 0 ) return "pencolor ( color );"; if ( strcmp(token, "penwidth" ) == 0 ) return "penwidth ( width );"; + if ( strcmp(token, "camerafocus") == 0 ) return "camerafocus ( object );"; return ""; } diff --git a/src/script/script.cpp b/src/script/script.cpp index 0b3eec4..6fcd883 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1639,7 +1639,7 @@ CBotTypResult CScript::cCanBuild(CBotVar* &var, void* user) return CBotTypResult(CBotTypBoolean); } -// Instruction "canbuid ( category );" +// Instruction "canbuild ( category );" // returns true if this building can be built bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user) @@ -3407,6 +3407,47 @@ bool CScript::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* use return true; } +// Compilation of the instruction with one object parameter + +CBotTypResult CScript::cOneObject(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + var = var->GetNext(); + if ( var == 0 ) return CBotTypResult(CBotTypFloat); + + return CBotTypResult(CBotErrOverParam); +} + +// Instruction "camerafocus(object)". + +bool CScript::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CScript* script = (static_cast(user))->GetRunScript(); + + CBotVar* classVars = var->GetItemList(); // "category" + classVars = classVars->GetNext(); // "position" + classVars = classVars->GetNext(); // "orientation" + classVars = classVars->GetNext(); // "pitch" + classVars = classVars->GetNext(); // "roll" + classVars = classVars->GetNext(); // "energyLevel" + classVars = classVars->GetNext(); // "shieldLevel" + classVars = classVars->GetNext(); // "temperature" + classVars = classVars->GetNext(); // "altitude" + classVars = classVars->GetNext(); // "lifeTime" + classVars = classVars->GetNext(); // "material" + classVars = classVars->GetNext(); // "energyCell" + classVars = classVars->GetNext(); // "load" + classVars = classVars->GetNext(); // "id" + int rank = classVars->GetValInt(); + CObject* object = CObjectManager::GetInstancePointer()->SearchInstance(rank); + + script->m_main->SelectObject(object, false); + + result->SetValInt(ERR_OK); + exception = ERR_OK; + return true; +} + // Object's constructor. @@ -3507,6 +3548,8 @@ void CScript::InitFonctions() CBotProgram::AddFunction("penup", rPenUp, CScript::cNull); CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat); CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat); + + CBotProgram::AddFunction("camerafocus", rCameraFocus, CScript::cOneObject); CBotProgram::AddFunction("canbuild", rCanBuild, CScript::cCanBuild); CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat); diff --git a/src/script/script.h b/src/script/script.h index 177d40a..afb89c8 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -128,6 +128,7 @@ private: static CBotTypResult cPenDown(CBotVar* &var, void* user); static CBotTypResult cOnePoint(CBotVar* &var, void* user); static CBotTypResult cPoint(CBotVar* &var, void* user); + static CBotTypResult cOneObject(CBotVar* &var, void* user); static bool rSin(CBotVar* var, CBotVar* result, int& exception, void* user); @@ -192,6 +193,7 @@ private: static bool rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user); public: static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var); -- cgit v1.2.3-1-g7c22 From 90437d1765eaf8b17cb9575632cb95739cfe80c2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 16:45:08 +0100 Subject: Fixed two bugs in dc81cda4b1f27af6fe8abcd566ffac03255f2642 * win/end scene animations * produce() was producing empty cells --- src/object/robotmain.cpp | 7 +++++++ src/script/script.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index f8db286..0d95907 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4630,6 +4630,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) trainer = OpInt(line, "trainer", 0), OpInt(line, "toy", 0), OpInt(line, "option", 0)); + + if (m_fixScene && type == OBJECT_HUMAN) + { + CMotion* motion = obj->GetMotion(); + if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f); + if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f); + } if (obj != nullptr) { diff --git a/src/script/script.cpp b/src/script/script.cpp index 6fcd883..1a26e62 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1905,6 +1905,7 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } object->SetActivity(false); } else { + if ((type == OBJECT_POWER || type == OBJECT_ATOMIC) && power == -1.0f) power = 1.0f; object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power); if ( object == nullptr ) { -- cgit v1.2.3-1-g7c22 From 130c4fd941424c0325af6a27fca9bb112880b56d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 16:46:28 +0100 Subject: Fixed log level in 8d30791595cf981b08310472faa2066a99aa9595 --- src/app/app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 8b5533e..a2162b1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -429,7 +429,7 @@ bool CApplication::Create() Language language; if (ParseLanguage(path, language)) { m_language = language; - GetLogger()->Error("Setting language '%s' from ini file\n", path.c_str()); + GetLogger()->Info("Setting language '%s' from ini file\n", path.c_str()); } else { GetLogger()->Error("Invalid language '%s' in ini file\n", path.c_str()); } -- cgit v1.2.3-1-g7c22 From ab57f623557d50208bf358f4a9177f336b815d89 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 16:55:47 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b422c5e..ceba212 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b422c5ee84bf19b7badc4d9fd3df39da1612f967 +Subproject commit ceba21259ab96df3331df96685ffdde48fbb9960 -- cgit v1.2.3-1-g7c22 From 59935b470674ae26342fd4145f9cba85a1cd9443 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 17:33:19 +0100 Subject: Changed comments in ObjectType to be object categories; removed unused SEAWEED --- src/object/object.h | 412 +++++++++++++++++++++++------------------------- src/script/cmdtoken.cpp | 20 +-- 2 files changed, 211 insertions(+), 221 deletions(-) diff --git a/src/object/object.h b/src/object/object.h index 64689eb..d5a073c 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -47,84 +47,84 @@ enum ObjectType { OBJECT_NULL = 0, //! < object destroyed OBJECT_FIX = 1, //! < stationary scenery - OBJECT_PORTICO = 2, //! < gantry - OBJECT_BASE = 3, //! < great main base - OBJECT_DERRICK = 4, //! < derrick set - OBJECT_FACTORY = 5, //! < factory set - OBJECT_STATION = 6, //! < recharging station - OBJECT_CONVERT = 7, //! < converter station - OBJECT_REPAIR = 8, //! < reparation - OBJECT_TOWER = 9, //! < defense tower - OBJECT_NEST = 10, //! < nest - OBJECT_RESEARCH = 11, //! < research center - OBJECT_RADAR = 12, //! < radar - OBJECT_ENERGY = 13, //! < energy factory - OBJECT_LABO = 14, //! < analytical laboratory for insect - OBJECT_NUCLEAR = 15, //! < nuclear power plant - OBJECT_START = 16, //! < starting - OBJECT_END = 17, //! < finish - OBJECT_INFO = 18, //! < information terminal - OBJECT_PARA = 19, //! < lightning conductor - OBJECT_TARGET1 = 20, //! < gate target - OBJECT_TARGET2 = 21, //! < center target - OBJECT_SAFE = 22, //! < safe - OBJECT_HUSTON = 23, //! < control centre - OBJECT_DESTROYER = 24, //! < destroyer - OBJECT_FRET = 30, //! < transportable - OBJECT_STONE = 31, //! < stone - OBJECT_URANIUM = 32, //! < uranium - OBJECT_METAL = 33, //! < metal - OBJECT_POWER = 34, //! < normal battery - OBJECT_ATOMIC = 35, //! < atomic battery - OBJECT_BULLET = 36, //! < bullet - OBJECT_BBOX = 37, //! < black-box - OBJECT_TNT = 38, //! < box of TNT - OBJECT_SCRAP1 = 40, //! < metal waste - OBJECT_SCRAP2 = 41, //! < metal waste - OBJECT_SCRAP3 = 42, //! < metal waste - OBJECT_SCRAP4 = 43, //! < plastic waste - OBJECT_SCRAP5 = 44, //! < plastic waste - OBJECT_MARKPOWER = 50, //! < mark underground energy source - OBJECT_MARKSTONE = 51, //! < mark underground ore - OBJECT_MARKURANIUM = 52, //! < mark underground uranium - OBJECT_MARKKEYa = 53, //! < mark underground key - OBJECT_MARKKEYb = 54, //! < mark underground key - OBJECT_MARKKEYc = 55, //! < mark underground key - OBJECT_MARKKEYd = 56, //! < mark underground key - OBJECT_BOMB = 60, //! < bomb - OBJECT_WINFIRE = 61, //! < fireworks - OBJECT_SHOW = 62, //! < shows a place - OBJECT_BAG = 63, //! < survival bag - OBJECT_PLANT0 = 70, //! < plant 0 - OBJECT_PLANT1 = 71, //! < plant 1 - OBJECT_PLANT2 = 72, //! < plant 2 - OBJECT_PLANT3 = 73, //! < plant 3 - OBJECT_PLANT4 = 74, //! < plant 4 - OBJECT_PLANT5 = 75, //! < plant 5 - OBJECT_PLANT6 = 76, //! < plant 6 - OBJECT_PLANT7 = 77, //! < plant 7 - OBJECT_PLANT8 = 78, //! < plant 8 - OBJECT_PLANT9 = 79, //! < plant 9 - OBJECT_PLANT10 = 80, //! < plant 10 - OBJECT_PLANT11 = 81, //! < plant 11 - OBJECT_PLANT12 = 82, //! < plant 12 - OBJECT_PLANT13 = 83, //! < plant 13 - OBJECT_PLANT14 = 84, //! < plant 14 - OBJECT_PLANT15 = 85, //! < plant 15 - OBJECT_PLANT16 = 86, //! < plant 16 - OBJECT_PLANT17 = 87, //! < plant 17 - OBJECT_PLANT18 = 88, //! < plant 18 - OBJECT_PLANT19 = 89, //! < plant 19 - OBJECT_TREE0 = 90, //! < tree 0 - OBJECT_TREE1 = 91, //! < tree 1 - OBJECT_TREE2 = 92, //! < tree 2 - OBJECT_TREE3 = 93, //! < tree 3 - OBJECT_TREE4 = 94, //! < tree 4 - OBJECT_TREE5 = 95, //! < tree 5 - OBJECT_TREE6 = 96, //! < tree 6 - OBJECT_TREE7 = 97, //! < tree 7 - OBJECT_TREE8 = 98, //! < tree 8 - OBJECT_TREE9 = 99, //! < tree 9 + OBJECT_PORTICO = 2, //! < Portico + OBJECT_BASE = 3, //! < SpaceShip + OBJECT_DERRICK = 4, //! < Derrick + OBJECT_FACTORY = 5, //! < BotFactory + OBJECT_STATION = 6, //! < PowerStation + OBJECT_CONVERT = 7, //! < Converter + OBJECT_REPAIR = 8, //! < RepairStation + OBJECT_TOWER = 9, //! < DefenseTower + OBJECT_NEST = 10, //! < AlienNest + OBJECT_RESEARCH = 11, //! < ResearchCenter + OBJECT_RADAR = 12, //! < RadarStation + OBJECT_ENERGY = 13, //! < PowerPlant + OBJECT_LABO = 14, //! < AutoLab + OBJECT_NUCLEAR = 15, //! < NuclearPlant + OBJECT_START = 16, //! < StartArea + OBJECT_END = 17, //! < EndArea + OBJECT_INFO = 18, //! < ExchangePost + OBJECT_PARA = 19, //! < PowerCaptor + OBJECT_TARGET1 = 20, //! < Target1 (gate) + OBJECT_TARGET2 = 21, //! < Target2 (center) + OBJECT_SAFE = 22, //! < Vault + OBJECT_HUSTON = 23, //! < Houston + OBJECT_DESTROYER = 24, //! < Destroyer + OBJECT_FRET = 30, //! < transportable (unused) + OBJECT_STONE = 31, //! < TitaniumOre + OBJECT_URANIUM = 32, //! < UraniumOre + OBJECT_METAL = 33, //! < Titanium + OBJECT_POWER = 34, //! < PowerCell + OBJECT_ATOMIC = 35, //! < NuclearCell + OBJECT_BULLET = 36, //! < OrgaMatter + OBJECT_BBOX = 37, //! < BlackBox + OBJECT_TNT = 38, //! < TNT + OBJECT_SCRAP1 = 40, //! < Scrap1 (metal) + OBJECT_SCRAP2 = 41, //! < Scrap2 (metal) + OBJECT_SCRAP3 = 42, //! < Scrap3 (metal) + OBJECT_SCRAP4 = 43, //! < Scrap4 (plastic) + OBJECT_SCRAP5 = 44, //! < Scrap5 (plastic) + OBJECT_MARKPOWER = 50, //! < PowerSpot + OBJECT_MARKSTONE = 51, //! < TitaniumSpot + OBJECT_MARKURANIUM = 52, //! < UraniumSpot + OBJECT_MARKKEYa = 53, //! < KeyASpot + OBJECT_MARKKEYb = 54, //! < KeyBSpot + OBJECT_MARKKEYc = 55, //! < KeyCSpot + OBJECT_MARKKEYd = 56, //! < KeyDSpot + OBJECT_BOMB = 60, //! < Mine + OBJECT_WINFIRE = 61, //! < Firework + OBJECT_SHOW = 62, //! < arrow above object (Visit) + OBJECT_BAG = 63, //! < Bag + OBJECT_PLANT0 = 70, //! < Greenery0 + OBJECT_PLANT1 = 71, //! < Greenery1 + OBJECT_PLANT2 = 72, //! < Greenery2 + OBJECT_PLANT3 = 73, //! < Greenery3 + OBJECT_PLANT4 = 74, //! < Greenery4 + OBJECT_PLANT5 = 75, //! < Greenery5 + OBJECT_PLANT6 = 76, //! < Greenery6 + OBJECT_PLANT7 = 77, //! < Greenery7 + OBJECT_PLANT8 = 78, //! < Greenery8 + OBJECT_PLANT9 = 79, //! < Greenery9 + OBJECT_PLANT10 = 80, //! < Greenery10 + OBJECT_PLANT11 = 81, //! < Greenery11 + OBJECT_PLANT12 = 82, //! < Greenery12 + OBJECT_PLANT13 = 83, //! < Greenery13 + OBJECT_PLANT14 = 84, //! < Greenery14 + OBJECT_PLANT15 = 85, //! < Greenery15 + OBJECT_PLANT16 = 86, //! < Greenery16 + OBJECT_PLANT17 = 87, //! < Greenery17 + OBJECT_PLANT18 = 88, //! < Greenery18 + OBJECT_PLANT19 = 89, //! < Greenery19 + OBJECT_TREE0 = 90, //! < Tree0 + OBJECT_TREE1 = 91, //! < Tree1 + OBJECT_TREE2 = 92, //! < Tree2 + OBJECT_TREE3 = 93, //! < Tree3 + OBJECT_TREE4 = 94, //! < Tree4 + OBJECT_TREE5 = 95, //! < Tree5 + OBJECT_TREE6 = 96, //! < Tree6 + OBJECT_TREE7 = 97, //! < Tree7 + OBJECT_TREE8 = 98, //! < Tree8 + OBJECT_TREE9 = 99, //! < Tree9 OBJECT_MOBILEwt = 100, //! < PracticeBot OBJECT_MOBILEtt = 101, //! < track-trainer (unused) OBJECT_MOBILEft = 102, //! < fly-trainer (unused) @@ -153,139 +153,129 @@ enum ObjectType OBJECT_MOBILEtg = 211, //! < TargetBot OBJECT_MOBILEdr = 212, //! < Scribbler OBJECT_CONTROLLER = 213, //! < MissionController - OBJECT_WAYPOINT = 250, //! < waypoint - OBJECT_FLAGb = 260, //! < blue flag - OBJECT_FLAGr = 261, //! < red flag - OBJECT_FLAGg = 262, //! < green flag - OBJECT_FLAGy = 263, //! < yellow flag - OBJECT_FLAGv = 264, //! < violet flag - OBJECT_KEYa = 270, //! < key a - OBJECT_KEYb = 271, //! < key b - OBJECT_KEYc = 272, //! < key c - OBJECT_KEYd = 273, //! < key d - OBJECT_HUMAN = 300, //! < human - OBJECT_TOTO = 301, //! < toto - OBJECT_TECH = 302, //! < technician - OBJECT_BARRIER0 = 400, //! < barrier - OBJECT_BARRIER1 = 401, //! < barrier - OBJECT_BARRIER2 = 402, //! < barrier - OBJECT_BARRIER3 = 403, //! < barrier - OBJECT_BARRIER4 = 404, //! < barrier - OBJECT_MOTHER = 500, //! < insect queen - OBJECT_EGG = 501, //! < egg - OBJECT_ANT = 502, //! < ant - OBJECT_SPIDER = 503, //! < spider - OBJECT_BEE = 504, //! < bee - OBJECT_WORM = 505, //! < worm - OBJECT_RUINmobilew1 = 600, //! < ruin 1 - OBJECT_RUINmobilew2 = 601, //! < ruin 1 - OBJECT_RUINmobilet1 = 602, //! < ruin 2 - OBJECT_RUINmobilet2 = 603, //! < ruin 2 - OBJECT_RUINmobiler1 = 604, //! < ruin 3 - OBJECT_RUINmobiler2 = 605, //! < ruin 3 - OBJECT_RUINfactory = 606, //! < ruin 4 - OBJECT_RUINdoor = 607, //! < ruin 5 - OBJECT_RUINsupport = 608, //! < ruin 6 - OBJECT_RUINradar = 609, //! < ruin 7 - OBJECT_RUINconvert = 610, //! < ruin 8 - OBJECT_RUINbase = 611, //! < ruin 9 - OBJECT_RUINhead = 612, //! < ruin 10 - OBJECT_TEEN0 = 620, //! < toy - OBJECT_TEEN1 = 621, //! < toy - OBJECT_TEEN2 = 622, //! < toy - OBJECT_TEEN3 = 623, //! < toy - OBJECT_TEEN4 = 624, //! < toy - OBJECT_TEEN5 = 625, //! < toy - OBJECT_TEEN6 = 626, //! < toy - OBJECT_TEEN7 = 627, //! < toy - OBJECT_TEEN8 = 628, //! < toy - OBJECT_TEEN9 = 629, //! < toy - OBJECT_TEEN10 = 630, //! < toy - OBJECT_TEEN11 = 631, //! < toy - OBJECT_TEEN12 = 632, //! < toy - OBJECT_TEEN13 = 633, //! < toy - OBJECT_TEEN14 = 634, //! < toy - OBJECT_TEEN15 = 635, //! < toy - OBJECT_TEEN16 = 636, //! < toy - OBJECT_TEEN17 = 637, //! < toy - OBJECT_TEEN18 = 638, //! < toy - OBJECT_TEEN19 = 639, //! < toy - OBJECT_TEEN20 = 640, //! < toy - OBJECT_TEEN21 = 641, //! < toy - OBJECT_TEEN22 = 642, //! < toy - OBJECT_TEEN23 = 643, //! < toy - OBJECT_TEEN24 = 644, //! < toy - OBJECT_TEEN25 = 645, //! < toy - OBJECT_TEEN26 = 646, //! < toy - OBJECT_TEEN27 = 647, //! < toy - OBJECT_TEEN28 = 648, //! < toy - OBJECT_TEEN29 = 649, //! < toy - OBJECT_TEEN30 = 650, //! < toy - OBJECT_TEEN31 = 651, //! < toy - OBJECT_TEEN32 = 652, //! < toy - OBJECT_TEEN33 = 653, //! < toy - OBJECT_TEEN34 = 654, //! < toy - OBJECT_TEEN35 = 655, //! < toy - OBJECT_TEEN36 = 656, //! < toy - OBJECT_TEEN37 = 657, //! < toy - OBJECT_TEEN38 = 658, //! < toy - OBJECT_TEEN39 = 659, //! < toy - OBJECT_TEEN40 = 660, //! < toy - OBJECT_TEEN41 = 661, //! < toy - OBJECT_TEEN42 = 662, //! < toy - OBJECT_TEEN43 = 663, //! < toy - OBJECT_TEEN44 = 664, //! < toy - OBJECT_TEEN45 = 665, //! < toy - OBJECT_TEEN46 = 666, //! < toy - OBJECT_TEEN47 = 667, //! < toy - OBJECT_TEEN48 = 668, //! < toy - OBJECT_TEEN49 = 669, //! < toy - OBJECT_QUARTZ0 = 700, //! < crystal 0 - OBJECT_QUARTZ1 = 701, //! < crystal 1 - OBJECT_QUARTZ2 = 702, //! < crystal 2 - OBJECT_QUARTZ3 = 703, //! < crystal 3 - OBJECT_QUARTZ4 = 704, //! < crystal 4 - OBJECT_QUARTZ5 = 705, //! < crystal 5 - OBJECT_QUARTZ6 = 706, //! < crystal 6 - OBJECT_QUARTZ7 = 707, //! < crystal 7 - OBJECT_QUARTZ8 = 708, //! < crystal 8 - OBJECT_QUARTZ9 = 709, //! < crystal 9 - OBJECT_ROOT0 = 710, //! < root 0 - OBJECT_ROOT1 = 711, //! < root 1 - OBJECT_ROOT2 = 712, //! < root 2 - OBJECT_ROOT3 = 713, //! < root 3 - OBJECT_ROOT4 = 714, //! < root 4 - OBJECT_ROOT5 = 715, //! < root 5 - OBJECT_ROOT6 = 716, //! < root 6 - OBJECT_ROOT7 = 717, //! < root 7 - OBJECT_ROOT8 = 718, //! < root 8 - OBJECT_ROOT9 = 719, //! < root 9 - OBJECT_SEAWEED0 = 720, //! < seaweed 0 - OBJECT_SEAWEED1 = 721, //! < seaweed 1 - OBJECT_SEAWEED2 = 722, //! < seaweed 2 - OBJECT_SEAWEED3 = 723, //! < seaweed 3 - OBJECT_SEAWEED4 = 724, //! < seaweed 4 - OBJECT_SEAWEED5 = 725, //! < seaweed 5 - OBJECT_SEAWEED6 = 726, //! < seaweed 6 - OBJECT_SEAWEED7 = 727, //! < seaweed 7 - OBJECT_SEAWEED8 = 728, //! < seaweed 8 - OBJECT_SEAWEED9 = 729, //! < seaweed 9 - OBJECT_MUSHROOM0 = 730, //! < mushroom 0 - OBJECT_MUSHROOM1 = 731, //! < mushroom 1 - OBJECT_MUSHROOM2 = 732, //! < mushroom 2 - OBJECT_MUSHROOM3 = 733, //! < mushroom 3 - OBJECT_MUSHROOM4 = 734, //! < mushroom 4 - OBJECT_MUSHROOM5 = 735, //! < mushroom 5 - OBJECT_MUSHROOM6 = 736, //! < mushroom 6 - OBJECT_MUSHROOM7 = 737, //! < mushroom 7 - OBJECT_MUSHROOM8 = 738, //! < mushroom 8 - OBJECT_MUSHROOM9 = 739, //! < mushroom 9 - OBJECT_APOLLO1 = 900, //! < apollo lem - OBJECT_APOLLO2 = 901, //! < apollo jeep - OBJECT_APOLLO3 = 902, //! < apollo flag - OBJECT_APOLLO4 = 903, //! < apollo module - OBJECT_APOLLO5 = 904, //! < apollo antenna - OBJECT_HOME1 = 910, //! < home 1 + OBJECT_WAYPOINT = 250, //! < WayPoint + OBJECT_FLAGb = 260, //! < BlueFlag + OBJECT_FLAGr = 261, //! < RedFlag + OBJECT_FLAGg = 262, //! < GreenFlag + OBJECT_FLAGy = 263, //! < YellowFlag + OBJECT_FLAGv = 264, //! < VioletFlag + OBJECT_KEYa = 270, //! < KeyA + OBJECT_KEYb = 271, //! < KeyB + OBJECT_KEYc = 272, //! < KeyC + OBJECT_KEYd = 273, //! < KeyD + OBJECT_HUMAN = 300, //! < Me + OBJECT_TOTO = 301, //! < Robby (toto) + OBJECT_TECH = 302, //! < Tech + OBJECT_BARRIER0 = 400, //! < Barrier0 + OBJECT_BARRIER1 = 401, //! < Barrier1 + OBJECT_BARRIER2 = 402, //! < Barrier2 + OBJECT_BARRIER3 = 403, //! < Barrier3 + OBJECT_BARRIER4 = 404, //! < Barrier4 + OBJECT_MOTHER = 500, //! < AlienQueen + OBJECT_EGG = 501, //! < AlienEgg + OBJECT_ANT = 502, //! < AlienAnt + OBJECT_SPIDER = 503, //! < AlienSpider + OBJECT_BEE = 504, //! < AlienWasp + OBJECT_WORM = 505, //! < AlienWorm + OBJECT_RUINmobilew1 = 600, //! < WreckBotw1 + OBJECT_RUINmobilew2 = 601, //! < WreckBotw2 + OBJECT_RUINmobilet1 = 602, //! < WreckBott1 + OBJECT_RUINmobilet2 = 603, //! < WreckBott2 + OBJECT_RUINmobiler1 = 604, //! < WreckBotr1 + OBJECT_RUINmobiler2 = 605, //! < WreckBotr2 + OBJECT_RUINfactory = 606, //! < RuinBotFactory + OBJECT_RUINdoor = 607, //! < RuinDoor + OBJECT_RUINsupport = 608, //! < RuinSupport + OBJECT_RUINradar = 609, //! < RuinRadar + OBJECT_RUINconvert = 610, //! < RuinConvert + OBJECT_RUINbase = 611, //! < RuinBaseCamp + OBJECT_RUINhead = 612, //! < RuinHeadCamp + OBJECT_TEEN0 = 620, //! < Teen0 + OBJECT_TEEN1 = 621, //! < Teen1 + OBJECT_TEEN2 = 622, //! < Teen2 + OBJECT_TEEN3 = 623, //! < Teen3 + OBJECT_TEEN4 = 624, //! < Teen4 + OBJECT_TEEN5 = 625, //! < Teen5 + OBJECT_TEEN6 = 626, //! < Teen6 + OBJECT_TEEN7 = 627, //! < Teen7 + OBJECT_TEEN8 = 628, //! < Teen8 + OBJECT_TEEN9 = 629, //! < Teen9 + OBJECT_TEEN10 = 630, //! < Teen10 + OBJECT_TEEN11 = 631, //! < Teen11 + OBJECT_TEEN12 = 632, //! < Teen12 + OBJECT_TEEN13 = 633, //! < Teen13 + OBJECT_TEEN14 = 634, //! < Teen14 + OBJECT_TEEN15 = 635, //! < Teen15 + OBJECT_TEEN16 = 636, //! < Teen16 + OBJECT_TEEN17 = 637, //! < Teen17 + OBJECT_TEEN18 = 638, //! < Teen18 + OBJECT_TEEN19 = 639, //! < Teen19 + OBJECT_TEEN20 = 640, //! < Teen20 + OBJECT_TEEN21 = 641, //! < Teen21 + OBJECT_TEEN22 = 642, //! < Teen22 + OBJECT_TEEN23 = 643, //! < Teen23 + OBJECT_TEEN24 = 644, //! < Teen24 + OBJECT_TEEN25 = 645, //! < Teen25 + OBJECT_TEEN26 = 646, //! < Teen26 + OBJECT_TEEN27 = 647, //! < Teen27 + OBJECT_TEEN28 = 648, //! < Teen28 + OBJECT_TEEN29 = 649, //! < Teen29 + OBJECT_TEEN30 = 650, //! < Teen30 + OBJECT_TEEN31 = 651, //! < Teen31 + OBJECT_TEEN32 = 652, //! < Teen32 + OBJECT_TEEN33 = 653, //! < Teen33 + OBJECT_TEEN34 = 654, //! < Stone (Teen34) + OBJECT_TEEN35 = 655, //! < Teen35 + OBJECT_TEEN36 = 656, //! < Teen36 + OBJECT_TEEN37 = 657, //! < Teen37 + OBJECT_TEEN38 = 658, //! < Teen38 + OBJECT_TEEN39 = 659, //! < Teen39 + OBJECT_TEEN40 = 660, //! < Teen40 + OBJECT_TEEN41 = 661, //! < Teen41 + OBJECT_TEEN42 = 662, //! < Teen42 + OBJECT_TEEN43 = 663, //! < Teen43 + OBJECT_TEEN44 = 664, //! < Teen44 + OBJECT_TEEN45 = 665, //! < Teen45 + OBJECT_TEEN46 = 666, //! < Teen46 + OBJECT_TEEN47 = 667, //! < Teen47 + OBJECT_TEEN48 = 668, //! < Teen48 + OBJECT_TEEN49 = 669, //! < Teen49 + OBJECT_QUARTZ0 = 700, //! < Quartz0 + OBJECT_QUARTZ1 = 701, //! < Quartz1 + OBJECT_QUARTZ2 = 702, //! < Quartz2 + OBJECT_QUARTZ3 = 703, //! < Quartz3 + OBJECT_QUARTZ4 = 704, //! < Quartz4 + OBJECT_QUARTZ5 = 705, //! < Quartz5 + OBJECT_QUARTZ6 = 706, //! < Quartz6 + OBJECT_QUARTZ7 = 707, //! < Quartz7 + OBJECT_QUARTZ8 = 708, //! < Quartz8 + OBJECT_QUARTZ9 = 709, //! < Quartz9 + OBJECT_ROOT0 = 710, //! < MegaStalk0 + OBJECT_ROOT1 = 711, //! < MegaStalk1 + OBJECT_ROOT2 = 712, //! < MegaStalk2 + OBJECT_ROOT3 = 713, //! < MegaStalk3 + OBJECT_ROOT4 = 714, //! < MegaStalk4 + OBJECT_ROOT5 = 715, //! < MegaStalk5 + OBJECT_ROOT6 = 716, //! < MegaStalk6 + OBJECT_ROOT7 = 717, //! < MegaStalk7 + OBJECT_ROOT8 = 718, //! < MegaStalk8 + OBJECT_ROOT9 = 719, //! < MegaStalk9 + OBJECT_MUSHROOM0 = 730, //! < Mushroom0 + OBJECT_MUSHROOM1 = 731, //! < Mushroom1 + OBJECT_MUSHROOM2 = 732, //! < Mushroom2 + OBJECT_MUSHROOM3 = 733, //! < Mushroom3 + OBJECT_MUSHROOM4 = 734, //! < Mushroom4 + OBJECT_MUSHROOM5 = 735, //! < Mushroom5 + OBJECT_MUSHROOM6 = 736, //! < Mushroom6 + OBJECT_MUSHROOM7 = 737, //! < Mushroom7 + OBJECT_MUSHROOM8 = 738, //! < Mushroom8 + OBJECT_MUSHROOM9 = 739, //! < Mushroom9 + OBJECT_APOLLO1 = 900, //! < ApolloLEM + OBJECT_APOLLO2 = 901, //! < ApolloJeep + OBJECT_APOLLO3 = 902, //! < ApolloFlag + OBJECT_APOLLO4 = 903, //! < ApolloModule + OBJECT_APOLLO5 = 904, //! < ApolloAntenna + OBJECT_HOME1 = 910, //! < Home OBJECT_MAX = 1000 //! < number of values }; diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index 4508459..bc3ed9f 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -238,16 +238,6 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Mine" ) ) return OBJECT_BOMB; if ( Cmd(p, "Firework" ) ) return OBJECT_WINFIRE; if ( Cmd(p, "Bag" ) ) return OBJECT_BAG; - if ( Cmd(p, "Greenery10" ) ) return OBJECT_PLANT10; - if ( Cmd(p, "Greenery11" ) ) return OBJECT_PLANT11; - if ( Cmd(p, "Greenery12" ) ) return OBJECT_PLANT12; - if ( Cmd(p, "Greenery13" ) ) return OBJECT_PLANT13; - if ( Cmd(p, "Greenery14" ) ) return OBJECT_PLANT14; - if ( Cmd(p, "Greenery15" ) ) return OBJECT_PLANT15; - if ( Cmd(p, "Greenery16" ) ) return OBJECT_PLANT16; - if ( Cmd(p, "Greenery17" ) ) return OBJECT_PLANT17; - if ( Cmd(p, "Greenery18" ) ) return OBJECT_PLANT18; - if ( Cmd(p, "Greenery19" ) ) return OBJECT_PLANT19; if ( Cmd(p, "Greenery0" ) ) return OBJECT_PLANT0; if ( Cmd(p, "Greenery1" ) ) return OBJECT_PLANT1; if ( Cmd(p, "Greenery2" ) ) return OBJECT_PLANT2; @@ -258,6 +248,16 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Greenery7" ) ) return OBJECT_PLANT7; if ( Cmd(p, "Greenery8" ) ) return OBJECT_PLANT8; if ( Cmd(p, "Greenery9" ) ) return OBJECT_PLANT9; + if ( Cmd(p, "Greenery10" ) ) return OBJECT_PLANT10; + if ( Cmd(p, "Greenery11" ) ) return OBJECT_PLANT11; + if ( Cmd(p, "Greenery12" ) ) return OBJECT_PLANT12; + if ( Cmd(p, "Greenery13" ) ) return OBJECT_PLANT13; + if ( Cmd(p, "Greenery14" ) ) return OBJECT_PLANT14; + if ( Cmd(p, "Greenery15" ) ) return OBJECT_PLANT15; + if ( Cmd(p, "Greenery16" ) ) return OBJECT_PLANT16; + if ( Cmd(p, "Greenery17" ) ) return OBJECT_PLANT17; + if ( Cmd(p, "Greenery18" ) ) return OBJECT_PLANT18; + if ( Cmd(p, "Greenery19" ) ) return OBJECT_PLANT19; if ( Cmd(p, "Tree0" ) ) return OBJECT_TREE0; if ( Cmd(p, "Tree1" ) ) return OBJECT_TREE1; if ( Cmd(p, "Tree2" ) ) return OBJECT_TREE2; -- cgit v1.2.3-1-g7c22 From affa7e32f11fdccc400471db63d0e0023d9c43f6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 19:35:49 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index ceba212..7433e1b 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit ceba21259ab96df3331df96685ffdde48fbb9960 +Subproject commit 7433e1b68802baf1e422b6bb73cd95d71b5785a2 -- cgit v1.2.3-1-g7c22 From 082989a413b229176210890dbda635ef98bb5b7d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 19:49:29 +0100 Subject: Changed main menu title to "COLOBOT: Gold Edition" --- po/colobot.pot | 3 +++ po/de.po | 3 +++ po/fr.po | 3 +++ po/pl.po | 3 +++ po/ru.po | 6 +++++- src/common/restext.cpp | 2 +- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index c302f7e..f062658 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -53,6 +53,9 @@ msgstr "" msgid "COLOBOT" msgstr "" +msgid "COLOBOT: Gold Edition" +msgstr "" + msgid "Programming exercises" msgstr "" diff --git a/po/de.po b/po/de.po index f6b81f5..93a1d7b 100644 --- a/po/de.po +++ b/po/de.po @@ -308,6 +308,9 @@ msgstr "Knopf %1" msgid "COLOBOT" msgstr "COLOBOT" +msgid "COLOBOT: Gold Edition" +msgstr "COLOBOT: Gold Edition" + msgid "Calling an unknown function" msgstr "Die aufgerufene Funktion existiert nicht" diff --git a/po/fr.po b/po/fr.po index b4f94d0..e6be922 100644 --- a/po/fr.po +++ b/po/fr.po @@ -312,6 +312,9 @@ msgstr "Bouton %1" msgid "COLOBOT" msgstr "COLOBOT" +msgid "COLOBOT: Gold Edition" +msgstr "COLOBOT: Gold Edition" + msgid "Calling an unknown function" msgstr "Appel d'une fonction inexistante" diff --git a/po/pl.po b/po/pl.po index 05da29f..0b13dbb 100644 --- a/po/pl.po +++ b/po/pl.po @@ -310,6 +310,9 @@ msgstr "Przycisk %1" msgid "COLOBOT" msgstr "COLOBOT" +msgid "COLOBOT: Gold Edition" +msgstr "COLOBOT: Gold Edition" + msgid "Calling an unknown function" msgstr "Odwołanie do nieznanej funkcji" diff --git a/po/ru.po b/po/ru.po index 7531fca..22f84a8 100644 --- a/po/ru.po +++ b/po/ru.po @@ -315,6 +315,9 @@ msgstr "Кнопка %1" msgid "COLOBOT" msgstr "КОЛОБОТ" +msgid "COLOBOT: Gold Edition" +msgstr "" + msgid "Calling an unknown function" msgstr "Вызов неизвестной функции" @@ -1110,7 +1113,8 @@ msgid "Programming help (\\key prog;)" msgstr "Помощь в программировании (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" -msgstr "Помощь в программировании\\Дает более детальную помощь в программировании" +msgstr "" +"Помощь в программировании\\Дает более детальную помощь в программировании" msgid "Programs dispatched by Houston" msgstr "Программы переданные с Хьюстона" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 6533c7c..b63160d 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -56,7 +56,7 @@ void InitializeRestext() stringsText[RT_KEY_OR] = " or "; stringsText[RT_TITLE_BASE] = "COLOBOT"; - stringsText[RT_TITLE_INIT] = "COLOBOT"; + stringsText[RT_TITLE_INIT] = "COLOBOT: Gold Edition"; stringsText[RT_TITLE_TRAINER] = "Programming exercises"; stringsText[RT_TITLE_DEFI] = "Challenges"; stringsText[RT_TITLE_MISSION] = "Missions"; -- cgit v1.2.3-1-g7c22 From 77331fccc62319329553463339d78d4bc548d92e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 1 Jan 2014 19:53:31 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 7433e1b..8d10f16 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 7433e1b68802baf1e422b6bb73cd95d71b5785a2 +Subproject commit 8d10f1662757973aaab2170c88925aac93f2754f -- cgit v1.2.3-1-g7c22 From aec1b978c8856422db1b334baec1a208336d4e79 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 2 Jan 2014 16:42:10 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 8d10f16..530c8b1 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 8d10f1662757973aaab2170c88925aac93f2754f +Subproject commit 530c8b1048dc484f015652bb97492b83b2d8d9c7 -- cgit v1.2.3-1-g7c22 From d8555866747d8624debf52620605d90890e98c15 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 11 Jan 2014 17:57:31 +0100 Subject: Fixed a bug from 59935b470674ae26342fd4145f9cba85a1cd9443 Cmd() now checks if length of token we're looking for is equal to token we've found --- src/script/cmdtoken.cpp | 89 ++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index bc3ed9f..076a38f 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -42,8 +42,15 @@ bool Cmd(char *line, const char *token) char* p; line = SkipSpace(line); + p = strstr(line, token); - return ( p == line ); // command at the beginning? + if(p != line) return false; // command at the beginning? + + unsigned int len = 0; + for(char* x = p; *x != 0 && *x != ' ' && *x != '\t' && *x != '\n'; x++, len++); + if(len != strlen(token)) return false; // ends with space? + + return true; } // Seeking an operator. @@ -324,46 +331,6 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Barrier2" ) ) return OBJECT_BARRIER2; if ( Cmd(p, "Barrier3" ) ) return OBJECT_BARRIER3; if ( Cmd(p, "Barrier4" ) ) return OBJECT_BARRIER4; - if ( Cmd(p, "Teen40" ) ) return OBJECT_TEEN40; - if ( Cmd(p, "Teen41" ) ) return OBJECT_TEEN41; - if ( Cmd(p, "Teen42" ) ) return OBJECT_TEEN42; - if ( Cmd(p, "Teen43" ) ) return OBJECT_TEEN43; - if ( Cmd(p, "Teen44" ) ) return OBJECT_TEEN44; - if ( Cmd(p, "Teen45" ) ) return OBJECT_TEEN45; - if ( Cmd(p, "Teen46" ) ) return OBJECT_TEEN46; - if ( Cmd(p, "Teen47" ) ) return OBJECT_TEEN47; - if ( Cmd(p, "Teen48" ) ) return OBJECT_TEEN48; - if ( Cmd(p, "Teen49" ) ) return OBJECT_TEEN49; - if ( Cmd(p, "Teen30" ) ) return OBJECT_TEEN30; - if ( Cmd(p, "Teen31" ) ) return OBJECT_TEEN31; - if ( Cmd(p, "Teen32" ) ) return OBJECT_TEEN32; - if ( Cmd(p, "Teen33" ) ) return OBJECT_TEEN33; - if ( Cmd(p, "Stone" ) ) return OBJECT_TEEN34; - if ( Cmd(p, "Teen35" ) ) return OBJECT_TEEN35; - if ( Cmd(p, "Teen36" ) ) return OBJECT_TEEN36; - if ( Cmd(p, "Teen37" ) ) return OBJECT_TEEN37; - if ( Cmd(p, "Teen38" ) ) return OBJECT_TEEN38; - if ( Cmd(p, "Teen39" ) ) return OBJECT_TEEN39; - if ( Cmd(p, "Teen20" ) ) return OBJECT_TEEN20; - if ( Cmd(p, "Teen21" ) ) return OBJECT_TEEN21; - if ( Cmd(p, "Teen22" ) ) return OBJECT_TEEN22; - if ( Cmd(p, "Teen23" ) ) return OBJECT_TEEN23; - if ( Cmd(p, "Teen24" ) ) return OBJECT_TEEN24; - if ( Cmd(p, "Teen25" ) ) return OBJECT_TEEN25; - if ( Cmd(p, "Teen26" ) ) return OBJECT_TEEN26; - if ( Cmd(p, "Teen27" ) ) return OBJECT_TEEN27; - if ( Cmd(p, "Teen28" ) ) return OBJECT_TEEN28; - if ( Cmd(p, "Teen29" ) ) return OBJECT_TEEN29; - if ( Cmd(p, "Teen10" ) ) return OBJECT_TEEN10; - if ( Cmd(p, "Teen11" ) ) return OBJECT_TEEN11; - if ( Cmd(p, "Teen12" ) ) return OBJECT_TEEN12; - if ( Cmd(p, "Teen13" ) ) return OBJECT_TEEN13; - if ( Cmd(p, "Teen14" ) ) return OBJECT_TEEN14; - if ( Cmd(p, "Teen15" ) ) return OBJECT_TEEN15; - if ( Cmd(p, "Teen16" ) ) return OBJECT_TEEN16; - if ( Cmd(p, "Teen17" ) ) return OBJECT_TEEN17; - if ( Cmd(p, "Teen18" ) ) return OBJECT_TEEN18; - if ( Cmd(p, "Teen19" ) ) return OBJECT_TEEN19; if ( Cmd(p, "Teen0" ) ) return OBJECT_TEEN0; if ( Cmd(p, "Teen1" ) ) return OBJECT_TEEN1; if ( Cmd(p, "Teen2" ) ) return OBJECT_TEEN2; @@ -374,6 +341,46 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Teen7" ) ) return OBJECT_TEEN7; if ( Cmd(p, "Teen8" ) ) return OBJECT_TEEN8; if ( Cmd(p, "Teen9" ) ) return OBJECT_TEEN9; + if ( Cmd(p, "Teen10" ) ) return OBJECT_TEEN10; + if ( Cmd(p, "Teen11" ) ) return OBJECT_TEEN11; + if ( Cmd(p, "Teen12" ) ) return OBJECT_TEEN12; + if ( Cmd(p, "Teen13" ) ) return OBJECT_TEEN13; + if ( Cmd(p, "Teen14" ) ) return OBJECT_TEEN14; + if ( Cmd(p, "Teen15" ) ) return OBJECT_TEEN15; + if ( Cmd(p, "Teen16" ) ) return OBJECT_TEEN16; + if ( Cmd(p, "Teen17" ) ) return OBJECT_TEEN17; + if ( Cmd(p, "Teen18" ) ) return OBJECT_TEEN18; + if ( Cmd(p, "Teen19" ) ) return OBJECT_TEEN19; + if ( Cmd(p, "Teen20" ) ) return OBJECT_TEEN20; + if ( Cmd(p, "Teen21" ) ) return OBJECT_TEEN21; + if ( Cmd(p, "Teen22" ) ) return OBJECT_TEEN22; + if ( Cmd(p, "Teen23" ) ) return OBJECT_TEEN23; + if ( Cmd(p, "Teen24" ) ) return OBJECT_TEEN24; + if ( Cmd(p, "Teen25" ) ) return OBJECT_TEEN25; + if ( Cmd(p, "Teen26" ) ) return OBJECT_TEEN26; + if ( Cmd(p, "Teen27" ) ) return OBJECT_TEEN27; + if ( Cmd(p, "Teen28" ) ) return OBJECT_TEEN28; + if ( Cmd(p, "Teen29" ) ) return OBJECT_TEEN29; + if ( Cmd(p, "Teen30" ) ) return OBJECT_TEEN30; + if ( Cmd(p, "Teen31" ) ) return OBJECT_TEEN31; + if ( Cmd(p, "Teen32" ) ) return OBJECT_TEEN32; + if ( Cmd(p, "Teen33" ) ) return OBJECT_TEEN33; + if ( Cmd(p, "Stone" ) ) return OBJECT_TEEN34; + if ( Cmd(p, "Teen35" ) ) return OBJECT_TEEN35; + if ( Cmd(p, "Teen36" ) ) return OBJECT_TEEN36; + if ( Cmd(p, "Teen37" ) ) return OBJECT_TEEN37; + if ( Cmd(p, "Teen38" ) ) return OBJECT_TEEN38; + if ( Cmd(p, "Teen39" ) ) return OBJECT_TEEN39; + if ( Cmd(p, "Teen40" ) ) return OBJECT_TEEN40; + if ( Cmd(p, "Teen41" ) ) return OBJECT_TEEN41; + if ( Cmd(p, "Teen42" ) ) return OBJECT_TEEN42; + if ( Cmd(p, "Teen43" ) ) return OBJECT_TEEN43; + if ( Cmd(p, "Teen44" ) ) return OBJECT_TEEN44; + if ( Cmd(p, "Teen45" ) ) return OBJECT_TEEN45; + if ( Cmd(p, "Teen46" ) ) return OBJECT_TEEN46; + if ( Cmd(p, "Teen47" ) ) return OBJECT_TEEN47; + if ( Cmd(p, "Teen48" ) ) return OBJECT_TEEN48; + if ( Cmd(p, "Teen49" ) ) return OBJECT_TEEN49; if ( Cmd(p, "Quartz0" ) ) return OBJECT_QUARTZ0; if ( Cmd(p, "Quartz1" ) ) return OBJECT_QUARTZ1; if ( Cmd(p, "Quartz2" ) ) return OBJECT_QUARTZ2; -- cgit v1.2.3-1-g7c22 From 652dc6081df8dc73bc9f57c031420e498be71451 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 11 Jan 2014 23:42:45 +0100 Subject: Removed some unused objects --- src/object/object.h | 28 ----------------- src/object/objman.cpp | 42 +++++--------------------- src/object/robotmain.cpp | 6 ++-- src/object/task/taskgoto.cpp | 4 +-- src/physics/physics.cpp | 8 ++--- src/script/cmdtoken.cpp | 72 -------------------------------------------- 6 files changed, 16 insertions(+), 144 deletions(-) diff --git a/src/object/object.h b/src/object/object.h index d5a073c..5d9e681 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -121,10 +121,6 @@ enum ObjectType OBJECT_TREE3 = 93, //! < Tree3 OBJECT_TREE4 = 94, //! < Tree4 OBJECT_TREE5 = 95, //! < Tree5 - OBJECT_TREE6 = 96, //! < Tree6 - OBJECT_TREE7 = 97, //! < Tree7 - OBJECT_TREE8 = 98, //! < Tree8 - OBJECT_TREE9 = 99, //! < Tree9 OBJECT_MOBILEwt = 100, //! < PracticeBot OBJECT_MOBILEtt = 101, //! < track-trainer (unused) OBJECT_MOBILEft = 102, //! < fly-trainer (unused) @@ -170,7 +166,6 @@ enum ObjectType OBJECT_BARRIER1 = 401, //! < Barrier1 OBJECT_BARRIER2 = 402, //! < Barrier2 OBJECT_BARRIER3 = 403, //! < Barrier3 - OBJECT_BARRIER4 = 404, //! < Barrier4 OBJECT_MOTHER = 500, //! < AlienQueen OBJECT_EGG = 501, //! < AlienEgg OBJECT_ANT = 502, //! < AlienAnt @@ -235,41 +230,18 @@ enum ObjectType OBJECT_TEEN42 = 662, //! < Teen42 OBJECT_TEEN43 = 663, //! < Teen43 OBJECT_TEEN44 = 664, //! < Teen44 - OBJECT_TEEN45 = 665, //! < Teen45 - OBJECT_TEEN46 = 666, //! < Teen46 - OBJECT_TEEN47 = 667, //! < Teen47 - OBJECT_TEEN48 = 668, //! < Teen48 - OBJECT_TEEN49 = 669, //! < Teen49 OBJECT_QUARTZ0 = 700, //! < Quartz0 OBJECT_QUARTZ1 = 701, //! < Quartz1 OBJECT_QUARTZ2 = 702, //! < Quartz2 OBJECT_QUARTZ3 = 703, //! < Quartz3 - OBJECT_QUARTZ4 = 704, //! < Quartz4 - OBJECT_QUARTZ5 = 705, //! < Quartz5 - OBJECT_QUARTZ6 = 706, //! < Quartz6 - OBJECT_QUARTZ7 = 707, //! < Quartz7 - OBJECT_QUARTZ8 = 708, //! < Quartz8 - OBJECT_QUARTZ9 = 709, //! < Quartz9 OBJECT_ROOT0 = 710, //! < MegaStalk0 OBJECT_ROOT1 = 711, //! < MegaStalk1 OBJECT_ROOT2 = 712, //! < MegaStalk2 OBJECT_ROOT3 = 713, //! < MegaStalk3 OBJECT_ROOT4 = 714, //! < MegaStalk4 OBJECT_ROOT5 = 715, //! < MegaStalk5 - OBJECT_ROOT6 = 716, //! < MegaStalk6 - OBJECT_ROOT7 = 717, //! < MegaStalk7 - OBJECT_ROOT8 = 718, //! < MegaStalk8 - OBJECT_ROOT9 = 719, //! < MegaStalk9 - OBJECT_MUSHROOM0 = 730, //! < Mushroom0 OBJECT_MUSHROOM1 = 731, //! < Mushroom1 OBJECT_MUSHROOM2 = 732, //! < Mushroom2 - OBJECT_MUSHROOM3 = 733, //! < Mushroom3 - OBJECT_MUSHROOM4 = 734, //! < Mushroom4 - OBJECT_MUSHROOM5 = 735, //! < Mushroom5 - OBJECT_MUSHROOM6 = 736, //! < Mushroom6 - OBJECT_MUSHROOM7 = 737, //! < Mushroom7 - OBJECT_MUSHROOM8 = 738, //! < Mushroom8 - OBJECT_MUSHROOM9 = 739, //! < Mushroom9 OBJECT_APOLLO1 = 900, //! < ApolloLEM OBJECT_APOLLO2 = 901, //! < ApolloJeep OBJECT_APOLLO3 = 902, //! < ApolloFlag diff --git a/src/object/objman.cpp b/src/object/objman.cpp index 131d007..b0bac1a 100644 --- a/src/object/objman.cpp +++ b/src/object/objman.cpp @@ -160,8 +160,7 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType if ( type == OBJECT_BARRIER0 || type == OBJECT_BARRIER1 || type == OBJECT_BARRIER2 || - type == OBJECT_BARRIER3 || - type == OBJECT_BARRIER4 ) + type == OBJECT_BARRIER3 ) { object = new CObject(); object->CreateBarrier(pos, angle, height, type); @@ -192,26 +191,14 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type == OBJECT_TREE2 || type == OBJECT_TREE3 || type == OBJECT_TREE4 || - type == OBJECT_TREE5 || - type == OBJECT_TREE6 || - type == OBJECT_TREE7 || - type == OBJECT_TREE8 || - type == OBJECT_TREE9 ) + type == OBJECT_TREE5 ) { object = new CObject(); object->CreatePlant(pos, angle, height, type); } else - if ( type == OBJECT_MUSHROOM0 || - type == OBJECT_MUSHROOM1 || - type == OBJECT_MUSHROOM2 || - type == OBJECT_MUSHROOM3 || - type == OBJECT_MUSHROOM4 || - type == OBJECT_MUSHROOM5 || - type == OBJECT_MUSHROOM6 || - type == OBJECT_MUSHROOM7 || - type == OBJECT_MUSHROOM8 || - type == OBJECT_MUSHROOM9 ) + if ( type == OBJECT_MUSHROOM1 || + type == OBJECT_MUSHROOM2 ) { object = new CObject(); object->CreateMushroom(pos, angle, height, type); @@ -261,12 +248,7 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type == OBJECT_TEEN41 || type == OBJECT_TEEN42 || type == OBJECT_TEEN43 || - type == OBJECT_TEEN44 || - type == OBJECT_TEEN45 || - type == OBJECT_TEEN46 || - type == OBJECT_TEEN47 || - type == OBJECT_TEEN48 || - type == OBJECT_TEEN49 ) + type == OBJECT_TEEN44 ) { object = new CObject(); object->SetOption(option); @@ -276,13 +258,7 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType if ( type == OBJECT_QUARTZ0 || type == OBJECT_QUARTZ1 || type == OBJECT_QUARTZ2 || - type == OBJECT_QUARTZ3 || - type == OBJECT_QUARTZ4 || - type == OBJECT_QUARTZ5 || - type == OBJECT_QUARTZ6 || - type == OBJECT_QUARTZ7 || - type == OBJECT_QUARTZ8 || - type == OBJECT_QUARTZ9 ) + type == OBJECT_QUARTZ3 ) { object = new CObject(); object->CreateQuartz(pos, angle, height, type); @@ -293,11 +269,7 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type == OBJECT_ROOT2 || type == OBJECT_ROOT3 || type == OBJECT_ROOT4 || - type == OBJECT_ROOT5 || - type == OBJECT_ROOT6 || - type == OBJECT_ROOT7 || - type == OBJECT_ROOT8 || - type == OBJECT_ROOT9 ) + type == OBJECT_ROOT5 ) { object = new CObject(); object->CreateRoot(pos, angle, height, type); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 0d95907..ced1127 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4592,11 +4592,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) (type >= OBJECT_PLANT0 && type <= OBJECT_PLANT19 ) || (type >= OBJECT_TREE0 && - type <= OBJECT_TREE9 ) || + type <= OBJECT_TREE5 ) || (type >= OBJECT_TEEN0 && - type <= OBJECT_TEEN49 ) || + type <= OBJECT_TEEN44 ) || (type >= OBJECT_QUARTZ0 && - type <= OBJECT_QUARTZ9 ) || + type <= OBJECT_QUARTZ3 ) || (type >= OBJECT_ROOT0 && type <= OBJECT_ROOT4 ) ) // not ROOT5! { diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 01ff38b..8070d13 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -1559,8 +1559,8 @@ void CTaskGoto::ComputeRepulse(Math::Point &dir) oType == OBJECT_BOMB || (oType >= OBJECT_PLANT0 && oType <= OBJECT_PLANT19 ) || - (oType >= OBJECT_MUSHROOM0 && - oType <= OBJECT_MUSHROOM9 ) ) continue; + (oType >= OBJECT_MUSHROOM1 && + oType <= OBJECT_MUSHROOM2 ) ) continue; } addi = add; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 85dd3a2..a7e1e6c 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2565,19 +2565,19 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) oType == OBJECT_KEYd || oType == OBJECT_TNT || (oType >= OBJECT_PLANT0 && oType <= OBJECT_PLANT19 ) || - (oType >= OBJECT_MUSHROOM0 && oType <= OBJECT_MUSHROOM9) ) continue; + (oType >= OBJECT_MUSHROOM1 && oType <= OBJECT_MUSHROOM2) ) continue; } -#if _TEEN +/* TODO: #if _TEEN if ( oType == OBJECT_WAYPOINT && pObj->GetEnable() && !m_object->GetResetBusy() ) // driving vehicle? -#else +#else */ if ( oType == OBJECT_WAYPOINT && pObj->GetEnable() && !m_object->GetResetBusy() && m_object->GetTrainer() ) // driving vehicle? -#endif +/* #endif */ { oPos = pObj->GetPosition(0); distance = Math::DistanceProjected(oPos, iPos); diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index 076a38f..da4a886 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -271,20 +271,8 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Tree3" ) ) return OBJECT_TREE3; if ( Cmd(p, "Tree4" ) ) return OBJECT_TREE4; if ( Cmd(p, "Tree5" ) ) return OBJECT_TREE5; - if ( Cmd(p, "Tree6" ) ) return OBJECT_TREE6; - if ( Cmd(p, "Tree7" ) ) return OBJECT_TREE7; - if ( Cmd(p, "Tree8" ) ) return OBJECT_TREE8; - if ( Cmd(p, "Tree9" ) ) return OBJECT_TREE9; - if ( Cmd(p, "Mushroom0" ) ) return OBJECT_MUSHROOM0; if ( Cmd(p, "Mushroom1" ) ) return OBJECT_MUSHROOM1; if ( Cmd(p, "Mushroom2" ) ) return OBJECT_MUSHROOM2; - if ( Cmd(p, "Mushroom3" ) ) return OBJECT_MUSHROOM3; - if ( Cmd(p, "Mushroom4" ) ) return OBJECT_MUSHROOM4; - if ( Cmd(p, "Mushroom5" ) ) return OBJECT_MUSHROOM5; - if ( Cmd(p, "Mushroom6" ) ) return OBJECT_MUSHROOM6; - if ( Cmd(p, "Mushroom7" ) ) return OBJECT_MUSHROOM7; - if ( Cmd(p, "Mushroom8" ) ) return OBJECT_MUSHROOM8; - if ( Cmd(p, "Mushroom9" ) ) return OBJECT_MUSHROOM9; if ( Cmd(p, "Home" ) ) return OBJECT_HOME1; if ( Cmd(p, "Derrick" ) ) return OBJECT_DERRICK; if ( Cmd(p, "BotFactory" ) ) return OBJECT_FACTORY; @@ -330,7 +318,6 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Barrier1" ) ) return OBJECT_BARRIER1; if ( Cmd(p, "Barrier2" ) ) return OBJECT_BARRIER2; if ( Cmd(p, "Barrier3" ) ) return OBJECT_BARRIER3; - if ( Cmd(p, "Barrier4" ) ) return OBJECT_BARRIER4; if ( Cmd(p, "Teen0" ) ) return OBJECT_TEEN0; if ( Cmd(p, "Teen1" ) ) return OBJECT_TEEN1; if ( Cmd(p, "Teen2" ) ) return OBJECT_TEEN2; @@ -376,31 +363,16 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "Teen42" ) ) return OBJECT_TEEN42; if ( Cmd(p, "Teen43" ) ) return OBJECT_TEEN43; if ( Cmd(p, "Teen44" ) ) return OBJECT_TEEN44; - if ( Cmd(p, "Teen45" ) ) return OBJECT_TEEN45; - if ( Cmd(p, "Teen46" ) ) return OBJECT_TEEN46; - if ( Cmd(p, "Teen47" ) ) return OBJECT_TEEN47; - if ( Cmd(p, "Teen48" ) ) return OBJECT_TEEN48; - if ( Cmd(p, "Teen49" ) ) return OBJECT_TEEN49; if ( Cmd(p, "Quartz0" ) ) return OBJECT_QUARTZ0; if ( Cmd(p, "Quartz1" ) ) return OBJECT_QUARTZ1; if ( Cmd(p, "Quartz2" ) ) return OBJECT_QUARTZ2; if ( Cmd(p, "Quartz3" ) ) return OBJECT_QUARTZ3; - if ( Cmd(p, "Quartz4" ) ) return OBJECT_QUARTZ4; - if ( Cmd(p, "Quartz5" ) ) return OBJECT_QUARTZ5; - if ( Cmd(p, "Quartz6" ) ) return OBJECT_QUARTZ6; - if ( Cmd(p, "Quartz7" ) ) return OBJECT_QUARTZ7; - if ( Cmd(p, "Quartz8" ) ) return OBJECT_QUARTZ8; - if ( Cmd(p, "Quartz9" ) ) return OBJECT_QUARTZ9; if ( Cmd(p, "MegaStalk0" ) ) return OBJECT_ROOT0; if ( Cmd(p, "MegaStalk1" ) ) return OBJECT_ROOT1; if ( Cmd(p, "MegaStalk2" ) ) return OBJECT_ROOT2; if ( Cmd(p, "MegaStalk3" ) ) return OBJECT_ROOT3; if ( Cmd(p, "MegaStalk4" ) ) return OBJECT_ROOT4; if ( Cmd(p, "MegaStalk5" ) ) return OBJECT_ROOT5; - if ( Cmd(p, "MegaStalk6" ) ) return OBJECT_ROOT6; - if ( Cmd(p, "MegaStalk7" ) ) return OBJECT_ROOT7; - if ( Cmd(p, "MegaStalk8" ) ) return OBJECT_ROOT8; - if ( Cmd(p, "MegaStalk9" ) ) return OBJECT_ROOT9; if ( Cmd(p, "ApolloLEM" ) ) return OBJECT_APOLLO1; if ( Cmd(p, "ApolloJeep" ) ) return OBJECT_APOLLO2; if ( Cmd(p, "ApolloFlag" ) ) return OBJECT_APOLLO3; @@ -445,11 +417,7 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_MOBILEdr ) return "Scribbler"; if ( type == OBJECT_MARKPOWER ) return "PowerSpot"; if ( type == OBJECT_MARKSTONE ) return "TitaniumSpot"; -#if _GERMAN | _WG - if ( type == OBJECT_MARKURANIUM ) return "PlatinumSpot"; -#else if ( type == OBJECT_MARKURANIUM ) return "UraniumSpot"; -#endif if ( type == OBJECT_MARKKEYa ) return "KeyASpot"; if ( type == OBJECT_MARKKEYb ) return "KeyBSpot"; if ( type == OBJECT_MARKKEYc ) return "KeyCSpot"; @@ -461,17 +429,9 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_FLAGy ) return "YellowFlag"; if ( type == OBJECT_FLAGv ) return "VioletFlag"; if ( type == OBJECT_POWER ) return "PowerCell"; -#if _GERMAN | _WG - if ( type == OBJECT_ATOMIC ) return "FuelCell"; -#else if ( type == OBJECT_ATOMIC ) return "NuclearCell"; -#endif if ( type == OBJECT_STONE ) return "TitaniumOre"; -#if _GERMAN | _WG - if ( type == OBJECT_URANIUM ) return "PlatinumOre"; -#else if ( type == OBJECT_URANIUM ) return "UraniumOre"; -#endif if ( type == OBJECT_METAL ) return "Titanium"; if ( type == OBJECT_BULLET ) return "OrgaMatter"; if ( type == OBJECT_BBOX ) return "BlackBox"; @@ -514,20 +474,8 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_TREE3 ) return "Tree3"; if ( type == OBJECT_TREE4 ) return "Tree4"; if ( type == OBJECT_TREE5 ) return "Tree5"; - if ( type == OBJECT_TREE6 ) return "Tree6"; - if ( type == OBJECT_TREE7 ) return "Tree7"; - if ( type == OBJECT_TREE8 ) return "Tree8"; - if ( type == OBJECT_TREE9 ) return "Tree9"; - if ( type == OBJECT_MUSHROOM0 ) return "Mushroom0"; if ( type == OBJECT_MUSHROOM1 ) return "Mushroom1"; if ( type == OBJECT_MUSHROOM2 ) return "Mushroom2"; - if ( type == OBJECT_MUSHROOM3 ) return "Mushroom3"; - if ( type == OBJECT_MUSHROOM4 ) return "Mushroom4"; - if ( type == OBJECT_MUSHROOM5 ) return "Mushroom5"; - if ( type == OBJECT_MUSHROOM6 ) return "Mushroom6"; - if ( type == OBJECT_MUSHROOM7 ) return "Mushroom7"; - if ( type == OBJECT_MUSHROOM8 ) return "Mushroom8"; - if ( type == OBJECT_MUSHROOM9 ) return "Mushroom9"; if ( type == OBJECT_HOME1 ) return "Home"; if ( type == OBJECT_DERRICK ) return "Derrick"; if ( type == OBJECT_FACTORY ) return "BotFactory"; @@ -542,11 +490,7 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_INFO ) return "ExchangePost"; if ( type == OBJECT_ENERGY ) return "PowerPlant"; if ( type == OBJECT_LABO ) return "AutoLab"; -/* TODO: #if _GERMAN | _WG - if ( type == OBJECT_NUCLEAR ) return "FuelCellPlant"; -#else */ if ( type == OBJECT_NUCLEAR ) return "NuclearPlant"; -/* #endif */ if ( type == OBJECT_PARA ) return "PowerCaptor"; if ( type == OBJECT_SAFE ) return "Vault"; if ( type == OBJECT_HUSTON ) return "Houston"; @@ -577,7 +521,6 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_BARRIER1 ) return "Barrier1"; if ( type == OBJECT_BARRIER2 ) return "Barrier2"; if ( type == OBJECT_BARRIER3 ) return "Barrier3"; - if ( type == OBJECT_BARRIER4 ) return "Barrier4"; if ( type == OBJECT_TEEN0 ) return "Teen0"; if ( type == OBJECT_TEEN1 ) return "Teen1"; if ( type == OBJECT_TEEN2 ) return "Teen2"; @@ -623,31 +566,16 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_TEEN42 ) return "Teen42"; if ( type == OBJECT_TEEN43 ) return "Teen43"; if ( type == OBJECT_TEEN44 ) return "Teen44"; - if ( type == OBJECT_TEEN45 ) return "Teen45"; - if ( type == OBJECT_TEEN46 ) return "Teen46"; - if ( type == OBJECT_TEEN47 ) return "Teen47"; - if ( type == OBJECT_TEEN48 ) return "Teen48"; - if ( type == OBJECT_TEEN49 ) return "Teen49"; if ( type == OBJECT_QUARTZ0 ) return "Quartz0"; if ( type == OBJECT_QUARTZ1 ) return "Quartz1"; if ( type == OBJECT_QUARTZ2 ) return "Quartz2"; if ( type == OBJECT_QUARTZ3 ) return "Quartz3"; - if ( type == OBJECT_QUARTZ4 ) return "Quartz4"; - if ( type == OBJECT_QUARTZ5 ) return "Quartz5"; - if ( type == OBJECT_QUARTZ6 ) return "Quartz6"; - if ( type == OBJECT_QUARTZ7 ) return "Quartz7"; - if ( type == OBJECT_QUARTZ8 ) return "Quartz8"; - if ( type == OBJECT_QUARTZ9 ) return "Quartz9"; if ( type == OBJECT_ROOT0 ) return "MegaStalk0"; if ( type == OBJECT_ROOT1 ) return "MegaStalk1"; if ( type == OBJECT_ROOT2 ) return "MegaStalk2"; if ( type == OBJECT_ROOT3 ) return "MegaStalk3"; if ( type == OBJECT_ROOT4 ) return "MegaStalk4"; if ( type == OBJECT_ROOT5 ) return "MegaStalk5"; - if ( type == OBJECT_ROOT6 ) return "MegaStalk6"; - if ( type == OBJECT_ROOT7 ) return "MegaStalk7"; - if ( type == OBJECT_ROOT8 ) return "MegaStalk8"; - if ( type == OBJECT_ROOT9 ) return "MegaStalk9"; if ( type == OBJECT_APOLLO1 ) return "ApolloLEM"; if ( type == OBJECT_APOLLO2 ) return "ApolloJeep"; if ( type == OBJECT_APOLLO3 ) return "ApolloFlag"; -- cgit v1.2.3-1-g7c22 From c5ae2610b57e54216ee55214bd74368c9c7e22ee Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 18 Jan 2014 03:42:07 +0100 Subject: Minor changes to sound support. * changed channel limit from 64 to 2048 that will decrease if error is found while trying to play sound * added id to each channel to avoid collisions when more than 1 object tries to modify a sound * minor formatting changes --- src/sound/oalsound/alsound.cpp | 143 ++++++++++++++++++++++++++++++----------- src/sound/oalsound/alsound.h | 3 + src/sound/oalsound/buffer.cpp | 2 +- src/sound/oalsound/channel.cpp | 31 ++++++--- src/sound/oalsound/channel.h | 4 ++ 5 files changed, 135 insertions(+), 48 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 5058141..3f8bade 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -33,6 +33,7 @@ ALSound::ALSound() m_lookat.LoadZero(); m_previousMusic.fadeTime = 0.0f; m_previousMusic.music = nullptr; + m_channels_limit = 2048; } @@ -243,11 +244,16 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) for (auto it : m_channels) { if (it.second->IsPlaying()) + { continue; + } if (it.second->GetSoundType() != sound) + { continue; + } it.second->SetPriority(priority); + it.second->Reset(); channel = it.first; bAlreadyLoaded = it.second->IsLoaded(); return true; @@ -261,6 +267,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) if (chn->IsReady()) { chn->SetPriority(priority); + chn->Reset(); m_channels[1] = chn; channel = 1; bAlreadyLoaded = false; @@ -271,8 +278,8 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) return false; } - // Seeks a channel completely free. - if (m_channels.size() < 64) + // Assigns new channel within limit + if (m_channels.size() < m_channels_limit) { auto it = m_channels.end(); it--; @@ -286,13 +293,14 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) if (chn->IsReady()) { chn->SetPriority(priority); + chn->Reset(); m_channels[++i] = chn; channel = i; bAlreadyLoaded = false; return true; } delete chn; - GetLogger()->Warn("Could not open additional channel to play sound!\n"); + GetLogger()->Debug("Could not open additional channel to play sound!\n"); } } } @@ -304,6 +312,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) { GetLogger()->Debug("Sound channel with lower priority will be reused.\n"); channel = it.first; + it.second->Reset(); return true; } if (it.second->GetPriority() <= priority) @@ -313,11 +322,12 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded) if (lowerOrEqual != -1) { channel = lowerOrEqual; + m_channels[channel]->Reset(); GetLogger()->Debug("Sound channel with lower or equal priority will be reused.\n"); return true; } - GetLogger()->Warn("Could not find free buffer to use.\n"); + GetLogger()->Debug("Could not find free buffer to use.\n"); return false; } @@ -343,7 +353,9 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f int channel; bool bAlreadyLoaded = false; if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded)) + { return -1; + } if (!bAlreadyLoaded) { @@ -354,7 +366,7 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f } } - Position(channel, pos); + m_channels[channel]->SetPosition(pos); m_channels[channel]->SetVolumeAtrib(1.0f); // setting initial values @@ -365,15 +377,25 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f m_channels[channel]->SetFrequency(frequency); m_channels[channel]->SetVolume(powf(amplitude * m_channels[channel]->GetVolumeAtrib(), 0.2f) * m_audioVolume); m_channels[channel]->SetLoop(bLoop); - m_channels[channel]->Play(); - return channel; + if (!m_channels[channel]->Play()) + { + GetLogger()->Debug("Changing channel limit to %u.\n", --m_channels_limit); + auto it = m_channels.find(channel); + Channel *ch = it->second; + m_channels.erase(it); + delete ch; + + return -1; + } + + return channel | ((m_channels[channel]->GetId() & 0xffff) << 16); } bool ALSound::FlushEnvelope(int channel) { - if (m_channels.find(channel) == m_channels.end()) + if (!CheckChannel(channel)) { return false; } @@ -385,10 +407,7 @@ bool ALSound::FlushEnvelope(int channel) bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) { - if (!m_enabled) - return false; - - if (m_channels.find(channel) == m_channels.end()) + if (!CheckChannel(channel)) { return false; } @@ -407,10 +426,7 @@ bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float t bool ALSound::Position(int channel, const Math::Vector &pos) { - if (!m_enabled) - return false; - - if (m_channels.find(channel) == m_channels.end()) + if (!CheckChannel(channel)) { return false; } @@ -422,10 +438,7 @@ bool ALSound::Position(int channel, const Math::Vector &pos) bool ALSound::Frequency(int channel, float frequency) { - if (!m_enabled) - return false; - - if (m_channels.find(channel) == m_channels.end()) + if (!CheckChannel(channel)) { return false; } @@ -437,10 +450,7 @@ bool ALSound::Frequency(int channel, float frequency) bool ALSound::Stop(int channel) { - if (!m_enabled) - return false; - - if (m_channels.find(channel) == m_channels.end()) + if (!CheckChannel(channel)) { return false; } @@ -455,7 +465,9 @@ bool ALSound::Stop(int channel) bool ALSound::StopAll() { if (!m_enabled) + { return false; + } for (auto channel : m_channels) { @@ -470,7 +482,9 @@ bool ALSound::StopAll() bool ALSound::MuteAll(bool bMute) { if (!m_enabled) + { return false; + } for (auto it : m_channels) { @@ -479,7 +493,7 @@ bool ALSound::MuteAll(bool bMute) it.second->Mute(bMute); } } - + return true; } @@ -487,7 +501,9 @@ bool ALSound::MuteAll(bool bMute) void ALSound::FrameMove(float delta) { if (!m_enabled) + { return; + } float progress; float volume, frequency; @@ -550,19 +566,25 @@ void ALSound::FrameMove(float delta) for (auto& it : m_oldMusic) { - if (it.currentTime >= it.fadeTime) { + if (it.currentTime >= it.fadeTime) + { delete it.music; toRemove.push_back(it); - } else { + } + else + { it.currentTime += delta; it.music->SetVolume(((it.fadeTime-it.currentTime) / it.fadeTime) * m_musicVolume); } } if (m_previousMusic.fadeTime > 0.0f) { - if (m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + if (m_previousMusic.currentTime >= m_previousMusic.fadeTime) + { m_previousMusic.music->Pause(); - } else { + } + else + { m_previousMusic.currentTime += delta; m_previousMusic.music->SetVolume(((m_previousMusic.fadeTime-m_previousMusic.currentTime) / m_previousMusic.fadeTime) * m_musicVolume); } @@ -585,6 +607,7 @@ void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) alListenerfv(AL_ORIENTATION, orientation); } + bool ALSound::PlayMusic(int rank, bool bRepeat, float fadeTime) { std::stringstream filename; @@ -592,15 +615,19 @@ bool ALSound::PlayMusic(int rank, bool bRepeat, float fadeTime) return PlayMusic(filename.str(), bRepeat, fadeTime); } + bool operator<(const OldMusic & l, const OldMusic & r) { return l.currentTime < r.currentTime; } + + bool operator==(const OldMusic & l, const OldMusic & r) { return l.currentTime == r.currentTime; } + bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTime) { if (!m_enabled) @@ -632,8 +659,9 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim GetLogger()->Debug("Music loaded from cache\n"); buffer = m_music[filename]; } - - if (m_currentMusic) { + + if (m_currentMusic) + { OldMusic old; old.music = m_currentMusic; old.fadeTime = fadeTime; @@ -650,17 +678,22 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return true; } + bool ALSound::PlayPauseMusic(const std::string &filename) { - if (m_previousMusic.fadeTime > 0.0f) { + if (m_previousMusic.fadeTime > 0.0f) + { OldMusic old; old.music = m_currentMusic; old.fadeTime = 2.0f; old.currentTime = 0.0f; m_oldMusic.push_back(old); m_currentMusic = nullptr; - } else { - if (m_currentMusic) { + } + else + { + if (m_currentMusic) + { m_previousMusic.music = m_currentMusic; m_previousMusic.fadeTime = 2.0f; m_previousMusic.currentTime = 0.0f; @@ -670,16 +703,20 @@ bool ALSound::PlayPauseMusic(const std::string &filename) return PlayMusic(filename, true); } + void ALSound::StopPauseMusic() { - if (m_previousMusic.fadeTime > 0.0f) { + if (m_previousMusic.fadeTime > 0.0f) + { StopMusic(); - + m_currentMusic = m_previousMusic.music; m_previousMusic.music = nullptr; - if(m_currentMusic != nullptr) { + if(m_currentMusic != nullptr) + { m_currentMusic->SetVolume(m_musicVolume); - if(m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + if(m_previousMusic.currentTime >= m_previousMusic.fadeTime) + { m_currentMusic->Play(); } } @@ -700,6 +737,7 @@ bool ALSound::RestartMusic() return true; } + void ALSound::StopMusic(float fadeTime) { if (!m_enabled || !m_currentMusic) @@ -737,3 +775,32 @@ void ALSound::SuspendMusic() m_currentMusic->Stop(); } + + +bool ALSound::CheckChannel(int &channel) +{ + int id = (channel >> 16) & 0xffff; + channel &= 0xffff; + + if (!m_enabled) + { + return false; + } + + if (m_channels.find(channel) == m_channels.end()) + { + return false; + } + + if (m_audioVolume == 0) + { + return false; + } + + if (m_channels[channel]->GetId() != id) + { + return false; + } + + return true; +} diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 6fb832e..4113098 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -81,6 +81,8 @@ public: bool PlayPauseMusic(const std::string &filename); void StopPauseMusic(); + bool CheckChannel(int &channel); + private: void CleanUp(); int GetPriority(Sound); @@ -89,6 +91,7 @@ private: bool m_enabled; float m_audioVolume; float m_musicVolume; + unsigned int m_channels_limit; ALCdevice* m_device; ALCcontext* m_context; std::map m_sounds; diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index 0047f91..b27029c 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -32,7 +32,7 @@ Buffer::~Buffer() { alDeleteBuffers(1, &m_buffer); if (alCheck()) - GetLogger()->Warn("Failed to unload buffer. Code %d\n", alGetCode()); + GetLogger()->Debug("Failed to unload buffer. Code %d\n", alGetCode()); } } diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index e58ab54..7021c2f 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -23,7 +23,7 @@ Channel::Channel() if (alCheck()) { - GetLogger()->Warn("Failed to create sound source. Code: %d\n", alGetCode()); + GetLogger()->Debug("Failed to create sound source. Code: %d\n", alGetCode()); m_ready = false; } else @@ -40,6 +40,7 @@ Channel::Channel() m_startFrequency = 0.0f; m_changeFrequency = 0.0f; m_volume = 0.0f; + m_id = 0; } @@ -51,7 +52,7 @@ Channel::~Channel() alSourcei(m_source, AL_BUFFER, 0); alDeleteSources(1, &m_source); if (alCheck()) - GetLogger()->Warn("Failed to delete sound source. Code: %d\n", alGetCode()); + GetLogger()->Debug("Failed to delete sound source. Code: %d\n", alGetCode()); } } @@ -69,7 +70,7 @@ bool Channel::Play() alSourcePlay(m_source); if (alCheck()) { - GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode()); + GetLogger()->Debug("Could not play audio sound source. Code: %d\n", alGetCode()); } return true; } @@ -84,7 +85,7 @@ bool Channel::Pause() alSourcePause(m_source); if (alCheck()) { - GetLogger()->Warn("Could not pause audio sound source. Code: %d\n", alGetCode()); + GetLogger()->Debug("Could not pause audio sound source. Code: %d\n", alGetCode()); } return true; } @@ -100,7 +101,7 @@ bool Channel::SetPosition(const Math::Vector &pos) alSource3f(m_source, AL_POSITION, pos.x, pos.y, pos.z); if (alCheck()) { - GetLogger()->Warn("Could not set sound position. Code: %d\n", alGetCode()); + GetLogger()->Debug("Could not set sound position. Code: %d\n", alGetCode()); return false; } return true; @@ -117,7 +118,7 @@ bool Channel::SetFrequency(float freq) alSourcef(m_source, AL_PITCH, freq); if (alCheck()) { - GetLogger()->Warn("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode()); + GetLogger()->Debug("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode()); return false; } return true; @@ -135,7 +136,7 @@ float Channel::GetFrequency() alGetSourcef(m_source, AL_PITCH, &freq); if (alCheck()) { - GetLogger()->Warn("Could not get sound pitch. Code: %d\n", alGetCode()); + GetLogger()->Debug("Could not get sound pitch. Code: %d\n", alGetCode()); return 0; } @@ -153,7 +154,7 @@ bool Channel::SetVolume(float vol) alSourcef(m_source, AL_GAIN, vol); if (alCheck()) { - GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); + GetLogger()->Debug("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); return false; } return true; @@ -171,7 +172,7 @@ float Channel::GetVolume() alGetSourcef(m_source, AL_GAIN, &vol); if (alCheck()) { - GetLogger()->Warn("Could not get sound volume. Code: %d\n", alGetCode()); + GetLogger()->Debug("Could not get sound volume. Code: %d\n", alGetCode()); return 0; } @@ -434,3 +435,15 @@ bool Channel::IsMuted() return m_mute; } + +void Channel::Reset() +{ + m_id++; +} + + +int Channel::GetId() +{ + return m_id; +} + diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index f973198..1d988c9 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -97,11 +97,15 @@ public: void Mute(bool); bool IsMuted(); + void Reset(); + int GetId(); + private: Buffer *m_buffer; ALuint m_source; int m_priority; + int m_id; float m_startAmplitude; float m_startFrequency; float m_changeFrequency; -- cgit v1.2.3-1-g7c22 From 181a4049309600ef31c2d22b3823429c6ee331df Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 18 Jan 2014 19:20:40 +0100 Subject: Fixed warnings about unknown commands in scene files --- src/object/robotmain.cpp | 14 +++++++++++--- src/script/cmdtoken.cpp | 10 ++++++++++ src/script/cmdtoken.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index ced1127..b1cbe52 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -81,6 +81,9 @@ #include +#include + + template<> CRobotMain* CSingleton::m_instance = nullptr; @@ -4050,9 +4053,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (Cmd(line, "Title")) continue; // Ignore - if (Cmd(line, "Resume")) continue; // Ignore - if (Cmd(line, "ScriptName")) continue; // Ignore + static const boost::regex titleCmdRe("Title\\.[A-Z]"); + static const boost::regex resumeCmdRe("Resume\\.[A-Z]"); + static const boost::regex scriptNameCmdRe("ScriptName\.[A-Z]"); + + if (boost::regex_match(GetCmd(line), titleCmdRe)) continue; // Ignore + if (boost::regex_match(GetCmd(line), resumeCmdRe)) continue; // Ignore + if (boost::regex_match(GetCmd(line), scriptNameCmdRe)) continue; // Ignore + if (Cmd(line, "ScriptFile") && !resetObject) { diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index da4a886..6393505 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -35,6 +35,16 @@ char* SkipSpace(char *line) return line; } +std::string GetCmd(char* line) +{ + line = SkipSpace(line); + + int len = 0; + for(char* x = line; *x != 0 && *x != ' ' && *x != '\t' && *x != '\n'; x++, len++); + + return std::string(line, len); +} + // Checks if a line contains a command. bool Cmd(char *line, const char *token) diff --git a/src/script/cmdtoken.h b/src/script/cmdtoken.h index 24b592f..8a423c5 100644 --- a/src/script/cmdtoken.h +++ b/src/script/cmdtoken.h @@ -30,6 +30,7 @@ // Procedures. +extern std::string GetCmd(char* line); extern bool Cmd(char *line, const char *token); extern char* SearchOp(char *line, const char *op); -- cgit v1.2.3-1-g7c22 From 604d4a614e994e60254f724dcbf629684760fe54 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 18 Jan 2014 20:16:31 +0100 Subject: Fixed tests compilation --- test/unit/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 278519f..269ffc2 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -23,6 +23,7 @@ configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/comm # Code sources set(COLOBOT_SOURCES ${SRC_DIR}/app/app.cpp +${SRC_DIR}/app/pausemanager.cpp ${SRC_DIR}/app/system.cpp ${SRC_DIR}/app/${SYSTEM_CPP_MODULE} ${SRC_DIR}/app/system_other.cpp -- cgit v1.2.3-1-g7c22 From d88511f89cc3f7a8f235c96773bcd3e2f396d4f2 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 18 Jan 2014 20:17:19 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 530c8b1..d58fb31 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 530c8b1048dc484f015652bb97492b83b2d8d9c7 +Subproject commit d58fb314ad6886f7bf57ece996861d050d993b1e -- cgit v1.2.3-1-g7c22 From 70b18cc4c05398cd06558f4634937a70c2436546 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 18 Jan 2014 21:35:32 +0100 Subject: Move engine frame update after game state update This should finally fix #225 --- src/app/app.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index a2162b1..70bec81 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -960,15 +960,15 @@ int CApplication::Run() { LogEvent(event); - StartPerformanceCounter(PCNT_UPDATE_ENGINE); - m_engine->FrameUpdate(); - StopPerformanceCounter(PCNT_UPDATE_ENGINE); - m_sound->FrameMove(m_relTime); StartPerformanceCounter(PCNT_UPDATE_GAME); m_robotMain->ProcessEvent(event); StopPerformanceCounter(PCNT_UPDATE_GAME); + + StartPerformanceCounter(PCNT_UPDATE_ENGINE); + m_engine->FrameUpdate(); + StopPerformanceCounter(PCNT_UPDATE_ENGINE); } StopPerformanceCounter(PCNT_UPDATE_ALL); -- cgit v1.2.3-1-g7c22 From d84d38280b3ed706ff2371fc88e43a2a7245d3dd Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 2 Feb 2014 01:50:34 +0100 Subject: Changed max number of sound channels --- src/sound/oalsound/alsound.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 3f8bade..9ef9341 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -20,6 +20,7 @@ #include #include +#include #include @@ -380,7 +381,8 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f if (!m_channels[channel]->Play()) { - GetLogger()->Debug("Changing channel limit to %u.\n", --m_channels_limit); + m_channels_limit = std::min(m_channels.size() - 1, m_channels_limit - 1); + GetLogger()->Debug("Changing channel limit to %u.\n", m_channels_limit); auto it = m_channels.find(channel); Channel *ch = it->second; m_channels.erase(it); -- cgit v1.2.3-1-g7c22 From f21ab91184cf5b6a97bc5ae62c49ac8ac68a8b05 Mon Sep 17 00:00:00 2001 From: erihel Date: Sun, 2 Feb 2014 02:01:42 +0100 Subject: Changed max channels to fix compilation error --- src/sound/oalsound/alsound.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 9ef9341..fab0445 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -20,7 +20,6 @@ #include #include -#include #include @@ -381,7 +380,7 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f if (!m_channels[channel]->Play()) { - m_channels_limit = std::min(m_channels.size() - 1, m_channels_limit - 1); + m_channels_limit = m_channels.size() - 1; GetLogger()->Debug("Changing channel limit to %u.\n", m_channels_limit); auto it = m_channels.find(channel); Channel *ch = it->second; -- cgit v1.2.3-1-g7c22 From 2433cb595acacf8433405fc9e446757280bd3108 Mon Sep 17 00:00:00 2001 From: erihel Date: Fri, 21 Feb 2014 10:13:48 +0100 Subject: Added a check when trying to play a music file --- src/sound/oalsound/alsound.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index fab0445..ce109e4 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -346,7 +346,7 @@ int ALSound::Play(Sound sound, const Math::Vector &pos, float amplitude, float f } if (m_sounds.find(sound) == m_sounds.end()) { - GetLogger()->Warn("Sound %d was not loaded!\n", sound); + GetLogger()->Debug("Sound %d was not loaded!\n", sound); return -1; } @@ -638,21 +638,23 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim std::stringstream file; file << m_soundPath << "/" << filename; - Buffer *buffer; // check if we have music in cache if (m_music.find(filename) == m_music.end()) { - GetLogger()->Warn("Music %s was not cached!\n", filename.c_str()); + GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); if (!boost::filesystem::exists(file.str())) { - GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str()); + GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); return false; } - + buffer = new Buffer(); - buffer->LoadFromFile(file.str(), static_cast(-1)); + if (!buffer->LoadFromFile(file.str(), static_cast(-1))) + { + return false; + } m_music[filename] = buffer; } else -- cgit v1.2.3-1-g7c22 From 2affc39b374fb83c22afb1e1deb3d82d3ab737da Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 21 Feb 2014 11:44:53 +0100 Subject: Fixed dev wiki link in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c67b755..7961e90 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is official repository for the open-source Colobot project developed by Pol The source code contained here was released by Epsitec -- the original creator of the game -- on open source (GPLv3) license. The code was given and the rights granted specifically to PPC community in March 2012. Since then, we have been developing the game further. -More information for developers (in English) can be found on the [developer wiki](http://colobot.info/w/Dev:Main_Page) or (in Polish) [our forum](http://colobot.info/forum/). However, the freshest source of information is our IRC channels (see below). +More information for developers (in English) can be found on the [developer wiki](http://colobot.info/wiki/Dev:Main_Page) or (in Polish) [our forum](http://colobot.info/forum/). However, the freshest source of information is our IRC channels (see below). This repository contains only the source code of the project. The game requires also data files which are now provided as git submodule and are hosted in [separate repository](https://github.com/colobot/colobot-data). @@ -54,7 +54,7 @@ To jest oficjalne repozytorium z kodem projektu open-source Colobot rozwijanego Kod źródłowy zawarty tutaj został wydany przez Epsitec -- oryginalnego twórcę gry -- na otwartej licencji (GPLv3). Kod został wydany i prawa nadane specjalnie dla społeczności PPC w marcu 2012. Od tamtej pory, zajmowaliśmy się dalszym rozwojem gry. -Więcej informacji dla developerów projektu (po angielsku) można znaleźć na [wiki dla developerów](htt://colobot.info/w/Dev:Main_Page) lub (po polsku) na [naszym forum](http://colobot.info/forum/). Jednak źródłem najświeższych informacji są nasze kanały IRC (patrz niżej). +Więcej informacji dla developerów projektu (po angielsku) można znaleźć na [wiki dla developerów](htt://colobot.info/wiki/Dev:Main_Page) lub (po polsku) na [naszym forum](http://colobot.info/forum/). Jednak źródłem najświeższych informacji są nasze kanały IRC (patrz niżej). To repozytorium zawiera jedynie kod źródłowy projektu. Gra wymaga jeszcze plików danych, które są teraz udostępniane jako submoduł gita i hostowane w [osobnym repozytorium]((https://github.com/colobot/colobot-data). -- cgit v1.2.3-1-g7c22 From bb2a9bcfd3f63434c4bfb01a31f2ab0d64d6260b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 21 Feb 2014 14:19:58 +0100 Subject: Added option to set pause audio in Scene --- data | 2 +- src/app/pausemanager.cpp | 24 +++------------------- src/object/robotmain.cpp | 46 +++++++++++++++++++++++++++++++++++++++--- src/object/robotmain.h | 9 +++++++-- src/sound/oalsound/alsound.cpp | 4 ++-- src/sound/oalsound/alsound.h | 2 +- src/sound/sound.cpp | 8 +------- src/sound/sound.h | 2 +- 8 files changed, 59 insertions(+), 38 deletions(-) diff --git a/data b/data index d58fb31..52a7290 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d58fb314ad6886f7bf57ece996861d050d993b1e +Subproject commit 52a729007d3dbf6e05761a1aa4c932960490730f diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index 761e158..d357bba 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -20,6 +20,8 @@ #include "common/logger.h" +#include "object/robotmain.h" + template<> CPauseManager* CSingleton::m_instance = nullptr; @@ -41,27 +43,7 @@ void CPauseManager::SetPause(PauseType pause) if(pause != PAUSE_NONE) { if(m_pause != pause) { CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); - switch(pause) { - case PAUSE_EDITOR: - // TODO: We don't have this music yet - // m_sound->PlayPauseMusic(""); - #if DEV_BUILD - m_sound->PlayPauseMusic("Prototype.ogg"); - #endif - break; - - case PAUSE_SATCOM: - // TODO: We don't have this music yet - // m_sound->PlayPauseMusic(""); - #if DEV_BUILD - m_sound->PlayPauseMusic("Constructive.ogg"); - #endif - break; - - default: - // Don't change music - break; - } + CRobotMain::GetInstancePointer()->StartPauseMusic(pause); } m_pause = pause; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index b1cbe52..e66e2c6 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -647,6 +647,10 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) m_visitArrow = 0; m_audioTrack = ""; m_audioRepeat = true; + m_satcomTrack = ""; + m_satcomRepeat = true; + m_editorTrack = ""; + m_editorRepeat = true; m_delayWriteMessage = 0; m_selectObject = 0; m_infoUsed = 0; @@ -3923,6 +3927,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_terrain->FlushMaterials(); m_audioTrack = ""; m_audioRepeat = true; + m_satcomTrack = ""; + m_satcomRepeat = true; + m_editorTrack = ""; + m_editorRepeat = true; m_displayText->SetDelay(1.0f); m_displayText->SetEnable(true); m_immediatSatCom = false; @@ -4028,8 +4036,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } } - if (Cmd(line, "MissionFile") && !resetObject) + if (Cmd(line, "MissionFile") && !resetObject) { m_version = OpInt(line, "version", 1); + continue; + } // TODO: Fallback to an non-localized entry sprintf(op, "Title.%c", m_app->GetLanguageChar()); @@ -4165,15 +4175,27 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) filenameStr << "music" << std::setfill('0') << std::setw(3) << trackid << ".ogg"; m_audioTrack = filenameStr.str(); } + m_audioRepeat = OpInt(line, "repeat", 1); } else { char trackname[100]; - OpString(line, "filename", trackname); + + OpString(line, "main", trackname); m_audioTrack = trackname; + m_audioRepeat = OpInt(line, "mainRepeat", 1); + + OpString(line, "satcom", trackname); + m_satcomTrack = trackname; + m_satcomRepeat = OpInt(line, "satcomRepeat", 1); + + OpString(line, "editor", trackname); + m_editorTrack = trackname; + m_editorRepeat = OpInt(line, "editorRepeat", 1); } - m_audioRepeat = OpInt(line, "repeat", 1); if (m_audioTrack != "") m_sound->CacheMusic(m_audioTrack); + if (m_satcomTrack != "") m_sound->CacheMusic(m_satcomTrack); + if (m_editorTrack != "") m_sound->CacheMusic(m_editorTrack); continue; } @@ -7220,6 +7242,24 @@ void CRobotMain::StartMusic() } } +//! Starts pause music +void CRobotMain::StartPauseMusic(PauseType pause) +{ + switch(pause) { + case PAUSE_EDITOR: + m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); + break; + + case PAUSE_SATCOM: + m_sound->PlayPauseMusic(m_satcomTrack, m_satcomRepeat); + break; + + default: + // Don't change music + break; + } +} + //! Removes hilite and tooltip void CRobotMain::ClearInterface() { diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 4fa842a..71ad455 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -340,6 +340,7 @@ public: float GetPersoAngle(); void StartMusic(); + void StartPauseMusic(PauseType pause); void ClearInterface(); void ChangeColor(); @@ -474,15 +475,19 @@ protected: bool m_showSoluce; bool m_showAll; bool m_cheatRadar; - bool m_audioRepeat; bool m_shortCut; std::string m_audioTrack; + bool m_audioRepeat; + std::string m_satcomTrack; + bool m_satcomRepeat; + std::string m_editorTrack; + bool m_editorRepeat; int m_delayWriteMessage; int m_movieInfoIndex; CObject* m_controller; - //Level Checker flags + // Level Checker flags bool m_beginObject; bool m_terrainGenerate; bool m_terrainInitTextures; diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index ce109e4..ad03970 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -682,7 +682,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim } -bool ALSound::PlayPauseMusic(const std::string &filename) +bool ALSound::PlayPauseMusic(const std::string &filename, bool repeat) { if (m_previousMusic.fadeTime > 0.0f) { @@ -703,7 +703,7 @@ bool ALSound::PlayPauseMusic(const std::string &filename) m_currentMusic = nullptr; } } - return PlayMusic(filename, true); + return PlayMusic(filename, repeat); } diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 4113098..bb9bf28 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -78,7 +78,7 @@ public: void SuspendMusic(); void StopMusic(float fadeTime=2.0f); bool IsPlayingMusic(); - bool PlayPauseMusic(const std::string &filename); + bool PlayPauseMusic(const std::string &filename, bool repeat); void StopPauseMusic(); bool CheckChannel(int &channel); diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 3802611..c4b30b5 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -59,12 +59,6 @@ void CSoundInterface::AddMusicFiles(const std::string &path) CacheMusic("Intro2.ogg"); CacheMusic("music010.ogg"); CacheMusic("music011.ogg"); - // TODO: Add pause music here - // CacheMusic(""); - #if DEV_BUILD - CacheMusic("Prototype.ogg"); - CacheMusic("Constructive.ogg"); - #endif } bool CSoundInterface::Cache(Sound bSound, const std::string &bFile) @@ -181,7 +175,7 @@ bool CSoundInterface::IsPlayingMusic() return true; } -bool CSoundInterface::PlayPauseMusic(const std::string &filename) +bool CSoundInterface::PlayPauseMusic(const std::string &filename, bool repeat) { return true; } diff --git a/src/sound/sound.h b/src/sound/sound.h index 135ee43..e86da2b 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -321,7 +321,7 @@ public: * \param filename - name of file to play * \return return true on success */ - virtual bool PlayPauseMusic(const std::string &filename); + virtual bool PlayPauseMusic(const std::string &filename, bool repeat); /** Stop playing pause music and return to the mission music * \return nothing -- cgit v1.2.3-1-g7c22 From 351616a9bfaada066a0c96c78235eefb7bb46824 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 21 Feb 2014 14:24:35 +0100 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 52a7290..8c148a8 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 52a729007d3dbf6e05761a1aa4c932960490730f +Subproject commit 8c148a8d5dd57e3662b3422d7c50b55ce518b22e -- cgit v1.2.3-1-g7c22 From 14709427c46897a37991a35beecb351428265a7f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 21 Feb 2014 14:33:56 +0100 Subject: Fixed compile warning --- src/object/robotmain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index e66e2c6..80f605c 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4065,7 +4065,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) static const boost::regex titleCmdRe("Title\\.[A-Z]"); static const boost::regex resumeCmdRe("Resume\\.[A-Z]"); - static const boost::regex scriptNameCmdRe("ScriptName\.[A-Z]"); + static const boost::regex scriptNameCmdRe("ScriptName\\.[A-Z]"); if (boost::regex_match(GetCmd(line), titleCmdRe)) continue; // Ignore if (boost::regex_match(GetCmd(line), resumeCmdRe)) continue; // Ignore -- cgit v1.2.3-1-g7c22 From e9960f53730f84c299147cb996fb656da48dfa66 Mon Sep 17 00:00:00 2001 From: andreymal Date: Sun, 2 Mar 2014 04:15:59 +0400 Subject: GetStringWidth fix --- src/graphics/engine/text.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index ffd2eb2..581ff01 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -333,7 +333,7 @@ float CText::GetStringWidth(std::string text, FontType font, float size) // Skip special chars for (char& c : text) { - if (c < 32) + if (c < 32 && c >= 0) c = ':'; } @@ -351,7 +351,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) if (font == FONT_BUTTON) return 0.0f; int width = 1; - if (ch.c1 < 32) + if (ch.c1 < 32 && ch.c1 >= 0) { if (ch.c1 == '\t') width = m_tabSize; -- cgit v1.2.3-1-g7c22 From 1a0dcedf83d83e02403ebe79469c70c9fb8f35fb Mon Sep 17 00:00:00 2001 From: andreymal Date: Sun, 2 Mar 2014 18:00:02 +0400 Subject: fixed m_oldMusic.push_back(nullptr) and segfault --- src/sound/oalsound/alsound.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index ad03970..23476d4 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -514,7 +514,6 @@ void ALSound::FrameMove(float delta) { continue; } - if (it.second->IsMuted()) { it.second->SetVolume(0.0f); @@ -686,12 +685,15 @@ bool ALSound::PlayPauseMusic(const std::string &filename, bool repeat) { if (m_previousMusic.fadeTime > 0.0f) { - OldMusic old; - old.music = m_currentMusic; - old.fadeTime = 2.0f; - old.currentTime = 0.0f; - m_oldMusic.push_back(old); - m_currentMusic = nullptr; + if(m_currentMusic) + { + OldMusic old; + old.music = m_currentMusic; + old.fadeTime = 2.0f; + old.currentTime = 0.0f; + m_oldMusic.push_back(old); + m_currentMusic = nullptr; + } } else { -- cgit v1.2.3-1-g7c22 From a806d4257ce3f10a23441cfa962b9caf5deebb85 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 2 Mar 2014 14:39:29 +0100 Subject: Check if pause music is defined in scene before trying to play it --- src/object/robotmain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 80f605c..c71c437 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -7247,11 +7247,13 @@ void CRobotMain::StartPauseMusic(PauseType pause) { switch(pause) { case PAUSE_EDITOR: - m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); + if(m_editorTrack != "") + m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); break; case PAUSE_SATCOM: - m_sound->PlayPauseMusic(m_satcomTrack, m_satcomRepeat); + if(m_satcomTrack != "") + m_sound->PlayPauseMusic(m_satcomTrack, m_satcomRepeat); break; default: -- cgit v1.2.3-1-g7c22 From fbe2bf8bc7d61a7a13759f56e65181e16e25806b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 3 Mar 2014 21:55:28 +0100 Subject: Added special mode in scene for bots to build more buildings than they usualy can Will be used in "Leaving Earth" missions for making decorative bots building base --- src/object/object.cpp | 15 ++++++++++++++- src/object/object.h | 4 ++++ src/object/robotmain.cpp | 6 ++++++ src/object/task/taskbuild.cpp | 3 ++- src/script/script.cpp | 17 ++++++++++------- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/object/object.cpp b/src/object/object.cpp index 2c32da0..3c225d0 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -276,6 +276,7 @@ CObject::CObject() m_lastVirusParticle = 0.0f; m_totalDesectList = 0; m_bLock = false; + m_bIgnoreBuildCheck = false; m_bExplo = false; m_bCargo = false; m_bBurn = false; @@ -6781,7 +6782,7 @@ float CObject::GetParam() // Management of the mode "blocked" of an object. // For example, a cube of titanium is blocked while it is used to make something, -//or a vehicle is blocked as its construction is not finished. +// or a vehicle is blocked as its construction is not finished. void CObject::SetLock(bool bLock) { @@ -6793,6 +6794,18 @@ bool CObject::GetLock() return m_bLock; } +// Ignore checks in build() function + +void CObject::SetIgnoreBuildCheck(bool bIgnoreBuildCheck) +{ + m_bIgnoreBuildCheck = bIgnoreBuildCheck; +} + +bool CObject::GetIgnoreBuildCheck() +{ + return m_bIgnoreBuildCheck; +} + // Management of the mode "current explosion" of an object. // An object in this mode is not saving. diff --git a/src/object/object.h b/src/object/object.h index 5d9e681..0e469f2 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -582,6 +582,9 @@ public: void SetParam(float value); float GetParam(); + + void SetIgnoreBuildCheck(bool bIgnoreBuildCheck); + bool GetIgnoreBuildCheck(); void SetExplo(bool bExplo); bool GetExplo(); @@ -720,6 +723,7 @@ protected: bool m_bTrainer; // drive vehicle (without remote) bool m_bToy; // toy key bool m_bManual; // manual control (Scribbler) + bool m_bIgnoreBuildCheck; bool m_bFixed; bool m_bClip; bool m_bShowLimit; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index c71c437..011cab8 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4593,6 +4593,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { m_controller = CObjectManager::GetInstancePointer()->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f); m_controller->SetMagnifyDamage(100.0f); + m_controller->SetIgnoreBuildCheck(true); CBrain* brain = m_controller->GetBrain(); if (brain != nullptr) { @@ -4720,6 +4721,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) bool selectable = OpInt(line, "selectable", 1); obj->SetSelectable(selectable); + obj->SetIgnoreBuildCheck(OpInt(line, "ignoreBuildCheck", 0)); obj->SetEnable(OpInt(line, "enable", 1)); obj->SetProxyActivate(OpInt(line, "proxyActivate", 0)); obj->SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit); @@ -6068,6 +6070,9 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) sprintf(name, " trainer=%d", obj->GetTrainer()); strcat(line, name); + + sprintf(name, " ignoreBuildCheck=%d", obj->GetIgnoreBuildCheck()); + strcat(line, name); sprintf(name, " option=%d", obj->GetOption()); strcat(line, name); @@ -6229,6 +6234,7 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) obj->SetDefRank(objRank); obj->SetPosition(0, pos); obj->SetAngle(0, dir); + obj->SetIgnoreBuildCheck(OpInt(line, "ignoreBuildCheck", 0)); obj->SetID(id); if (g_id < id) g_id = id; diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index 4a62a4a..4dfd6fb 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -100,6 +100,7 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) if ( m_type == OBJECT_PARA ) m_buildingHeight = 68.0f; if ( m_type == OBJECT_INFO ) m_buildingHeight = 19.0f; if ( m_type == OBJECT_DESTROYER) m_buildingHeight = 35.0f; + if ( m_type == OBJECT_HUSTON ) m_buildingHeight = 45.0f; m_buildingHeight *= 0.25f; m_buildingPos = m_building->GetPosition(0); @@ -574,7 +575,7 @@ Error CTaskBuild::FlatFloor() if ( m_type == OBJECT_PARA ) radius = 20.0f; if ( m_type == OBJECT_INFO ) radius = 5.0f; if ( m_type == OBJECT_DESTROYER) radius = 20.0f; - if ( radius == 0.0f ) return ERR_GENERIC; + //if ( radius == 0.0f ) return ERR_GENERIC; center = m_metal->GetPosition(0); angle = m_terrain->GetFineSlope(center); diff --git a/src/script/script.cpp b/src/script/script.cpp index 1a26e62..3a4d2d1 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1665,7 +1665,7 @@ bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* use (category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER))) { - //if we want to build not researched one + // if we want to build not researched one if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) || (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC)) ) @@ -1709,7 +1709,7 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) } else { - category = static_cast(var->GetValInt()); //get category parameter + category = static_cast(var->GetValInt()); // get category parameter if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) || (category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) || (category == OBJECT_STATION && (g_build & BUILD_STATION)) || @@ -1726,7 +1726,7 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) (category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER))) { - //if we want to build not researched one + // if we want to build not researched one if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) || (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC)) ) @@ -1739,8 +1739,11 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) } } + + if (pThis->GetIgnoreBuildCheck()) + err = ERR_OK; - if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present + if (err == ERR_OK && script->m_primaryTask == 0) // if we can build and no task is present { script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskBuild(category); @@ -1751,9 +1754,9 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) script->m_primaryTask = 0; } } - //When script is waiting for finishing this task, it sets ERR_OK, and continues executing Process - //without creating new task. I think, there was a problem with previous version in release configuration - //It did not init error variable in this situation, and code tried to use variable with trash inside + // When script is waiting for finishing this task, it sets ERR_OK, and continues executing Process + // without creating new task. I think, there was a problem with previous version in release configuration + // It did not init error variable in this situation, and code tried to use variable with trash inside } if ( err != ERR_OK ) -- cgit v1.2.3-1-g7c22 From a61da7404bf8430132864d493c7e75a6b4c3d978 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sat, 8 Mar 2014 22:36:35 +0100 Subject: Added fall damage + changed window title --- src/app/app.cpp | 2 +- src/physics/physics.cpp | 16 ++++++++++++++++ src/physics/physics.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 70bec81..51f1e42 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -112,7 +112,7 @@ CApplication::CApplication() m_debugModes = 0; m_customDataPath = false; - m_windowTitle = "COLOBOT"; + m_windowTitle = "COLOBOT GOLD"; m_simulationSuspended = false; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index a7e1e6c..c84040e 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -107,6 +107,9 @@ CPhysics::CPhysics(CObject* object) m_bFreeze = false; m_bForceUpdate = true; m_bLowLevel = false; + m_fallingHeight = 0.0f; + m_fallDamageFraction = 0.0f; + m_minFallingHeight = 0.0f; memset(&m_linMotion, 0, sizeof(Motion)); memset(&m_cirMotion, 0,sizeof(Motion)); @@ -912,9 +915,15 @@ void CPhysics::MotorUpdate(float aTime, float rTime) if ( m_reactorRange < 0.5f ) m_bLowLevel = true; } + m_minFallingHeight = 20.0f; + m_fallDamageFraction = 0.007f; + if ( m_reactorRange == 0.0f ) // reactor tilt? { motorSpeed.y = -1.0f; // grave + + if (m_fallingHeight == 0.0f && m_floorHeight >= m_minFallingHeight) + m_fallingHeight = m_floorHeight; } } @@ -974,6 +983,13 @@ void CPhysics::MotorUpdate(float aTime, float rTime) m_cirMotion.motorSpeed.y = 0.0f; } + if ( m_bLand && m_fallingHeight != 0.0f ) // if fell + { + float force = m_fallingHeight * m_fallDamageFraction; + m_object->ExploObject(EXPLO_BOUM, force); + m_fallingHeight = 0.0f; + } + if ( m_type == TYPE_FLYING && m_bLand ) // flying on the ground? { if ( type == OBJECT_HUMAN || diff --git a/src/physics/physics.h b/src/physics/physics.h index 834d7b8..cf15b13 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -248,5 +248,8 @@ protected: bool m_bSoundSlow; bool m_bForceUpdate; bool m_bLowLevel; + float m_fallingHeight; + float m_fallDamageFraction; + float m_minFallingHeight; }; -- cgit v1.2.3-1-g7c22 From 3dd400810f16657d1f99963f249a8b93f640fdd6 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sat, 8 Mar 2014 23:20:39 +0100 Subject: Fixed bug from a61da7404bf8430132864d493c7e75a6b4c3d978 Moved ExploObject to CPhysics::EventFrame, it shouldn't crash anymore. --- src/physics/physics.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index c84040e..2ab7425 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -983,13 +983,6 @@ void CPhysics::MotorUpdate(float aTime, float rTime) m_cirMotion.motorSpeed.y = 0.0f; } - if ( m_bLand && m_fallingHeight != 0.0f ) // if fell - { - float force = m_fallingHeight * m_fallDamageFraction; - m_object->ExploObject(EXPLO_BOUM, force); - m_fallingHeight = 0.0f; - } - if ( m_type == TYPE_FLYING && m_bLand ) // flying on the ground? { if ( type == OBJECT_HUMAN || @@ -1621,6 +1614,13 @@ bool CPhysics::EventFrame(const Event &event) MotorParticle(m_time, event.rTime); SoundMotor(event.rTime); + if ( m_bLand && m_fallingHeight != 0.0f ) // if fell + { + float force = m_fallingHeight * m_fallDamageFraction; + m_object->ExploObject(EXPLO_BOUM, force); + m_fallingHeight = 0.0f; + } + m_bForceUpdate = false; return true; -- cgit v1.2.3-1-g7c22 From 2ee0702d69728016593030e1b3a18d537563dab4 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sun, 9 Mar 2014 14:36:39 +0100 Subject: Made some improvements to fall damage from a61da740 Fall damage on: - no energy - overheat Fall damage off: - underwater --- src/physics/physics.cpp | 46 ++++++++++++++++++++++++++++++++++++++-------- src/physics/physics.h | 19 ++++++++++++++----- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 2ab7425..0d1c6fe 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -108,8 +108,8 @@ CPhysics::CPhysics(CObject* object) m_bForceUpdate = true; m_bLowLevel = false; m_fallingHeight = 0.0f; - m_fallDamageFraction = 0.0f; - m_minFallingHeight = 0.0f; + m_minFallingHeight = 20.0f; + m_fallDamageFraction = 0.007f; memset(&m_linMotion, 0, sizeof(Motion)); memset(&m_cirMotion, 0,sizeof(Motion)); @@ -854,6 +854,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime) else { motorSpeed.y = -1.0f; // grave + SetFalling(); } SetMotor(false); } @@ -915,15 +916,10 @@ void CPhysics::MotorUpdate(float aTime, float rTime) if ( m_reactorRange < 0.5f ) m_bLowLevel = true; } - m_minFallingHeight = 20.0f; - m_fallDamageFraction = 0.007f; - if ( m_reactorRange == 0.0f ) // reactor tilt? { motorSpeed.y = -1.0f; // grave - - if (m_fallingHeight == 0.0f && m_floorHeight >= m_minFallingHeight) - m_fallingHeight = m_floorHeight; + SetFalling(); } } @@ -1522,6 +1518,7 @@ bool CPhysics::EventFrame(const Event &event) if ( pos.y < m_water->GetLevel(m_object) ) // underwater? { h *= 0.5f; + m_fallingHeight = 0.0f; // can't fall underwater } #endif //? m_linMotion.terrainSpeed.x = -tAngle.z*m_linMotion.terrainForce.x*h; @@ -3901,3 +3898,36 @@ Error CPhysics::GetError() return ERR_OK; } +void CPhysics::SetFalling() +{ + if (m_fallingHeight == 0.0f && m_floorHeight >= m_minFallingHeight) + m_fallingHeight = m_floorHeight; +} + +float CPhysics::GetFallingHeight() +{ + return m_fallingHeight; +} + +void CPhysics::SetMinFallingHeight(float value) +{ + if (value < 0.0f) return; + m_minFallingHeight = value; +} + +float CPhysics::GetMinFallingHeight() +{ + return m_minFallingHeight; +} + +void CPhysics::SetFallDamageFraction(float value) +{ + if (value < 0.0f) return; + m_fallDamageFraction = value; +} + +float CPhysics::GetFallDamageFraction() +{ + return m_fallDamageFraction; +} + diff --git a/src/physics/physics.h b/src/physics/physics.h index cf15b13..fea5601 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -165,6 +165,14 @@ public: void CreateInterface(bool bSelect); Error GetError(); + float GetFallingHeight(); + + void SetMinFallingHeight(float value); + float GetMinFallingHeight(); + + void SetFallDamageFraction(float value); + float GetFallDamageFraction(); + protected: bool EventFrame(const Event &event); void WaterFrame(float aTime, float rTime); @@ -191,6 +199,7 @@ protected: void MotorParticle(float aTime, float rTime); void WaterParticle(float aTime, Math::Vector pos, ObjectType type, float floor, float advance, float turn); void WheelParticle(int color, float width); + void SetFalling(); protected: Gfx::CEngine* m_engine; @@ -240,16 +249,16 @@ protected: float m_restBreakParticle; float m_floorLevel; // ground level float m_floorHeight; // height above the ground - int m_soundChannel; - int m_soundChannelSlide; + int m_soundChannel; + int m_soundChannelSlide; float m_soundTimePshhh; float m_soundTimeJostle; float m_soundTimeBoum; bool m_bSoundSlow; bool m_bForceUpdate; bool m_bLowLevel; - float m_fallingHeight; - float m_fallDamageFraction; - float m_minFallingHeight; + float m_fallingHeight; + float m_fallDamageFraction; + float m_minFallingHeight; }; -- cgit v1.2.3-1-g7c22 From 3bb951119ed26f28d822ed26c622673f1445f526 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sun, 9 Mar 2014 17:20:19 +0100 Subject: Replaced an old icon with a new one --- desktop/colobot.ico | Bin 353118 -> 370070 bytes desktop/colobot.svg | 538 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 350 insertions(+), 188 deletions(-) diff --git a/desktop/colobot.ico b/desktop/colobot.ico index 54ab418..e71b6d1 100644 Binary files a/desktop/colobot.ico and b/desktop/colobot.ico differ diff --git a/desktop/colobot.svg b/desktop/colobot.svg index ef5949f..c514d6b 100644 --- a/desktop/colobot.svg +++ b/desktop/colobot.svg @@ -8,232 +8,394 @@ xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="32" + height="32" + id="svg2" version="1.1" - width="48" - height="48" - id="colobot-logo" - style="enable-background:new"> - Colobot icon - - - - image/svg+xml - - Colobot icon - 2012-12-27 - - - - - - - - Polish Portal of Colobot - - - - Three spheres symbolizing planets. - - - Didier Raboud <odyx@debian.org> - - - - - + inkscape:version="0.48.4 r9939" + sodipodi:docname="colobot_gold_icon.svg"> + id="defs4"> + inkscape:collect="always" + id="linearGradient3992"> + style="stop-color:#f5c700;stop-opacity:1;" + offset="0" + id="stop3994" /> + offset="1" + id="stop3996" /> + inkscape:collect="always" + id="linearGradient3984"> + style="stop-color:#f5c700;stop-opacity:1;" + offset="0" + id="stop3986" /> + style="stop-color:#000000;stop-opacity:1" + offset="1" + id="stop3988" /> + inkscape:collect="always" + id="linearGradient3971"> + style="stop-color:#f5c700;stop-opacity:1;" + offset="0" + id="stop3973" /> + offset="1" + id="stop3975" /> + inkscape:collect="always" + id="linearGradient3963"> + style="stop-color:#000000;stop-opacity:1" + offset="0" + id="stop3965" /> + style="stop-color:#7f6400;stop-opacity:0;" + offset="1" + id="stop3967" /> + inkscape:collect="always" + id="linearGradient3945"> + style="stop-color:#f5c700;stop-opacity:1;" + offset="0" + id="stop3947" /> + offset="1" + id="stop3949" /> + inkscape:collect="always" + id="linearGradient3929"> + style="stop-color:#1a1500;stop-opacity:1" + offset="0" + id="stop3931" /> + style="stop-color:#d7ae00;stop-opacity:1" + offset="1" + id="stop3933" /> + + + + + + + + - - - + gradientTransform="matrix(2.3589521,0,0,2.3589521,-24.265377,-34.101604)" /> - + + + x1="3.3806913" + y1="1040.2177" + x2="24.976213" + y2="1037.3557" + gradientTransform="matrix(1,0,0,-1,3.746111e-8,2073.851)" /> + + + + + + + + - + + + + + image/svg+xml + + + + + + transform="translate(0,-1020.3622)"> - - - - - - - - - - - - - - - - + id="g4088" + style="fill:#000000;fill-opacity:1;stroke:none;filter:url(#filter4138)"> + + + + + + + + + + + + + + + + + + + + + + - -- cgit v1.2.3-1-g7c22 From 244ca93cf7c224cc855501893701ed556b7425e5 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Wed, 12 Mar 2014 19:43:20 +0100 Subject: Fixed bug with fall damage If you change the height after overheat, you get damage like you didn't change it at all. For example: overheat when you are 10 meters above the ground, and you fall to place 20 meters deeper, but you get the damage like you fell from 10 meters instead of 30. This commit fix this. --- src/physics/physics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 0d1c6fe..ad59ec0 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -1613,7 +1613,7 @@ bool CPhysics::EventFrame(const Event &event) if ( m_bLand && m_fallingHeight != 0.0f ) // if fell { - float force = m_fallingHeight * m_fallDamageFraction; + float force = (m_fallingHeight - m_object->GetPosition(0).y) * m_fallDamageFraction; m_object->ExploObject(EXPLO_BOUM, force); m_fallingHeight = 0.0f; } @@ -3901,7 +3901,7 @@ Error CPhysics::GetError() void CPhysics::SetFalling() { if (m_fallingHeight == 0.0f && m_floorHeight >= m_minFallingHeight) - m_fallingHeight = m_floorHeight; + m_fallingHeight = m_object->GetPosition(0).y; } float CPhysics::GetFallingHeight() -- cgit v1.2.3-1-g7c22 From e569fd6c3938ca885bfca0978d143def154abd73 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sun, 16 Mar 2014 15:25:49 +0100 Subject: Fix for #294 --- src/object/task/taskrecover.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/object/task/taskrecover.cpp b/src/object/task/taskrecover.cpp index af84099..d8bbafd 100644 --- a/src/object/task/taskrecover.cpp +++ b/src/object/task/taskrecover.cpp @@ -105,9 +105,11 @@ bool CTaskRecover::EventProcess(const Event &event) if ( power != 0 ) { energy = power->GetEnergy(); - power->SetEnergy(energy-ENERGY_RECOVER*event.rTime*m_speed); + energy -= event.rTime * ENERGY_RECOVER / power->GetCapacity() * m_speed; + power->SetEnergy(energy); } + speed.x = (Math::Rand()-0.5f)*0.1f*m_progress; speed.y = (Math::Rand()-0.5f)*0.1f*m_progress; speed.z = (Math::Rand()-0.5f)*0.1f*m_progress; -- cgit v1.2.3-1-g7c22 From 2cf84ad2148c8f88a1153771b357cc8b3208e38a Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Fri, 21 Mar 2014 09:34:52 +0200 Subject: Added spaces to align values --- src/common/global.h | 260 ++++++++++++++++++++++++++-------------------------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/src/common/global.h b/src/common/global.h index da62bac..5f85ce3 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -28,137 +28,137 @@ */ enum Error { - ERR_OK = 0, //! < ok - ERR_GENERIC = 1, //! < any error - ERR_CONTINUE = 2, //! < continues - ERR_STOP = 3, //! < stops - ERR_CMD = 4, //! < unknown command - ERR_MANIP_VEH = 100, //! < inappropriate vehicle - ERR_MANIP_FLY = 101, //! < impossible in flight - ERR_MANIP_BUSY = 102, //! < taking: hands already occupied - ERR_MANIP_NIL = 103, //! < taking: nothing has to take - ERR_MANIP_MOTOR = 105, //! < busy: impossible to move - ERR_MANIP_OCC = 106, //! < busy: location already occupied - ERR_MANIP_FRIEND = 107, //! < no other vehicle - ERR_MANIP_RADIO = 108, //! < impossible because radioactive - ERR_MANIP_WATER = 109, //! < not possible under water - ERR_MANIP_EMPTY = 110, //! < nothing to deposit - ERR_BUILD_FLY = 120, //! < not possible in flight - ERR_BUILD_WATER = 121, //! < not possible under water - ERR_BUILD_ENERGY = 122, //! < not enough energy - ERR_BUILD_METALAWAY = 123, //! < lack of metal (too far) - ERR_BUILD_METALNEAR = 124, //! < lack of metal (too close) - ERR_BUILD_METALINEX = 125, //! < lack of metal - ERR_BUILD_FLAT = 126, //! < not enough flat ground - ERR_BUILD_FLATLIT = 127, //! < not enough flat ground space - ERR_BUILD_BUSY = 128, //! < location occupied - ERR_BUILD_BASE = 129, //! < too close to the rocket - ERR_BUILD_NARROW = 130, //! < buildings too close - ERR_BUILD_MOTOR = 131, //! < built: not possible in movement - ERR_BUILD_DISABLED = 132, //! < built: can not produce this object in this mission - ERR_BUILD_RESEARCH = 133, //! < built: can not produce not researched object - ERR_SEARCH_FLY = 140, //! < not possible in flight - ERR_SEARCH_VEH = 141, //! < inappropriate vehicle - ERR_SEARCH_MOTOR = 142, //! < impossible in movement - ERR_TERRA_VEH = 150, //! < inappropriate vehicle - ERR_TERRA_ENERGY = 151, //! < not enough energy - ERR_TERRA_FLOOR = 152, //! < inappropriate ground - ERR_TERRA_BUILDING = 153, //! < building too close - ERR_TERRA_OBJECT = 154, //! < object too close - ERR_FIRE_VEH = 160, //! < inappropriate vehicle - ERR_FIRE_ENERGY = 161, //! < not enough energy - ERR_FIRE_FLY = 162, //! < not possible in flight - ERR_RECOVER_VEH = 170, //! < inappropriate vehicle - ERR_RECOVER_ENERGY = 171, //! < not enough energy - ERR_RECOVER_NULL = 172, //! < lack of ruin - ERR_CONVERT_EMPTY = 180, //! < no stone was transformed - ERR_SHIELD_VEH = 190, //! < inappropriate vehicle - ERR_SHIELD_ENERGY = 191, //! < not enough energy - ERR_MOVE_IMPOSSIBLE = 200, //! < move impossible - ERR_FIND_IMPOSSIBLE = 201, //! < find impossible - ERR_GOTO_IMPOSSIBLE = 210, //! < goto impossible - ERR_GOTO_ITER = 211, //! < goto too complicated - ERR_GOTO_BUSY = 212, //! < goto destination occupied - ERR_DERRICK_NULL = 300, //! < no ore underground - ERR_STATION_NULL = 301, //! < no energy underground - ERR_TOWER_POWER = 310, //! < no battery - ERR_TOWER_ENERGY = 311, //! < more energy - ERR_RESEARCH_POWER = 320, //! < no battery - ERR_RESEARCH_ENERGY = 321, //! < more energy - ERR_RESEARCH_TYPE = 322, //! < the wrong type of battery - ERR_RESEARCH_ALREADY = 323, //! < research already done - ERR_ENERGY_NULL = 330, //! < no energy underground - ERR_ENERGY_LOW = 331, //! < not enough energy - ERR_ENERGY_EMPTY = 332, //! < lack of metal - ERR_ENERGY_BAD = 333, //! < transforms only the metal - ERR_BASE_DLOCK = 340, //! < doors locked - ERR_BASE_DHUMAN = 341, //! < you must be on spaceship - ERR_LABO_NULL = 350, //! < nothing to analyze - ERR_LABO_BAD = 351, //! < analyzes only organic ball - ERR_LABO_ALREADY = 352, //! < analysis already made - ERR_NUCLEAR_NULL = 360, //! < no energy underground - ERR_NUCLEAR_LOW = 361, //! < not enough energy - ERR_NUCLEAR_EMPTY = 362, //! < lack of uranium - ERR_NUCLEAR_BAD = 363, //! < transforms only uranium - ERR_FACTORY_NULL = 370, //! < no metal - ERR_FACTORY_NEAR = 371, //! < vehicle too close - ERR_RESET_NEAR = 380, //! < vehicle too close - ERR_INFO_NULL = 390, //! < no information terminal - ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus - ERR_BAT_VIRUS = 401, //! < building infected by a virus - ERR_DESTROY_NOTFOUND = 410, //! < not found anything to destroy - ERR_WRONG_OBJ = 420, //! < inappropriate vehicle - ERR_VEH_POWER = 500, //! < no battery - ERR_VEH_ENERGY = 501, //! < more energy - ERR_FLAG_FLY = 510, //! < impossible in flight - ERR_FLAG_WATER = 511, //! < impossible during swimming - ERR_FLAG_MOTOR = 512, //! < impossible in movement - ERR_FLAG_BUSY = 513, //! < taking: already creating flag - ERR_FLAG_CREATE = 514, //! < too many flags - ERR_FLAG_PROXY = 515, //! < too close - ERR_FLAG_DELETE = 516, //! < nothing to remove - ERR_MISSION_NOTERM = 600, //! < Mission not completed - ERR_DELETEMOBILE = 700, //! < vehicle destroyed - ERR_DELETEBUILDING = 701, //! < building destroyed - ERR_TOOMANY = 702, //! < too many objects - ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing - ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited + ERR_OK = 0, //! < ok + ERR_GENERIC = 1, //! < any error + ERR_CONTINUE = 2, //! < continues + ERR_STOP = 3, //! < stops + ERR_CMD = 4, //! < unknown command + ERR_MANIP_VEH = 100, //! < inappropriate vehicle + ERR_MANIP_FLY = 101, //! < impossible in flight + ERR_MANIP_BUSY = 102, //! < taking: hands already occupied + ERR_MANIP_NIL = 103, //! < taking: nothing has to take + ERR_MANIP_MOTOR = 105, //! < busy: impossible to move + ERR_MANIP_OCC = 106, //! < busy: location already occupied + ERR_MANIP_FRIEND = 107, //! < no other vehicle + ERR_MANIP_RADIO = 108, //! < impossible because radioactive + ERR_MANIP_WATER = 109, //! < not possible under water + ERR_MANIP_EMPTY = 110, //! < nothing to deposit + ERR_BUILD_FLY = 120, //! < not possible in flight + ERR_BUILD_WATER = 121, //! < not possible under water + ERR_BUILD_ENERGY = 122, //! < not enough energy + ERR_BUILD_METALAWAY = 123, //! < lack of metal (too far) + ERR_BUILD_METALNEAR = 124, //! < lack of metal (too close) + ERR_BUILD_METALINEX = 125, //! < lack of metal + ERR_BUILD_FLAT = 126, //! < not enough flat ground + ERR_BUILD_FLATLIT = 127, //! < not enough flat ground space + ERR_BUILD_BUSY = 128, //! < location occupied + ERR_BUILD_BASE = 129, //! < too close to the rocket + ERR_BUILD_NARROW = 130, //! < buildings too close + ERR_BUILD_MOTOR = 131, //! < built: not possible in movement + ERR_BUILD_DISABLED = 132, //! < built: can not produce this object in this mission + ERR_BUILD_RESEARCH = 133, //! < built: can not produce not researched object + ERR_SEARCH_FLY = 140, //! < not possible in flight + ERR_SEARCH_VEH = 141, //! < inappropriate vehicle + ERR_SEARCH_MOTOR = 142, //! < impossible in movement + ERR_TERRA_VEH = 150, //! < inappropriate vehicle + ERR_TERRA_ENERGY = 151, //! < not enough energy + ERR_TERRA_FLOOR = 152, //! < inappropriate ground + ERR_TERRA_BUILDING = 153, //! < building too close + ERR_TERRA_OBJECT = 154, //! < object too close + ERR_FIRE_VEH = 160, //! < inappropriate vehicle + ERR_FIRE_ENERGY = 161, //! < not enough energy + ERR_FIRE_FLY = 162, //! < not possible in flight + ERR_RECOVER_VEH = 170, //! < inappropriate vehicle + ERR_RECOVER_ENERGY = 171, //! < not enough energy + ERR_RECOVER_NULL = 172, //! < lack of ruin + ERR_CONVERT_EMPTY = 180, //! < no stone was transformed + ERR_SHIELD_VEH = 190, //! < inappropriate vehicle + ERR_SHIELD_ENERGY = 191, //! < not enough energy + ERR_MOVE_IMPOSSIBLE = 200, //! < move impossible + ERR_FIND_IMPOSSIBLE = 201, //! < find impossible + ERR_GOTO_IMPOSSIBLE = 210, //! < goto impossible + ERR_GOTO_ITER = 211, //! < goto too complicated + ERR_GOTO_BUSY = 212, //! < goto destination occupied + ERR_DERRICK_NULL = 300, //! < no ore underground + ERR_STATION_NULL = 301, //! < no energy underground + ERR_TOWER_POWER = 310, //! < no battery + ERR_TOWER_ENERGY = 311, //! < more energy + ERR_RESEARCH_POWER = 320, //! < no battery + ERR_RESEARCH_ENERGY = 321, //! < more energy + ERR_RESEARCH_TYPE = 322, //! < the wrong type of battery + ERR_RESEARCH_ALREADY = 323, //! < research already done + ERR_ENERGY_NULL = 330, //! < no energy underground + ERR_ENERGY_LOW = 331, //! < not enough energy + ERR_ENERGY_EMPTY = 332, //! < lack of metal + ERR_ENERGY_BAD = 333, //! < transforms only the metal + ERR_BASE_DLOCK = 340, //! < doors locked + ERR_BASE_DHUMAN = 341, //! < you must be on spaceship + ERR_LABO_NULL = 350, //! < nothing to analyze + ERR_LABO_BAD = 351, //! < analyzes only organic ball + ERR_LABO_ALREADY = 352, //! < analysis already made + ERR_NUCLEAR_NULL = 360, //! < no energy underground + ERR_NUCLEAR_LOW = 361, //! < not enough energy + ERR_NUCLEAR_EMPTY = 362, //! < lack of uranium + ERR_NUCLEAR_BAD = 363, //! < transforms only uranium + ERR_FACTORY_NULL = 370, //! < no metal + ERR_FACTORY_NEAR = 371, //! < vehicle too close + ERR_RESET_NEAR = 380, //! < vehicle too close + ERR_INFO_NULL = 390, //! < no information terminal + ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus + ERR_BAT_VIRUS = 401, //! < building infected by a virus + ERR_DESTROY_NOTFOUND = 410, //! < not found anything to destroy + ERR_WRONG_OBJ = 420, //! < inappropriate vehicle + ERR_VEH_POWER = 500, //! < no battery + ERR_VEH_ENERGY = 501, //! < more energy + ERR_FLAG_FLY = 510, //! < impossible in flight + ERR_FLAG_WATER = 511, //! < impossible during swimming + ERR_FLAG_MOTOR = 512, //! < impossible in movement + ERR_FLAG_BUSY = 513, //! < taking: already creating flag + ERR_FLAG_CREATE = 514, //! < too many flags + ERR_FLAG_PROXY = 515, //! < too close + ERR_FLAG_DELETE = 516, //! < nothing to remove + ERR_MISSION_NOTERM = 600, //! < Mission not completed + ERR_DELETEMOBILE = 700, //! < vehicle destroyed + ERR_DELETEBUILDING = 701, //! < building destroyed + ERR_TOOMANY = 702, //! < too many objects + ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing + ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited - INFO_FIRST = 10000, //! < first information - INFO_BUILD = 10001, //! < construction builded - INFO_CONVERT = 10002, //! < metal available - INFO_RESEARCH = 10003, //! < search ended - INFO_FACTORY = 10004, //! < vehicle manufactured - INFO_LABO = 10005, //! < analysis ended - INFO_ENERGY = 10006, //! < battery available - INFO_NUCLEAR = 10007, //! < nuclear battery available - INFO_FINDING = 10008, //! < nuclear battery available - INFO_MARKPOWER = 10020, //! < location for station found - INFO_MARKURANIUM = 10021, //! < location for derrick found - INFO_MARKSTONE = 10022, //! < location for derrick found - INFO_MARKKEYa = 10023, //! < location for derrick found - INFO_MARKKEYb = 10024, //! < location for derrick found - INFO_MARKKEYc = 10025, //! < location for derrick found - INFO_MARKKEYd = 10026, //! < location for derrick found - INFO_RESEARCHTANK = 10030, //! < research ended - INFO_RESEARCHFLY = 10031, //! < research ended - INFO_RESEARCHTHUMP = 10032, //! < research ended - INFO_RESEARCHCANON = 10033, //! < research ended - INFO_RESEARCHTOWER = 10034, //! < research ended - INFO_RESEARCHPHAZER = 10035, //! < research ended - INFO_RESEARCHSHIELD = 10036, //! < research ended - INFO_RESEARCHATOMIC = 10037, //! < research ended - INFO_WIN = 10040, //! < win - INFO_LOST = 10041, //! < lost - INFO_LOSTq = 10042, //! < lost immediately - INFO_WRITEOK = 10043, //! < record done - INFO_DELETEPATH = 10050, //! < way mark deleted - INFO_DELETEMOTHER = 10100, //! < insect killed - INFO_DELETEANT = 10101, //! < insect killed - INFO_DELETEBEE = 10102, //! < insect killed - INFO_DELETEWORM = 10103, //! < insect killed - INFO_DELETESPIDER = 10104, //! < insect killed - INFO_BEGINSATCOM = 10105, //! < use your SatCom + INFO_FIRST = 10000, //! < first information + INFO_BUILD = 10001, //! < construction builded + INFO_CONVERT = 10002, //! < metal available + INFO_RESEARCH = 10003, //! < search ended + INFO_FACTORY = 10004, //! < vehicle manufactured + INFO_LABO = 10005, //! < analysis ended + INFO_ENERGY = 10006, //! < battery available + INFO_NUCLEAR = 10007, //! < nuclear battery available + INFO_FINDING = 10008, //! < nuclear battery available + INFO_MARKPOWER = 10020, //! < location for station found + INFO_MARKURANIUM = 10021, //! < location for derrick found + INFO_MARKSTONE = 10022, //! < location for derrick found + INFO_MARKKEYa = 10023, //! < location for derrick found + INFO_MARKKEYb = 10024, //! < location for derrick found + INFO_MARKKEYc = 10025, //! < location for derrick found + INFO_MARKKEYd = 10026, //! < location for derrick found + INFO_RESEARCHTANK = 10030, //! < research ended + INFO_RESEARCHFLY = 10031, //! < research ended + INFO_RESEARCHTHUMP = 10032, //! < research ended + INFO_RESEARCHCANON = 10033, //! < research ended + INFO_RESEARCHTOWER = 10034, //! < research ended + INFO_RESEARCHPHAZER = 10035, //! < research ended + INFO_RESEARCHSHIELD = 10036, //! < research ended + INFO_RESEARCHATOMIC = 10037, //! < research ended + INFO_WIN = 10040, //! < win + INFO_LOST = 10041, //! < lost + INFO_LOSTq = 10042, //! < lost immediately + INFO_WRITEOK = 10043, //! < record done + INFO_DELETEPATH = 10050, //! < way mark deleted + INFO_DELETEMOTHER = 10100, //! < insect killed + INFO_DELETEANT = 10101, //! < insect killed + INFO_DELETEBEE = 10102, //! < insect killed + INFO_DELETEWORM = 10103, //! < insect killed + INFO_DELETESPIDER = 10104, //! < insect killed + INFO_BEGINSATCOM = 10105, //! < use your SatCom ERR_MAX //! < number of values }; -- cgit v1.2.3-1-g7c22 From 7485ed790caeaa76efab0e9df48224cf1943ec27 Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Fri, 21 Mar 2014 13:08:36 +0200 Subject: Fixes #295 When cannon cannot turn at specified angle, it will still reach the edge angle, but return the error code --- src/common/global.h | 1 + src/object/task/taskgungoal.cpp | 24 ++++++++++++++++++++++-- src/object/task/taskgungoal.h | 2 ++ src/script/script.cpp | 23 +++++++++++++++++++++-- src/script/script.h | 3 +++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/common/global.h b/src/common/global.h index 5f85ce3..8b72774 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -123,6 +123,7 @@ enum Error ERR_TOOMANY = 702, //! < too many objects ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited + ERR_AIM_IMPOSSIBLE = 900, //! < cannot aim at specified angle(s) INFO_FIRST = 10000, //! < first information INFO_BUILD = 10001, //! < construction builded diff --git a/src/object/task/taskgungoal.cpp b/src/object/task/taskgungoal.cpp index 3373610..c9c8d30 100644 --- a/src/object/task/taskgungoal.cpp +++ b/src/object/task/taskgungoal.cpp @@ -26,6 +26,7 @@ CTaskGunGoal::CTaskGunGoal(CObject* object) : CTask(object) { + m_aimImpossible = false; } // Object's destructor. @@ -116,6 +117,12 @@ Error CTaskGunGoal::Start(float dirV, float dirH) m_progress = 0.0f; + // direction was constrainted, hence resulting in impossible move + if (dirV != m_finalDirV || dirH != m_finalDirH) + { + m_aimImpossible = true; + } + return ERR_OK; } @@ -126,12 +133,25 @@ Error CTaskGunGoal::IsEnded() if ( m_engine->GetPause() ) return ERR_CONTINUE; if ( m_initialDirV == m_finalDirV && - m_initialDirH == m_finalDirH ) return ERR_STOP; - if ( m_progress < 1.0f ) return ERR_CONTINUE; + m_initialDirH == m_finalDirH ) + { + if ( m_aimImpossible ) + return ERR_AIM_IMPOSSIBLE; + else + return ERR_STOP; + } + + if ( m_progress < 1.0f ) return ERR_CONTINUE; m_object->SetGunGoalV(m_finalDirV); m_object->SetGunGoalH(m_finalDirH); Abort(); + + if ( m_aimImpossible ) + { + return ERR_AIM_IMPOSSIBLE; + } + return ERR_STOP; } diff --git a/src/object/task/taskgungoal.h b/src/object/task/taskgungoal.h index c6f010b..9fc509d 100644 --- a/src/object/task/taskgungoal.h +++ b/src/object/task/taskgungoal.h @@ -44,5 +44,7 @@ protected: float m_finalDirV; // direction to reach float m_initialDirH; // initial direction float m_finalDirH; // direction to reach + + bool m_aimImpossible; // set to true if impossible aim was set }; diff --git a/src/script/script.cpp b/src/script/script.cpp index 3a4d2d1..d55c4d1 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1393,7 +1393,7 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception) if ( err == ERR_STOP ) err = ERR_OK; result->SetValInt(err); // indicates the error or ok - if ( err != ERR_OK && script->m_errMode == ERM_STOP ) + if ( ShouldExecutionStop(err, script->m_errMode) ) { exception = err; return false; @@ -1407,6 +1407,21 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception) } +// Returns true if error code means rela error and exception must be thrown + +bool CScript::ShouldExecutionStop(Error err, int errMode) +{ + // aim impossible - not a real error + if (err == ERR_AIM_IMPOSSIBLE) + return false; + + if (err != ERR_OK && errMode == ERM_STOP) + return true; + + return false; +} + + // Compilation of the instruction "detect(type)". CBotTypResult CScript::cDetect(CBotVar* &var, void* user) @@ -2954,7 +2969,11 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) var = var->GetNext(); var == 0 ? y=0.0f : y=var->GetValFloat(); err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f); - if ( err != ERR_OK ) + if (err == ERR_AIM_IMPOSSIBLE) + { + result->SetValInt(err); // shows the error + } + else if ( err != ERR_OK ) { delete script->m_primaryTask; script->m_primaryTask = 0; diff --git a/src/script/script.h b/src/script/script.h index afb89c8..694228a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -24,6 +24,8 @@ #include "common/event.h" +#include "common/global.h" + #include "app/pausemanager.h" #include "CBot/CBotDll.h" @@ -209,6 +211,7 @@ public: private: static bool Process(CScript* script, CBotVar* result, int &exception); + static bool ShouldExecutionStop(Error err, int errMode); static CObject* SearchInfo(CScript* script, CObject* object, float power); protected: -- cgit v1.2.3-1-g7c22 From 4491f51839a8d6806d27cc50bbb6e285205e3d24 Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Fri, 21 Mar 2014 13:15:15 +0200 Subject: Whitespace --- src/common/global.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/global.h b/src/common/global.h index 8b72774..79206af 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -106,7 +106,7 @@ enum Error ERR_INFO_NULL = 390, //! < no information terminal ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus ERR_BAT_VIRUS = 401, //! < building infected by a virus - ERR_DESTROY_NOTFOUND = 410, //! < not found anything to destroy + ERR_DESTROY_NOTFOUND = 410, //! < not found anything to destroy ERR_WRONG_OBJ = 420, //! < inappropriate vehicle ERR_VEH_POWER = 500, //! < no battery ERR_VEH_ENERGY = 501, //! < more energy -- cgit v1.2.3-1-g7c22 From 119fce546a993bdb3640234a04a365bbda1d1053 Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Fri, 21 Mar 2014 13:18:28 +0200 Subject: Issue #295 - continue Renamed the method, fixed typo in comments --- src/script/script.cpp | 6 +++--- src/script/script.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index d55c4d1..ca3f4e1 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1393,7 +1393,7 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception) if ( err == ERR_STOP ) err = ERR_OK; result->SetValInt(err); // indicates the error or ok - if ( ShouldExecutionStop(err, script->m_errMode) ) + if ( ShouldProcessStop(err, script->m_errMode) ) { exception = err; return false; @@ -1407,9 +1407,9 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception) } -// Returns true if error code means rela error and exception must be thrown +// Returns true if error code means real error and exception must be thrown -bool CScript::ShouldExecutionStop(Error err, int errMode) +bool CScript::ShouldProcessStop(Error err, int errMode) { // aim impossible - not a real error if (err == ERR_AIM_IMPOSSIBLE) diff --git a/src/script/script.h b/src/script/script.h index 694228a..fb44342 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -211,7 +211,7 @@ public: private: static bool Process(CScript* script, CBotVar* result, int &exception); - static bool ShouldExecutionStop(Error err, int errMode); + static bool ShouldProcessStop(Error err, int errMode); static CObject* SearchInfo(CScript* script, CObject* object, float power); protected: -- cgit v1.2.3-1-g7c22 From a2a4eb75cb196b10c4af243f13e49563d59b321c Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Fri, 21 Mar 2014 13:22:02 +0200 Subject: Whitespace --- src/script/script.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index ca3f4e1..dd6b942 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1412,10 +1412,10 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception) bool CScript::ShouldProcessStop(Error err, int errMode) { // aim impossible - not a real error - if (err == ERR_AIM_IMPOSSIBLE) + if ( err == ERR_AIM_IMPOSSIBLE ) return false; - if (err != ERR_OK && errMode == ERM_STOP) + if ( err != ERR_OK && errMode == ERM_STOP ) return true; return false; @@ -2969,7 +2969,7 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) var = var->GetNext(); var == 0 ? y=0.0f : y=var->GetValFloat(); err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f); - if (err == ERR_AIM_IMPOSSIBLE) + if ( err == ERR_AIM_IMPOSSIBLE ) { result->SetValInt(err); // shows the error } -- cgit v1.2.3-1-g7c22 From a181ba9bbf319447db83eea6ce243a08425bb4f4 Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov Date: Tue, 25 Mar 2014 22:56:40 +0200 Subject: Fixes #271 --- src/graphics/engine/text.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 581ff01..d0c9cc8 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -646,7 +646,13 @@ void CText::DrawString(const std::string &text, std::vector::itera DrawCharAndAdjustPos(ch, font, size, pos, color); - fmtIndex++; + // increment fmtIndex for each byte in multibyte character + if ( ch.c1 != 0 ) + fmtIndex++; + if ( ch.c2 != 0 ) + fmtIndex++; + if ( ch.c3 != 0 ) + fmtIndex++; } if (eol != 0) -- cgit v1.2.3-1-g7c22 From c93f91b1ba0b3052337de3740cd4bc9c5b4bc095 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 2 Apr 2014 22:27:57 +0200 Subject: Updated INSTALL file --- INSTALL.md | 13 ++++++++++++- data | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 0ff56f1..81037c5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -117,12 +117,23 @@ You will need: * OpenAL (OpenAL-Soft) >= 1.13 * po4a >= 0.45 (to generate translated data files) +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 +``` + Make sure you install the packages along with header files (often distributed in separate *-dev packages). If you miss any requirements, CMake should warn you. -To compile colobot, run your favorite shell and change the directory to where you downloaded colobot source files: +To compile colobot, run your favorite shell and download colobot source files: ``` + $ git clone https://github.com/colobot/colobot.git /path/to/colobot/sources $ cd /path/to/colobot/sources + $ git submodule update --init +``` +If you want to compile development branch, change the first command to: +``` + $ git clone -b dev https://github.com/colobot/colobot.git /path/to/colobot/sources ``` It is recommended that you create a build directory: ``` diff --git a/data b/data index 8c148a8..b4aee6e 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 8c148a8d5dd57e3662b3422d7c50b55ce518b22e +Subproject commit b4aee6e68407ba92dbd1b4985511b2b0f1c76854 -- cgit v1.2.3-1-g7c22 From bfa226d64e8bbfb2617974abf19c6fc67a951884 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Apr 2014 14:51:13 +0200 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index b4aee6e..fc8f515 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit b4aee6e68407ba92dbd1b4985511b2b0f1c76854 +Subproject commit fc8f515b615235a236641700cc3fcde403548b4f -- cgit v1.2.3-1-g7c22 From f71658e38dbcfc5635a6b2a9c6c4168582728bb5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Apr 2014 21:50:26 +0200 Subject: Random relief generator --- src/graphics/engine/terrain.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ src/graphics/engine/terrain.h | 4 ++- src/object/robotmain.cpp | 6 +++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 4b5384e..e6ca824 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -331,6 +331,66 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, return true; } +bool CTerrain::RandomizeRelief() +{ + // Perlin noise + // Based on Python implementation by Marek Rogalski (mafik) + // http://amt2014.pl/archiwum/perlin.py + + int size = (m_mosaicCount*m_brickCount)+1; + const int ilosc_oktaw = 6; + + float* oktawy[ilosc_oktaw]; + for(int i=0; i(pow(2, (i+1)*2)); + oktawy[i] = new float[pxCount]; + for(int j=0; j(y2) / size; + for(int x2=0; x2 < size; x2++) + { + float x = static_cast(x2) / size; + + float wart = 0; + for(int i=0; i(pow(2, (i+1)*2))); + double xi, yi, a, b; + a = modf(x * (rozmiar_oktawy-1), &xi); + b = modf(y * (rozmiar_oktawy-1), &yi); + /*int xi = floor(x * (rozmiar_oktawy-1)); + int yi = floor(y * (rozmiar_oktawy-1)); + float a = (x * (rozmiar_oktawy-1)) - xi; + float b = (y * (rozmiar_oktawy-1)) - yi;*/ + //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", xi, yi, a, b); + + float lg = oktawy[i][static_cast(yi * rozmiar_oktawy + xi)]; + float pg = oktawy[i][static_cast(yi * rozmiar_oktawy + xi + 1)]; + float ld = oktawy[i][static_cast((yi+1) * rozmiar_oktawy + xi)]; + float pd = oktawy[i][static_cast((yi+1) * rozmiar_oktawy + xi + 1)]; + //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", lg, pg, ld, pd); + + float g = pg * a + lg * (1-a); + float d = pd * a + ld * (1-a); + float res = d * b + g * (1-b); + wart += res; + } + + wart /= ilosc_oktaw; + + m_relief[x2+y2*size] = wart * 255.0f; + } + } + return true; +} + bool CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index e618691..75a8975 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -212,7 +212,7 @@ struct FlyingLimit * where relief data is specifically adjusted to level space to allow * construction of buildings. * - * Undergound resources can be supplied by loading them from image like relief data. + * Underground resources can be supplied by loading them from image like relief data. * * Terrain also specifies flying limits for player: one global level and possible * additional spherical restrictions. @@ -243,6 +243,8 @@ public: void FlushRelief(); //! Load relief from image bool LoadRelief(const std::string& fileName, float scaleRelief, bool adjustBorder); + //! Load ramdomized relief + bool RandomizeRelief(); //! Load resources from image bool LoadResources(const std::string& fileName); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 011cab8..256c362 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -4377,6 +4377,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1)); continue; } + + if (Cmd(line, "TerrainRandomRelief") && !resetObject) + { + m_terrain->RandomizeRelief(); + continue; + } if (Cmd(line, "TerrainResource") && !resetObject) { -- cgit v1.2.3-1-g7c22 From f0d97bfdb91a2c0a17d1697b145d4df930280dbb Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 18 May 2014 12:12:47 +0200 Subject: Better datadir mod support --- data | 2 +- src/CMakeLists.txt | 3 +- src/app/app.cpp | 114 +++++--------------------------- src/app/app.h | 22 ++----- src/app/gamedata.cpp | 123 +++++++++++++++++++++++++++++++++++ src/app/gamedata.h | 66 +++++++++++++++++++ src/common/global.h | 19 ------ src/graphics/engine/engine.cpp | 34 ++-------- src/graphics/engine/modelmanager.cpp | 20 +++++- src/graphics/engine/modelmanager.h | 17 +++++ src/graphics/engine/terrain.cpp | 5 +- src/graphics/engine/text.cpp | 3 +- src/object/robotmain.cpp | 11 ++-- src/script/script.cpp | 7 +- src/sound/oalsound/alsound.cpp | 15 ++--- src/sound/sound.cpp | 7 +- src/sound/sound.h | 7 +- src/ui/edit.cpp | 3 +- src/ui/maindialog.cpp | 3 +- 19 files changed, 287 insertions(+), 194 deletions(-) create mode 100644 src/app/gamedata.cpp create mode 100644 src/app/gamedata.h diff --git a/data b/data index fc8f515..3aa2028 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit fc8f515b615235a236641700cc3fcde403548b4f +Subproject commit 3aa20285393ba9be6b5db7bc4559f2c90f2155bf diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d6b14c..12171f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,11 +61,12 @@ 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 -app/pausemanager.cpp common/event.cpp common/image.cpp common/iman.cpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 51f1e42..549317a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -19,6 +19,7 @@ #include "app/app.h" +#include "app/gamedata.h" #include "app/system.h" #include "common/logger.h" @@ -100,6 +101,7 @@ CApplication::CApplication() m_objMan = new CObjectManager(); m_eventQueue = new CEventQueue(); m_profile = new CProfile(); + m_gameData = new CGameData(); m_engine = nullptr; m_device = nullptr; @@ -149,7 +151,6 @@ CApplication::CApplication() m_dataPath = GetSystemUtils()->GetDataPath(); m_langPath = GetSystemUtils()->GetLangPath(); - m_texPackPath = ""; m_runSceneName = ""; m_runSceneRank = 0; @@ -161,19 +162,6 @@ CApplication::CApplication() m_lowCPU = true; m_protoMode = false; - - for (int i = 0; i < DIR_MAX; ++i) - m_standardDataDirs[i] = nullptr; - - m_standardDataDirs[DIR_AI] = "ai"; - m_standardDataDirs[DIR_FONT] = "fonts"; - m_standardDataDirs[DIR_HELP] = "help"; - m_standardDataDirs[DIR_ICON] = "icons"; - m_standardDataDirs[DIR_LEVEL] = "levels"; - m_standardDataDirs[DIR_MODEL] = "models"; - m_standardDataDirs[DIR_MUSIC] = "music"; - m_standardDataDirs[DIR_SOUND] = "sounds"; - m_standardDataDirs[DIR_TEXTURE] = "textures"; } CApplication::~CApplication() @@ -231,8 +219,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_LOGLEVEL, OPT_LANGUAGE, OPT_DATADIR, + OPT_MOD, OPT_LANGDIR, - OPT_TEXPACK, OPT_VBO }; @@ -245,9 +233,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, { "datadir", required_argument, nullptr, OPT_DATADIR }, - { "game", required_argument, nullptr, OPT_DATADIR }, + { "mod", required_argument, nullptr, OPT_MOD }, { "langdir", required_argument, nullptr, OPT_LANGDIR }, - { "texpack", required_argument, nullptr, OPT_TEXPACK }, { "vbo", required_argument, nullptr, OPT_VBO }, { nullptr, 0, nullptr, 0} }; @@ -286,9 +273,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); - GetLogger()->Message(" -game modid run mod\n"); + GetLogger()->Message(" -mod path run mod\n"); GetLogger()->Message(" -langdir path set custom language directory path\n"); - GetLogger()->Message(" -texpack path set path to custom texture pack\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); return PARSE_ARGS_HELP; } @@ -355,19 +341,19 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { m_dataPath = optarg; m_customDataPath = true; - GetLogger()->Info("Using custom datadir or running mod: '%s'\n", m_dataPath.c_str()); + GetLogger()->Info("Using datadir: '%s'\n", optarg); break; } - case OPT_LANGDIR: + case OPT_MOD: { - m_langPath = optarg; - GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str()); + m_gameData->AddMod(std::string(optarg)); + GetLogger()->Info("Running mod from path: '%s'\n", optarg); break; } - case OPT_TEXPACK: + case OPT_LANGDIR: { - m_texPackPath = optarg; - GetLogger()->Info("Using texturepack: '%s'\n", m_texPackPath.c_str()); + m_langPath = optarg; + GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str()); break; } case OPT_VBO: @@ -424,6 +410,9 @@ bool CApplication::Create() m_exitCode = 1; return false; } + + m_gameData->SetDataDir(std::string(m_dataPath)); + m_gameData->Init(); if (GetProfile().GetLocalProfileString("Language", "Lang", path)) { Language language; @@ -446,24 +435,8 @@ bool CApplication::Create() #endif m_sound->Create(); - - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Sound", path)) - { - m_sound->CacheAll(path); - } - else - { - m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); - } - - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Music", path)) - { - m_sound->AddMusicFiles(path); - } - else - { - m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC)); - } + m_sound->CacheAll(); + m_sound->AddMusicFiles(); GetLogger()->Info("CApplication created successfully\n"); @@ -1606,59 +1579,6 @@ bool CApplication::GetJoystickEnabled() const return m_joystickEnabled; } -std::string CApplication::GetDataDirPath() const -{ - return m_dataPath; -} - -std::string CApplication::GetDataSubdirPath(DataDir stdDir) const -{ - int index = static_cast(stdDir); - assert(index >= 0 && index < DIR_MAX); - std::stringstream str; - str << m_dataPath; - str << "/"; - str << m_standardDataDirs[index]; - return str.str(); -} - -std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath) const -{ - int index = static_cast(stdDir); - assert(index >= 0 && index < DIR_MAX); - std::stringstream str; - str << m_dataPath; - str << "/"; - str << m_standardDataDirs[index]; - if (stdDir == DIR_HELP) - { - str << "/"; - str << GetLanguageChar(); - } - str << "/"; - str << subpath; - return str.str(); -} - -std::string CApplication::GetTexPackFilePath(const std::string& textureName) const -{ - std::stringstream str; - - if (! m_texPackPath.empty()) - { - str << m_texPackPath; - str << "/"; - str << textureName; - if (! boost::filesystem::exists(str.str())) - { - GetLogger()->Trace("Texture '%s' not in texpack\n", textureName.c_str()); - str.str(""); - } - } - - return str.str(); -} - Language CApplication::GetLanguage() const { return m_language; diff --git a/src/app/app.h b/src/app/app.h index 3d61081..86a757f 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -42,6 +42,7 @@ class CInstanceManager; class CEventQueue; class CRobotMain; class CSoundInterface; +class CGameData; namespace Gfx { class CModelManager; @@ -328,18 +329,6 @@ public: static bool ParseDebugModes(const std::string& str, int& debugModes); //@} - //! Returns the full path to data directory - std::string GetDataDirPath() const; - - //! Returns the full path to a standard dir in data directory - std::string GetDataSubdirPath(DataDir stdDir) const; - - //! Returns the full path to a file in data directory given standard dir and subpath - std::string GetDataFilePath(DataDir stdDir, const std::string &subpath) const; - - //! Returns the full path to a file in texture pack directory - std::string GetTexPackFilePath(const std::string& textureName) const; - //! Management of language //@{ Language GetLanguage() const; @@ -413,6 +402,8 @@ protected: CRobotMain* m_robotMain; //! Profile (INI) reader/writer CProfile* m_profile; + //! Game data + CGameData* m_gameData; //! Code to return at exit int m_exitCode; @@ -485,10 +476,7 @@ protected: //! Path to directory with language files std::string m_langPath; - - //! Path to directory with user texture pack - std::string m_texPackPath; - + //@{ //! Scene to run on startup std::string m_runSceneName; @@ -498,8 +486,6 @@ protected: //! Scene test mode bool m_sceneTest; - const char* m_standardDataDirs[DIR_MAX]; - //! Application language Language m_language; diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp new file mode 100644 index 0000000..1bf3f36 --- /dev/null +++ b/src/app/gamedata.cpp @@ -0,0 +1,123 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2014, Polish Portal of Colobot (PPC) +// * +// * 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/. + +#include "app/gamedata.h" + + +#include "app/app.h" + +#include + +template<> CGameData* CSingleton::m_instance = nullptr; + +CGameData::CGameData() +{ + m_dataDirSet = false; + + for (int i = 0; i < DIR_MAX; ++i) + m_standardDataDirs[i] = nullptr; + + m_standardDataDirs[DIR_AI] = "ai"; + m_standardDataDirs[DIR_FONT] = "fonts"; + m_standardDataDirs[DIR_HELP] = "help"; + m_standardDataDirs[DIR_ICON] = "icons"; + m_standardDataDirs[DIR_LEVEL] = "levels"; + m_standardDataDirs[DIR_MODEL] = "models"; + m_standardDataDirs[DIR_MUSIC] = "music"; + m_standardDataDirs[DIR_SOUND] = "sounds"; + m_standardDataDirs[DIR_TEXTURE] = "textures"; +} + +CGameData::~CGameData() +{ +} + +void CGameData::SetDataDir(std::string path) +{ + assert(!m_dataDirSet); + m_dataDirSet = true; + + m_dataDirs.insert(m_dataDirs.begin(), path); +} + +void CGameData::AddMod(std::string path) +{ + m_dataDirs.push_back(path); +} + +void CGameData::Init() +{ + std::string out = "Using datadirs: "; + bool first = true; + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + if(!first) out += ", "; + first = false; + out += *rit; + } + out += "\n"; + CLogger::GetInstancePointer()->Info(out.c_str()); +} + +std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) +{ + int index = static_cast(dir); + assert(index >= 0 && index < DIR_MAX); + + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + std::stringstream str; + str << *rit; + str << "/"; + str << m_standardDataDirs[index]; + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } + str << "/"; + str << subpath; + boost::filesystem::path path(str.str()); + if(boost::filesystem::exists(path)) + { + return str.str(); + } + } + + std::stringstream str; + str << m_dataDirs[0]; + str << "/"; + str << m_standardDataDirs[index]; + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } + str << "/"; + str << subpath; + return str.str(); +} + +std::string CGameData::GetDataPath(const std::string &subpath) +{ + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + std::string path = *rit + "/" + subpath; + boost::filesystem::path boostPath(path); + if(boost::filesystem::exists(boostPath)) + { + return path; + } + } + return m_dataDirs[0] + "/" + subpath; +} diff --git a/src/app/gamedata.h b/src/app/gamedata.h new file mode 100644 index 0000000..b7536a2 --- /dev/null +++ b/src/app/gamedata.h @@ -0,0 +1,66 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2014, Polish Portal of Colobot (PPC) +// * +// * 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/. + +/** + * \file app/gamedata.h + * \brief Game data + */ + +#pragma once + +#include "common/singleton.h" + +#include +#include + +/** + * \enum DataDir + * \brief Directories in data directory + */ +enum DataDir +{ + DIR_AI, //! < ai scripts + DIR_FONT, //! < fonts + DIR_HELP, //! < help files + DIR_ICON, //! < icons & images + DIR_LEVEL, //! < levels + DIR_MODEL, //! < models + DIR_MUSIC, //! < music + DIR_SOUND, //! < sounds + DIR_TEXTURE, //! < textures + + DIR_MAX //! < number of dirs +}; + +class CGameData : public CSingleton +{ +public: + CGameData(); + ~CGameData(); + + void Init(); + void SetDataDir(std::string path); + void AddMod(std::string path); + + std::string GetFilePath(DataDir dir, const std::string &subpath); + std::string GetDataPath(const std::string &subpath); + +private: + bool m_dataDirSet; + std::vector m_dataDirs; + const char* m_standardDataDirs[DIR_MAX]; +}; + diff --git a/src/common/global.h b/src/common/global.h index 79206af..4049bdc 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -178,25 +178,6 @@ enum Language LANGUAGE_RUSSIAN = 4 }; -/** - * \enum DataDir - * \brief Directories in data directory - */ -enum DataDir -{ - DIR_AI, //! < ai scripts - DIR_FONT, //! < fonts - DIR_HELP, //! < help files - DIR_ICON, //! < icons & images - DIR_LEVEL, //! < levels - DIR_MODEL, //! < models - DIR_MUSIC, //! < music - DIR_SOUND, //! < sounds - DIR_TEXTURE, //! < textures - - DIR_MAX //! < number of dirs -}; - /** * \enum BuildType diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 0ee7715..d6e4415 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/engine.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -2246,33 +2247,12 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - bool loadedFromTexPack = false; - - std::string texPackName = m_app->GetTexPackFilePath(texName); - if (! texPackName.empty()) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { - if (img.Load(texPackName)) - { - loadedFromTexPack = true; - } - else - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s' from texpack: %s, blacklisting the texpack path\n", - texName.c_str(), error.c_str()); - m_texBlacklist.insert(texPackName); - } - } - - if (!loadedFromTexPack) - { - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); - m_texBlacklist.insert(texName); - return Texture(); // invalid texture - } + std::string error = img.GetError(); + GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + m_texBlacklist.insert(texName); + return Texture(); // invalid texture } image = &img; @@ -2435,7 +2415,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index abc8c6c..0c0fb98 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -1,6 +1,24 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * 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/. + #include "graphics/engine/modelmanager.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/logger.h" @@ -30,7 +48,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); + std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) { diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 9d50b97..ee5fc27 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -1,3 +1,20 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * 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/. + #pragma once #include "common/singleton.h" diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index e6ca824..5f37cd8 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/terrain.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -189,7 +190,7 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); @@ -286,7 +287,7 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index d0c9cc8..8fd01b7 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/text.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -865,7 +866,7 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_FONT, mf->fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); m_lastCachedFont = new CachedFont(); m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 256c362..2424938 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -20,6 +20,7 @@ #include "CBot/CBotDll.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/event.h" #include "common/global.h" @@ -4081,7 +4082,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Instructions") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str()); m_immediatSatCom = OpInt(line, "immediat", 0); @@ -4093,7 +4094,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Satellite") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SAT], path.c_str()); continue; } @@ -4101,7 +4102,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Loading") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_LOADING], path.c_str()); continue; } @@ -4109,14 +4110,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "HelpFile") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_PROG], path.c_str()); continue; } if (Cmd(line, "SoluceFile") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str()); continue; } diff --git a/src/script/script.cpp b/src/script/script.cpp index dd6b942..f97ed08 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -18,6 +18,7 @@ #include "script/script.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/global.h" #include "common/iman.h" @@ -4406,7 +4407,7 @@ void CScript::New(Ui::CEdit* edit, const char* name) sf = m_main->GetScriptFile(); if ( sf[0] != 0 ) // Load an empty program specific? { - std::string filename = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, sf); + std::string filename = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, sf); file = fopen(filename.c_str(), "rb"); if ( file != NULL ) { @@ -4500,7 +4501,7 @@ bool CScript::ReadScript(const char* filename) if ( strchr(filename, '/') == 0 ) //we're reading non user script { - name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); + name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); } else { @@ -4534,7 +4535,7 @@ bool CScript::WriteScript(const char* filename) if ( strchr(filename, '/') == 0 ) //we're writing non user script { - name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); + name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); } else { diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 23476d4..8afbdd2 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -18,6 +18,8 @@ #include "sound/oalsound/alsound.h" +#include "app/gamedata.h" + #include #include @@ -163,7 +165,7 @@ int ALSound::GetMusicVolume() bool ALSound::Cache(Sound sound, const std::string &filename) { Buffer *buffer = new Buffer(); - if (buffer->LoadFromFile(filename, sound)) + if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_SOUND, filename), sound)) { m_sounds[sound] = buffer; return true; @@ -176,9 +178,7 @@ bool ALSound::CacheMusic(const std::string &filename) if (m_music.find(filename) == m_music.end()) { Buffer *buffer = new Buffer(); - std::stringstream file; - file << m_soundPath << "/" << filename; - if (buffer->LoadFromFile(file.str(), static_cast(-1))) + if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename), static_cast(-1))) { m_music[filename] = buffer; return true; @@ -635,22 +635,21 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return false; } - std::stringstream file; - file << m_soundPath << "/" << filename; + std::string file = CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename); Buffer *buffer; // check if we have music in cache if (m_music.find(filename) == m_music.end()) { GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); - if (!boost::filesystem::exists(file.str())) + if (!boost::filesystem::exists(file)) { GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); return false; } buffer = new Buffer(); - if (!buffer->LoadFromFile(file.str(), static_cast(-1))) + if (!buffer->LoadFromFile(file, static_cast(-1))) { return false; } diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index c4b30b5..9cae1fd 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -41,20 +41,19 @@ bool CSoundInterface::Create() return true; } -void CSoundInterface::CacheAll(const std::string &path) +void CSoundInterface::CacheAll() { for ( int i = 1; i < SOUND_MAX; i++ ) { std::stringstream filename; - filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav"; + filename << "sound" << std::setfill('0') << std::setw(3) << i << ".wav"; if ( !Cache(static_cast(i), filename.str()) ) GetLogger()->Warn("Unable to load audio: %s\n", filename.str().c_str()); } } -void CSoundInterface::AddMusicFiles(const std::string &path) +void CSoundInterface::AddMusicFiles() { - m_soundPath = path; CacheMusic("Intro1.ogg"); CacheMusic("Intro2.ogg"); CacheMusic("music010.ogg"); diff --git a/src/sound/sound.h b/src/sound/sound.h index e86da2b..22a5ee2 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -159,10 +159,10 @@ public: /** Function called to cache all sound effect files. * Function calls \link CSoundInterface::Cache() \endlink for each file */ - void CacheAll(const std::string &path); + void CacheAll(); /** Function called to add all music files to list */ - void AddMusicFiles(const std::string &path); + void AddMusicFiles(); /** Function called to cache sound effect file. * This function is called by plugin interface for each file. @@ -327,8 +327,5 @@ public: * \return nothing */ virtual void StopPauseMusic(); - -protected: - std::string m_soundPath; }; diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index ff06161..6602651 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -19,6 +19,7 @@ #include "ui/edit.h" #include "app/app.h" +#include "app/gamedata.h" #include "clipboard/clipboard.h" @@ -1462,7 +1463,7 @@ bool CEdit::ReadText(std::string filename, int addSize) std::string path = filename; if (!fs::exists(path)) { - path = CApplication::GetInstancePointer()->GetDataDirPath() + "/" + filename; + path = CGameData::GetInstancePointer()->GetDataPath(filename); } file = fopen(fs::path(path).make_preferred().string().c_str(), "rb"); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index b954c71..1964531 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -18,6 +18,7 @@ #include "ui/maindialog.h" #include "app/app.h" +#include "app/gamedata.h" #include "app/system.h" #include "common/config.h" @@ -3588,7 +3589,7 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { rankStream << std::setfill('0') << std::setw(3) << rank; filename = base + rankStream.str() + ".txt"; - filename = CApplication::GetInstance().GetDataFilePath(DIR_LEVEL, filename); + filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename); } } -- cgit v1.2.3-1-g7c22 From ba62e6f8be5f7008939677ce70799ecc26adf420 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 1 Jun 2014 13:02:08 +0200 Subject: Remove dead code --- src/app/app.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 549317a..1efabb5 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -200,12 +200,6 @@ CEventQueue* CApplication::GetEventQueue() CSoundInterface* CApplication::GetSound() { return m_sound; - - for (int i = 0; i < PCNT_MAX; ++i) - { - GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][0]); - GetSystemUtils()->DestroyTimeStamp(m_performanceCounters[i][1]); - } } ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) -- cgit v1.2.3-1-g7c22 From 99cd015dd89f0928246d1178c5641ebe325fe997 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 19 Jun 2014 21:54:31 +0200 Subject: Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 3aa2028..8d83ede 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 3aa20285393ba9be6b5db7bc4559f2c90f2155bf +Subproject commit 8d83edee8e2a860cb1be526f73c6a17023a2248b -- cgit v1.2.3-1-g7c22 From 613e1d74c47cf3a756af9aff75575c7567699381 Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 01:35:05 +0300 Subject: implemented savefile screenshot feature --- src/common/image.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/common/image.h | 6 ++++++ src/graphics/core/device.h | 3 +++ src/graphics/engine/engine.cpp | 17 ++++++++++++++--- src/graphics/opengl/gldevice.cpp | 17 +++++++++++++++++ src/graphics/opengl/gldevice.h | 2 ++ src/ui/maindialog.cpp | 7 ++++--- 7 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/common/image.cpp b/src/common/image.cpp index 8a876e3..ff5e42c 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -418,3 +418,43 @@ bool CImage::SavePNG(const std::string& fileName) return true; } +void CImage::SetDataPixels(void *pixels){ + + if (m_data != nullptr){ + + if (m_data->surface != nullptr) + { + if ( m_data->surface->pixels != nullptr ){ + unsigned int* pixels = static_cast(m_data->surface->pixels); + delete [] pixels; + m_data->surface->pixels = nullptr; + } + } + } + + m_data->surface->pixels = pixels; +} + +void CImage::flipVertical(){ + + SDL_Surface* result = SDL_CreateRGBSurface(m_data->surface->flags, m_data->surface->w, m_data->surface->h, + m_data->surface->format->BytesPerPixel * 8, m_data->surface->format->Rmask, m_data->surface->format->Gmask, + m_data->surface->format->Bmask, m_data->surface->format->Amask); + + assert(result != nullptr); + + Uint8* srcPixels = static_cast (m_data->surface->pixels); + Uint8* resultPixels = static_cast (result->pixels); + + Uint32 pitch = m_data->surface->pitch; + Uint32 pxLength = pitch*m_data->surface->h; + + for(int line = 0; line < m_data->surface->h; ++line) { + Uint32 pos = line * pitch; + memcpy(&resultPixels[pos], &srcPixels[(pxLength-pos)-pitch], pitch); + } + + SDL_FreeSurface(m_data->surface); + + m_data->surface = result; +} \ No newline at end of file diff --git a/src/common/image.h b/src/common/image.h index 31dab2d..afbebc2 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -109,6 +109,12 @@ public: //! Returns the last error std::string GetError(); + //! Flips the image vertically + void flipVertical(); + + //! sets/replaces the pixels from the surface + void SetDataPixels(void *pixels); + private: //! Blit to new RGBA surface with given size void BlitToNewRGBASurface(int width, int height); diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 4c1189c..a896104 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -400,6 +400,9 @@ public: 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; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d6e4415..9216fb0 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -424,9 +424,20 @@ void CEngine::FrameUpdate() bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height) { - // TODO write screenshot: not very important for now - GetLogger()->Debug("CEngine::WriteSceenShot(): stub!\n"); - return true; + void *pixels = m_device->GetFrameBufferPixels(); + CImage img({width,height}); + + img.SetDataPixels(pixels); + img.flipVertical(); + + if ( img.SavePNG(fileName.c_str()) ){ + GetLogger()->Info("Save SceenShot Saved Successfully!\n"); + return true; + } + else{ + GetLogger()->Error("%s!\n",img.GetError().c_str()); + return false; + } } bool CEngine::GetPause() diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 9f64fab..57738a6 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1791,6 +1791,23 @@ FillMode CGLDevice::GetFillMode() return FILL_POINT; } +void* CGLDevice::GetFrameBufferPixels()const{ + + SDL_Surface* surface = SDL_GetVideoSurface(); + + assert(surface != nullptr); + + GLubyte* pixels = new GLubyte [4 * surface->h * surface->w]; + + glReadPixels(0,0,surface->w,surface->h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + + unsigned int* p = static_cast ( static_cast(pixels) ); + + for (int i = 0; i < surface->h * surface->w; ++i) + p[i] |= 0xFF000000; + + return static_cast(p); +} } // namespace Gfx diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index c648161..267ee73 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -188,6 +188,8 @@ public: virtual void SetFillMode(FillMode mode) ; virtual FillMode GetFillMode(); + virtual void* GetFrameBufferPixels()const; + private: //! Updates internal modelview matrix void UpdateModelviewMatrix(); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 1964531..784cd59 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -2075,9 +2075,10 @@ bool CMainDialog::EventProcess(const Event &event) { m_shotDelay --; if ( m_shotDelay == 0 ) - { - m_engine->WriteScreenShot(m_shotName, 320, 240); - //? m_engine->WriteScreenShot(m_shotName, 160, 120); + { + Math::IntPoint screenSize = m_app->GetVideoConfig().size; + + m_engine->WriteScreenShot(m_shotName, screenSize.x, screenSize.y); } } -- cgit v1.2.3-1-g7c22 From 52cf9e2815688481f689e03e67c5fc983ed1351b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 24 Jun 2014 17:38:28 +0200 Subject: Fix test compilation --- test/envs/opengl/light_test.cpp | 4 ++-- test/envs/opengl/transform_test.cpp | 4 ++-- test/unit/CMakeLists.txt | 1 + test/unit/ui/CMakeLists.txt | 1 + test/unit/ui/stubs/app_stub.cpp | 10 ---------- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index 227ca2a..1a52084 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -78,7 +78,7 @@ void Render(Gfx::CGLDevice *device) worldMat.LoadIdentity(); device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - Gfx::VertexCol line[2] = { Gfx::VertexCol() }; + Gfx::VertexCol line[2] = Gfx::VertexCol{ Gfx::VertexCol() }; for (int x = -40; x <= 40; ++x) { @@ -103,7 +103,7 @@ void Render(Gfx::CGLDevice *device) } - Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; + Gfx::VertexCol quad[6] = Gfx::VertexCol{ Gfx::VertexCol() }; quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index 58d8e9e..d994cc5 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -73,7 +73,7 @@ void Render(Gfx::CGLDevice *device) worldMat.LoadIdentity(); device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - Gfx::VertexCol line[2] = { Gfx::VertexCol() }; + Gfx::VertexCol line[2] = Gfx::VertexCol{ Gfx::VertexCol() }; for (int x = -40; x <= 40; ++x) { @@ -98,7 +98,7 @@ void Render(Gfx::CGLDevice *device) } - Gfx::VertexCol quad[6] = { Gfx::VertexCol() }; + Gfx::VertexCol quad[6] = Gfx::VertexCol{ Gfx::VertexCol() }; for (int i = 0; i < 6; ++i) quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 269ffc2..bdb5a67 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -23,6 +23,7 @@ configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/comm # 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} diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index 503f84b..7f7b2f8 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -17,6 +17,7 @@ else() 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 diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 960972f..95430d8 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -21,11 +21,6 @@ CApplication::~CApplication() { } -std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) const -{ - return subpath; -} - CSoundInterface* CApplication::GetSound() { return nullptr; @@ -36,11 +31,6 @@ CEventQueue* CApplication::GetEventQueue() return nullptr; } -std::string CApplication::GetDataDirPath() const -{ - return ""; -} - Event CApplication::CreateUpdateEvent() { return Event(EVENT_NULL); -- cgit v1.2.3-1-g7c22 From b7125a5b24bc6d2581bec0d3f792ba948e0e7edd Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 20:27:31 +0300 Subject: formatting and enhancements for savefile screenshot feature --- src/common/image.cpp | 33 +++++++++++++++++---------------- src/common/image.h | 2 +- src/graphics/engine/engine.cpp | 2 +- src/graphics/opengl/gldevice.cpp | 10 +++------- src/ui/maindialog.cpp | 4 ++-- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/common/image.cpp b/src/common/image.cpp index ff5e42c..e3d1ef7 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -420,26 +420,27 @@ bool CImage::SavePNG(const std::string& fileName) void CImage::SetDataPixels(void *pixels){ - if (m_data != nullptr){ - - if (m_data->surface != nullptr) - { - if ( m_data->surface->pixels != nullptr ){ - unsigned int* pixels = static_cast(m_data->surface->pixels); - delete [] pixels; - m_data->surface->pixels = nullptr; - } - } + Uint8* srcPixels = static_cast (pixels); + Uint8* resultPixels = static_cast (m_data->surface->pixels); + + Uint32 pitch = m_data->surface->pitch; + + for(int line = 0; line < m_data->surface->h; ++line) { + Uint32 pos = line * pitch; + memcpy(&resultPixels[pos], &srcPixels[pos], pitch); } - - m_data->surface->pixels = pixels; } -void CImage::flipVertical(){ +void CImage::flipVertically(){ - SDL_Surface* result = SDL_CreateRGBSurface(m_data->surface->flags, m_data->surface->w, m_data->surface->h, - m_data->surface->format->BytesPerPixel * 8, m_data->surface->format->Rmask, m_data->surface->format->Gmask, - m_data->surface->format->Bmask, m_data->surface->format->Amask); + SDL_Surface* result = SDL_CreateRGBSurface( m_data->surface->flags, + m_data->surface->w, + m_data->surface->h, + m_data->surface->format->BytesPerPixel * 8, + m_data->surface->format->Rmask, + m_data->surface->format->Gmask, + m_data->surface->format->Bmask, + m_data->surface->format->Amask); assert(result != nullptr); diff --git a/src/common/image.h b/src/common/image.h index afbebc2..b93f2f9 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -110,7 +110,7 @@ public: std::string GetError(); //! Flips the image vertically - void flipVertical(); + void flipVertically(); //! sets/replaces the pixels from the surface void SetDataPixels(void *pixels); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 9216fb0..e0861d2 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -428,7 +428,7 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height CImage img({width,height}); img.SetDataPixels(pixels); - img.flipVertical(); + img.flipVertically(); if ( img.SavePNG(fileName.c_str()) ){ GetLogger()->Info("Save SceenShot Saved Successfully!\n"); diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 57738a6..b42f29d 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1793,17 +1793,13 @@ FillMode CGLDevice::GetFillMode() void* CGLDevice::GetFrameBufferPixels()const{ - SDL_Surface* surface = SDL_GetVideoSurface(); - - assert(surface != nullptr); - - GLubyte* pixels = new GLubyte [4 * surface->h * surface->w]; + GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y]; - glReadPixels(0,0,surface->w,surface->h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + 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) ); - for (int i = 0; i < surface->h * surface->w; ++i) + for (int i = 0; i < m_config.size.x * m_config.size.y; ++i) p[i] |= 0xFF000000; return static_cast(p); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 784cd59..fc5bb30 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -2076,9 +2076,9 @@ bool CMainDialog::EventProcess(const Event &event) m_shotDelay --; if ( m_shotDelay == 0 ) { - Math::IntPoint screenSize = m_app->GetVideoConfig().size; + Math::IntPoint windowSize = m_engine->GetWindowSize(); - m_engine->WriteScreenShot(m_shotName, screenSize.x, screenSize.y); + m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y); } } -- cgit v1.2.3-1-g7c22 From f5ba2a27d4422401317d814c60048121f9804429 Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 20:31:17 +0300 Subject: fixed savefile screenshot loading bug --- src/app/gamedata.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp index 1bf3f36..05c0242 100644 --- a/src/app/gamedata.cpp +++ b/src/app/gamedata.cpp @@ -78,16 +78,22 @@ std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { std::stringstream str; - str << *rit; - str << "/"; - str << m_standardDataDirs[index]; - if (dir == DIR_HELP) - { + + if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot + str << *rit; + str << "/"; + str << m_standardDataDirs[index]; + + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } str << "/"; - str << CApplication::GetInstancePointer()->GetLanguageChar(); } - str << "/"; + str << subpath; + boost::filesystem::path path(str.str()); if(boost::filesystem::exists(path)) { @@ -95,18 +101,9 @@ std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) } } - std::stringstream str; - str << m_dataDirs[0]; - str << "/"; - str << m_standardDataDirs[index]; - if (dir == DIR_HELP) - { - str << "/"; - str << CApplication::GetInstancePointer()->GetLanguageChar(); - } - str << "/"; - str << subpath; - return str.str(); + GetLogger()->Error("file subpath error\n"); + + return ""; } std::string CGameData::GetDataPath(const std::string &subpath) -- cgit v1.2.3-1-g7c22 From 76d01b44f762357dffe91b0e884687bb34fa537d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 24 Jun 2014 19:51:48 +0200 Subject: Fix test compilation --- test/unit/graphics/core/device_mock.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/graphics/core/device_mock.h b/test/unit/graphics/core/device_mock.h index 9e75daf..498239f 100644 --- a/test/unit/graphics/core/device_mock.h +++ b/test/unit/graphics/core/device_mock.h @@ -105,4 +105,6 @@ public: MOCK_METHOD1(SetFillMode, void(Gfx::FillMode mode)); MOCK_METHOD0(GetFillMode, Gfx::FillMode()); + + MOCK_CONST_METHOD0(GetFrameBufferPixels, void*()); }; -- cgit v1.2.3-1-g7c22 From 2b9abf2a4843d7324de50d1b3d52fa9fcb00b185 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 25 Jun 2014 22:49:16 +0200 Subject: Fixed CMake git branch detection with build dir outside of repository working dir --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4405d1..6a348c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,11 @@ if(DEFINED COLOBOT_VERSION_UNRELEASED) if(EXISTS "${CMAKE_SOURCE_DIR}/.git") find_package(Git) execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE GIT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE) set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") -- cgit v1.2.3-1-g7c22 From bc3b7ef283d5a4f84af352f693a50182571909e7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Jun 2014 20:41:18 +0200 Subject: Fixed negative parameter in fire() (issue #305) Also fixed checking parameter count and type for ants, spiders and shooters --- src/script/script.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index f97ed08..2299fbf 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -2862,7 +2862,6 @@ bool CScript::rShield(CBotVar* var, CBotVar* result, int& exception, void* user) CBotTypResult CScript::cFire(CBotVar* &var, void* user) { -#if 0 CObject* pThis = static_cast(user); ObjectType type; @@ -2870,23 +2869,25 @@ CBotTypResult CScript::cFire(CBotVar* &var, void* user) if ( type == OBJECT_ANT ) { - return cOnePoint(var, user); + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + CBotTypResult ret = cPoint(var, user); + if ( ret.GetType() != 0 ) return ret; + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); } else if ( type == OBJECT_SPIDER ) { - return cNull(var, user); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); } else { - if ( var == 0 ) return CBotTypResult(CBotTypFloat); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != 0 ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypFloat); + if ( var != 0 ) + { + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + } } -#else return CBotTypResult(CBotTypFloat); -#endif } // Instruction "fire(delay)". @@ -2922,6 +2923,7 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) { if ( var == 0 ) delay = 0.0f; else delay = var->GetValFloat(); + if ( delay < 0.0f ) delay = -delay; err = script->m_primaryTask->StartTaskFire(delay); } -- cgit v1.2.3-1-g7c22 From fd8ea13cbbe276de899a35f2772a1f05ab79c596 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Jun 2014 21:37:38 +0200 Subject: Fixed not destroying CGameData This also fixed failing assertion in tests --- src/app/app.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/app.cpp b/src/app/app.cpp index 1efabb5..8b310c9 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -180,6 +180,9 @@ CApplication::~CApplication() delete m_iMan; m_iMan = nullptr; + + delete m_gameData; + m_gameData = nullptr; GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp); GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp); -- cgit v1.2.3-1-g7c22 From 092e7cc68de3d4e46505a2931ce266b4e5aabaab Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 26 Jun 2014 22:14:30 +0200 Subject: Fixed tests --- src/app/gamedata.cpp | 20 ++++++++++++++++++-- test/unit/ui/edit_test.cpp | 20 +++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp index 05c0242..ceeb7b3 100644 --- a/src/app/gamedata.cpp +++ b/src/app/gamedata.cpp @@ -101,9 +101,25 @@ std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) } } - GetLogger()->Error("file subpath error\n"); + if(m_dataDirs.size() > 0) { + std::stringstream str; + if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot + str << m_dataDirs[0]; + str << "/"; + str << m_standardDataDirs[index]; + + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } + str << "/"; + } + str << subpath; + return str.str(); + } - return ""; + return subpath; } std::string CGameData::GetDataPath(const std::string &subpath) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index 4a4063e..34af013 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -1,4 +1,5 @@ #include "app/app.h" +#include "app/gamedata.h" #include "ui/edit.h" @@ -14,6 +15,7 @@ class CEditTest : public testing::Test public: CEditTest() : m_robotMain(nullptr) + , m_gameData(nullptr) , m_engine(nullptr) , m_edit(nullptr) {} @@ -21,21 +23,24 @@ public: 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_robotMain; - m_robotMain = nullptr; - delete m_engine; - m_engine = nullptr; 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() { @@ -45,6 +50,7 @@ public: protected: CApplication m_app; CRobotMain* m_robotMain; + CGameData * m_gameData; Gfx::CEngine * m_engine; Ui::CEdit * m_edit; CLogger m_logger; -- cgit v1.2.3-1-g7c22 From 0fbc05b96ca9b464b273d64349d9a7940a0c992b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 26 Jun 2014 22:36:57 +0200 Subject: Fix test compilation --- src/graphics/core/vertex.h | 4 +++- test/envs/opengl/light_test.cpp | 4 ++-- test/envs/opengl/transform_test.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index c3a657a..ca68352 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -82,7 +82,9 @@ struct VertexCol Math::Vector coord; Color color; - explicit VertexCol(Math::Vector aCoord = Math::Vector(), + VertexCol() = default; + + explicit VertexCol(Math::Vector aCoord, Color aColor = Color()) : coord(aCoord), color(aColor) {} diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index 1a52084..5c5af7c 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -78,7 +78,7 @@ void Render(Gfx::CGLDevice *device) worldMat.LoadIdentity(); device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - Gfx::VertexCol line[2] = Gfx::VertexCol{ Gfx::VertexCol() }; + Gfx::VertexCol line[2] = {}; for (int x = -40; x <= 40; ++x) { @@ -103,7 +103,7 @@ void Render(Gfx::CGLDevice *device) } - Gfx::VertexCol quad[6] = Gfx::VertexCol{ Gfx::VertexCol() }; + Gfx::VertexCol quad[6] = {}; quad[0].coord = Math::Vector(-1.0f, -1.0f, 0.0f); quad[1].coord = Math::Vector( 1.0f, -1.0f, 0.0f); diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index d994cc5..99ec9f0 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -73,7 +73,7 @@ void Render(Gfx::CGLDevice *device) worldMat.LoadIdentity(); device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat); - Gfx::VertexCol line[2] = Gfx::VertexCol{ Gfx::VertexCol() }; + Gfx::VertexCol line[2] = {}; for (int x = -40; x <= 40; ++x) { @@ -98,7 +98,7 @@ void Render(Gfx::CGLDevice *device) } - Gfx::VertexCol quad[6] = Gfx::VertexCol{ Gfx::VertexCol() }; + Gfx::VertexCol quad[6] = {}; for (int i = 0; i < 6; ++i) quad[i].color = Gfx::Color(1.0f, 1.0f, 0.0f); -- cgit v1.2.3-1-g7c22 From 400bcd60fe07ef313f3944dda725020e0f6485da Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Thu, 26 Jun 2014 23:38:15 +0200 Subject: Updated submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 8d83ede..826bc69 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 8d83edee8e2a860cb1be526f73c6a17023a2248b +Subproject commit 826bc69e4b9d31e58d6bc68303ce6a623458ea65 -- cgit v1.2.3-1-g7c22 From 1835d2ae580525603308206f7b8e6b4552b3ca0f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 Jun 2014 19:50:09 +0200 Subject: Removed old code based on #ifs (issue #55) --- src/common/misc.cpp | 18 -- src/graphics/engine/camera.cpp | 3 - src/object/auto/autobase.cpp | 4 - src/object/brain.cpp | 20 --- src/object/robotmain.cpp | 29 ---- src/object/task/taskterraform.cpp | 23 --- src/physics/physics.cpp | 16 +- src/ui/color.cpp | 34 +--- src/ui/control.cpp | 4 - src/ui/displayinfo.cpp | 6 - src/ui/edit.cpp | 4 - src/ui/maindialog.cpp | 357 +------------------------------------- src/ui/studio.cpp | 6 - src/ui/window.cpp | 3 - 14 files changed, 11 insertions(+), 516 deletions(-) diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 65689e6..92c3e9a 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -192,18 +192,6 @@ void TimeToAscii(time_t time, char *buffer) year = when.tm_year+1900; if ( year < 2000 ) year -= 1900; else year -= 2000; -/* TODO -#if _FRENCH - sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d", - when.tm_mday, when.tm_mon+1, year, - when.tm_hour, when.tm_min); -#endif -#if _GERMAN | _WG - sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d", - when.tm_mday, when.tm_mon+1, year, - when.tm_hour, when.tm_min); -#endif -#if _ENGLISH*/ char format[10]; int hour; @@ -222,12 +210,6 @@ void TimeToAscii(time_t time, char *buffer) sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s", when.tm_mon+1, when.tm_mday, year, hour, when.tm_min, format); -/*#endif -#if _POLISH - sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d", - when.tm_mday, when.tm_mon+1, year, - when.tm_hour, when.tm_min); -#endif*/ } // Converting time to string. diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index f0c379c..fedc70a 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -593,9 +593,6 @@ void CCamera::EffectFrame(const Event &event) dist = Math::Norm((dist - 100.f) / 100.0f); force *= 1.0f-dist; -#if _TEEN - force *= 2.0f; -#endif m_effectOffset *= force; if (m_effectProgress >= 1.0f) diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 25320d3..af6c6e0 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -1356,11 +1356,7 @@ void CAutoBase::BeginTransit() } else { -#if _DEMO - m_bgBack = "back46b.png"; // paintings -#else m_bgBack = "back46.png"; // paintings -#endif } m_engine->SetFogStart(0.9f); // hardly any fog diff --git a/src/object/brain.cpp b/src/object/brain.cpp index b27acd1..4bd8742 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1789,9 +1789,6 @@ bool CBrain::CreateInterface(bool bSelect) pos.x = ox+sx*13.4f; pos.y = oy+sy*0; -#if _TEEN - pw->CreateButton(pos, dim, 9, EVENT_OBJECT_RESET); -#else if ( m_object->GetTrainer() ) // Training? { pw->CreateButton(pos, dim, 9, EVENT_OBJECT_RESET); @@ -1800,7 +1797,6 @@ bool CBrain::CreateInterface(bool bSelect) { pw->CreateButton(pos, dim, 10, EVENT_OBJECT_DESELECT); } -#endif if ( type == OBJECT_MOBILEfa || type == OBJECT_MOBILEta || @@ -2459,17 +2455,10 @@ void CBrain::UpdateScript(Ui::CWindow *pw) char name[100]; char title[100]; int i; - bool bSoluce; pl = static_cast< Ui::CList* >(pw->SearchControl(EVENT_OBJECT_PROGLIST)); if ( pl == 0 ) return; -#if _SCHOOL - bSoluce = m_main->GetSoluce4(); -#else - bSoluce = true; -#endif - for ( i=0 ; iGetTitle(title); - if ( !bSoluce && i == 3 ) - { - title[0] = 0; - } if ( title[0] != 0 ) { sprintf(name, "%d: %s", i+1, title); @@ -2490,11 +2475,6 @@ void CBrain::UpdateScript(Ui::CWindow *pw) pl->SetItemName(i, name); } - if ( !bSoluce ) - { - pl->SetEnable(3, false); - } - pl->SetSelect(m_selScript); pl->ShowSelect(true); } diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 2424938..76c234d 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1083,9 +1083,6 @@ void CRobotMain::ChangePhase(Phase phase) m_sound->StopMusic(0.0f); m_camera->SetControllingObject(0); -/* TODO: #if _SCHOOL - if ( true ) -#else*/ if (m_gameTime > 10.0f) // did you play at least 10 seconds? { int rank = m_dialog->GetSceneRank(); @@ -1172,12 +1169,6 @@ void CRobotMain::ChangePhase(Phase phase) m_cmdEdit = false; // hidden for now // Creates the speedometer. -/* TODO: #if _TEEN - dim.x = 30.0f/640.0f; - dim.y = 20.0f/480.0f; - pos.x = 4.0f/640.0f; - pos.y = 454.0f/480.0f; -#else*/ dim.x = 30.0f/640.0f; dim.y = 20.0f/480.0f; pos.x = 4.0f/640.0f; @@ -1249,10 +1240,6 @@ void CRobotMain::ChangePhase(Phase phase) } else { -/* TODO: #if _TEEN - m_winTerminate = (m_endingWinRank == 900); - m_dialog->SetSceneName("teenw"); -#else*/ m_winTerminate = (m_endingWinRank == 904); m_dialog->SetSceneName("win"); @@ -1266,16 +1253,6 @@ void CRobotMain::ChangePhase(Phase phase) if (m_winTerminate) { -/* TODO: #if _TEEN - pos.x = ox+sx*3; pos.y = oy+sy*1; - ddim.x = dim.x*15; ddim.y = dim.y*2; - pe = m_interface->CreateEdit(pos, ddim, 0, EVENT_EDIT0); - pe->SetFontType(FONT_COLOBOT); - pe->SetEditCap(false); - pe->SetHiliteCap(false); - pe->ReadText("help/teenw.txt"); -#else*/ - pos.x = ox+sx*3; pos.y = oy+sy*0.2f; ddim.x = dim.x*15; ddim.y = dim.y*3.0f; pe = m_interface->CreateEdit(pos, ddim, 0, EVENT_EDIT0); @@ -2106,9 +2083,6 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } -/* TODO: #if _TEEN - if (strcmp(cmd, "allteens") == 0) -#else*/ if (strcmp(cmd, "allmission") == 0) { m_showAll = !m_showAll; @@ -4771,9 +4745,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { sprintf(op, "script%d", i+1); // script1..script10 OpString(line, op, name); -/* TODO: #if _SCHOOL - if ( !m_dialog->GetSoluce4() && i == 3 ) continue; -#endif*/ if (name[0] != 0) brain->SetScriptName(i, name); diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index 096e5de..61ff045 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -76,15 +76,9 @@ bool CTaskTerraform::EventProcess(const Event &event) { if ( m_soundChannel == -1 ) { -#if _TEEN - m_soundChannel = m_sound->Play(SOUND_GGG, m_object->GetPosition(0), 1.0f, 0.5f, true); - m_sound->AddEnvelope(m_soundChannel, 1.0f, 2.0f, 1.5f, SOPER_CONTINUE); - m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.5f, SOPER_STOP); -#else m_soundChannel = m_sound->Play(SOUND_GGG, m_object->GetPosition(0), 1.0f, 0.5f, true); m_sound->AddEnvelope(m_soundChannel, 1.0f, 2.0f, 4.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.5f, SOPER_STOP); -#endif } dir.x = 0.0f; @@ -109,11 +103,7 @@ bool CTaskTerraform::EventProcess(const Event &event) if ( m_phase == TTP_DOWN ) { pos.x = 9.0f; -#if _TEEN - pos.y = 4.0f-m_progress*4.0f; -#else pos.y = 4.0f-m_progress*5.8f; -#endif pos.z = 0.0f; m_object->SetPosition(2, pos); } @@ -121,11 +111,7 @@ bool CTaskTerraform::EventProcess(const Event &event) if ( m_phase == TTP_UP ) { pos.x = 9.0f; -#if _TEEN - pos.y = 4.0f-(1.0f-m_progress)*4.0f; -#else pos.y = 4.0f-(1.0f-m_progress)*5.8f; -#endif pos.z = 0.0f; m_object->SetPosition(2, pos); } @@ -230,11 +216,7 @@ Error CTaskTerraform::Start() m_phase = TTP_CHARGE; m_progress = 0.0f; -#if _TEEN - m_speed = 1.0f/1.5f; -#else m_speed = 1.0f/4.0f; -#endif m_time = 0.0f; m_bError = false; // ok @@ -261,9 +243,6 @@ Error CTaskTerraform::IsEnded() if ( m_phase == TTP_CHARGE ) { -#if _TEEN - Terraform(); // changes the terrain. -#endif m_phase = TTP_DOWN; m_speed = 1.0f/0.2f; @@ -272,9 +251,7 @@ Error CTaskTerraform::IsEnded() if ( m_phase == TTP_DOWN ) { -#if !_TEEN Terraform(); // changes the terrain. -#endif m_object->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f)); m_object->SetZoom(0, 1.0f); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index ad59ec0..a3aaa28 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2581,16 +2581,10 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) (oType >= OBJECT_MUSHROOM1 && oType <= OBJECT_MUSHROOM2) ) continue; } -/* TODO: #if _TEEN - if ( oType == OBJECT_WAYPOINT && - pObj->GetEnable() && - !m_object->GetResetBusy() ) // driving vehicle? -#else */ if ( oType == OBJECT_WAYPOINT && pObj->GetEnable() && !m_object->GetResetBusy() && m_object->GetTrainer() ) // driving vehicle? -/* #endif */ { oPos = pObj->GetPosition(0); distance = Math::DistanceProjected(oPos, iPos); @@ -2996,15 +2990,15 @@ void CPhysics::FrameParticle(float aTime, float rTime) { Math::Vector pos; CObject* power; - float energy, intensity; + float energy/*, intensity*/; int effectLight; - bool bFlash; + //bool bFlash; m_restBreakParticle -= rTime; if ( aTime-m_lastPowerParticle < m_engine->ParticleAdapt(0.05f) ) return; m_lastPowerParticle = aTime; - bFlash = false; + //bFlash = false; energy = 0.0f; power = m_object->GetPower(); @@ -3018,7 +3012,7 @@ void CPhysics::FrameParticle(float aTime, float rTime) if ( energy > m_lastEnergy ) // recharge? { PowerParticle(1.0f, false); - bFlash = true; + //bFlash = true; } if ( energy == 0.0f || m_lastEnergy == 0.0f ) @@ -3032,7 +3026,7 @@ void CPhysics::FrameParticle(float aTime, float rTime) if ( m_restBreakParticle > 0.0f ) { PowerParticle(m_restBreakParticle/2.5f, (energy == 0)); - bFlash = true; + //bFlash = true; } effectLight = m_object->GetEffectLight(); diff --git a/src/ui/color.cpp b/src/ui/color.cpp index cbbc0dc..d1dc746 100644 --- a/src/ui/color.cpp +++ b/src/ui/color.cpp @@ -141,38 +141,7 @@ void CColor::Draw() m_engine->SetTexture("button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); CControl::Draw(); - -#if _TEEN -// color = GetColor(m_color); - color = GetColor(); - - m_engine->SetTexture(""); // no texture - m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); - - device = m_engine->GetDevice(); - - p1.x = m_pos.x + (4.0f / 640.0f); - p1.y = m_pos.y + (4.0f / 480.0f); - p2.x = m_pos.x + m_dim.x - (4.0f / 640.0f); - p2.y = m_pos.y + m_dim.y - (4.0f / 480.0f); - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), 0x00000000,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), 0x00000000,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), 0x00000000,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), 0x00000000,0x00000000, Math::Point( 0.0f, 0.0f)); - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); - - p1.x = m_pos.x + (5.0f / 640.0f); - p1.y = m_pos.y + (5.0f / 480.0f); - p2.x = m_pos.x + m_dim.x - (5.0f / 640.0f); - p2.y = m_pos.y + m_dim.y - (5.0f / 480.0f); - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), color,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), color,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), color,0x00000000, Math::Point( 0.0f, 0.0f)); - vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), color,0x00000000, Math::Point( 0.0f, 0.0f)); - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); - - m_engine->AddStatisticTriangle(4); -#else + p1.x = m_pos.x + (3.0f / 640.0f); p1.y = m_pos.y + (3.0f / 480.0f); p2.x = m_pos.x + m_dim.x - (3.0f / 640.0f); @@ -191,7 +160,6 @@ void CColor::Draw() device = m_engine->GetDevice(); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); -#endif } diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 501350e..4e64ee9 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -506,11 +506,7 @@ void CControl::Draw() if ( icon >= 192 ) { icon -= 192; -#if _POLISH - m_engine->SetTexture("textp.png"); -#else m_engine->SetTexture("text.png"); -#endif m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); } else if ( icon >= 128 ) diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 8db53c5..e7748ae 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -390,13 +390,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc button = pw->CreateButton(pos, dim, 128+57, EVENT_SATCOM_HUSTON); button->SetState(STATE_SHADOW); -#if _TEEN -#if !_ENGLISH - button = pw->CreateButton(pos, dim, 46, EVENT_SATCOM_SAT); -#endif -#else button = pw->CreateButton(pos, dim, 128+58, EVENT_SATCOM_SAT); -#endif button->SetState(STATE_SHADOW); //? button = pw->CreateButton(pos, dim, 128+59, EVENT_SATCOM_OBJECT); //? button->SetState(STATE_SHADOW); diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 6602651..e2df62b 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1225,11 +1225,7 @@ void CEdit::DrawPart(Math::Point pos, Math::Point dim, int icon) Math::Point uv1, uv2; float dp; -#if _POLISH - m_engine->SetTexture("textp.png"); -#else m_engine->SetTexture("text.png"); -#endif m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = (16.0f/256.0f)*(icon%16); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index fc5bb30..11f8f4a 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -157,9 +157,6 @@ CMainDialog::CMainDialog() m_bMovies = true; m_bNiceReset = true; m_bHimselfDamage = true; -/* TODO: #if _TEEN - m_bCameraScroll = false; -#else*/ m_bCameraScroll = true; m_bCameraInvertX = false; @@ -247,9 +244,6 @@ void CMainDialog::ChangePhase(Phase phase) pos.y = 0.10f; ddim.x = 0.30f; ddim.y = 0.80f; - /* TODO: #if _TEEN - pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5); -#else*/ pw = m_interface->CreateWindows(pos, ddim, 10, EVENT_WINDOW5); GetResource(RES_TEXT, RT_TITLE_INIT, name); @@ -265,22 +259,7 @@ void CMainDialog::ChangePhase(Phase phase) ddim.x = 0.30f; ddim.y = 0.30f; pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner - - /* TODO: #if _SCHOOL - ddim.x = 0.20f; - ddim.y = dim.y*2.4f; - pos.x = 0.40f; - pos.y = oy+sy*7.9f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // orange - pg->SetState(STATE_SHADOW); - pos.y = oy+sy*3.9f; - pg = pw->CreateGroup(pos, ddim, 25, EVENT_LABEL1); // orange - pg->SetState(STATE_SHADOW); - ddim.y = dim.y*1.2f; - pos.y = oy+sy*1.9f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red - pg->SetState(STATE_SHADOW); -#else */ + ddim.x = 0.20f; ddim.y = dim.y*2.4f; pos.x = 0.40f; @@ -300,26 +279,7 @@ void CMainDialog::ChangePhase(Phase phase) pos.y = oy+sy*1.9f; pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red pg->SetState(STATE_SHADOW); - - /* TODO: #if _SCHOOL - ddim.x = 0.18f; - ddim.y = dim.y*1; - pos.x = 0.41f; - pos.y = oy+sy*9.1f; - pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_TRAINER); - pb->SetState(STATE_SHADOW); - - pos.y = oy+sy*8.0f; -#if _TEEN -pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_TEEN); -#else -pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_DEFI); -#endif -#if _CEEBOTDEMO -pb->ClearState(STATE_ENABLE); -#endif -pb->SetState(STATE_SHADOW); -#else */ + ddim.x = 0.18f; ddim.y = dim.y*1; pos.x = 0.41f; @@ -356,20 +316,14 @@ pb->SetState(STATE_SHADOW); pb->SetState(STATE_SHADOW); #if DEV_BUILD - // TODO: #if !_DEMO & !_SCHOOL if ( m_accessEnable && m_accessUser ) { pos.x = 447.0f/640.0f; pos.y = 313.0f/480.0f; ddim.x = 0.09f; - /*#if _POLISH - pos.x -= 5.0f/640.0f; - ddim.x += 10.0f/640.0f; -#endif*/ pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER); pb->SetState(STATE_SHADOW); } - // #endif #endif /*pos.x = 139.0f/640.0f; @@ -408,19 +362,6 @@ pb->SetState(STATE_SHADOW); GetResource(RES_TEXT, RT_TITLE_NAME, name); pw->SetName(name); - /* TODO: #if _NEWLOOK - pos.x = 80.0f/640.0f; - pos.y = 93.0f/480.0f; - ddim.x = 285.0f/640.0f; - ddim.y = 266.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 372.0f/640.0f; - ddim.x = 188.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif*/ - pos.x = 0.10f; pos.y = 0.40f; ddim.x = 0.50f; @@ -528,15 +469,6 @@ pb->SetState(STATE_SHADOW); GetResource(RES_TEXT, RT_TITLE_PERSO, name); pw->SetName(name); - /* TODO: #if _NEWLOOK - pos.x = 95.0f/640.0f; - pos.y = 66.0f/480.0f; - ddim.x = 443.0f/640.0f; - ddim.y = 42.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif*/ - pos.x = 0.10f; pos.y = 0.40f; ddim.x = 0.50f; @@ -812,29 +744,6 @@ pb->SetState(STATE_SHADOW); GetResource(RES_TEXT, res, name); pw->SetName(name); - /* TODO: #if _NEWLOOK - pos.x = 100.0f/640.0f; - pos.y = 226.0f/480.0f; - ddim.x = 216.0f/640.0f; - ddim.y = 160.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 322.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // cyan - pg->SetState(STATE_SHADOW); - - pos.x = 100.0f/640.0f; - pos.y = 122.0f/480.0f; - ddim.x = 438.0f/640.0f; - ddim.y = 98.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 25, EVENT_LABEL1); // green - pg->SetState(STATE_SHADOW); - pos.y = 66.0f/480.0f; - ddim.y = 42.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif */ - pos.x = 0.10f; pos.y = 0.40f; ddim.x = 0.50f; @@ -1045,80 +954,6 @@ pb->SetState(STATE_SHADOW); ddim.y = 0.05f; pw->CreateGroup(pos, ddim, 3, EVENT_NULL); // transparent -> gray - /* TODO: #if _NEWLOOK - if ( m_phase == PHASE_SETUPd || // setup/display ? - m_phase == PHASE_SETUPds ) - { - pos.x = 100.0f/640.0f; - pos.y = 130.0f/480.0f; - ddim.x = 216.0f/640.0f; - ddim.y = 212.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 324.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // cyan - pg->SetState(STATE_SHADOW); - } - if ( m_phase == PHASE_SETUPg || // setup/graphic ? - m_phase == PHASE_SETUPgs ) - { - pos.x = 100.0f/640.0f; - pos.y = 130.0f/480.0f; - ddim.x = 174.0f/640.0f; - ddim.y = 212.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 282.0f/640.0f; - ddim.x = 258.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // cyan - pg->SetState(STATE_SHADOW); - } - if ( m_phase == PHASE_SETUPp || // setup/game ? - m_phase == PHASE_SETUPps ) - { - pos.x = 100.0f/640.0f; - pos.y = 130.0f/480.0f; - ddim.x = 226.0f/640.0f; - ddim.y = 212.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 334.0f/640.0f; - ddim.x = 206.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // cyan - pg->SetState(STATE_SHADOW); - } - if ( m_phase == PHASE_SETUPc || // setup/command ? - m_phase == PHASE_SETUPcs ) - { - pos.x = 100.0f/640.0f; - pos.y = 125.0f/480.0f; - ddim.x = 440.0f/640.0f; - ddim.y = 222.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - } - if ( m_phase == PHASE_SETUPs || // setup/sound ? - m_phase == PHASE_SETUPss ) - { - pos.x = 100.0f/640.0f; - pos.y = 130.0f/480.0f; - ddim.x = 216.0f/640.0f; - ddim.y = 212.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // blue - pg->SetState(STATE_SHADOW); - pos.x = 324.0f/640.0f; - pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // cyan - pg->SetState(STATE_SHADOW); - } - - pos.x = 100.0f/640.0f; - pos.y = 66.0f/480.0f; - ddim.x = 440.0f/640.0f; - ddim.y = 42.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif */ - ddim.x = 0.78f/5-0.01f; ddim.y = 0.06f; pos.x = 0.115f; @@ -1349,10 +1184,7 @@ pb->SetState(STATE_SHADOW); ddim.y = dim.y*1; pos.x = ox+sx*10; pos.y = oy+sy*2; - /* TODO: #if _POLISH - ddim.x += 20.0f/640.0f; - pos.x -= 20.0f/640.0f*3.0f; -#endif*/ + pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_MIN); pb->SetState(STATE_SHADOW); pos.x += ddim.x; @@ -1375,13 +1207,7 @@ pb->SetState(STATE_SHADOW); //? pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_TOTO); //? pc->SetState(STATE_SHADOW); //? pos.y -= 0.048f; - /*TODO: #if _SCHOOL -#if _EDU -pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_SOLUCE4); -pc->SetState(STATE_SHADOW); -pos.y -= 0.048f; -#endif -#else*/ + pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_MOVIES); pc->SetState(STATE_SHADOW); pos.y -= 0.048f; @@ -1503,7 +1329,6 @@ pos.y -= 0.048f; pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); - // TODO: #if (_FULL | _NET) & _SOUNDTRACKS pos.x = ox+sx*3; pos.y = 0.40f; ddim.x = dim.x*4.0f; @@ -1516,7 +1341,6 @@ pos.y -= 0.048f; GetResource(RES_EVENT, EVENT_INTERFACE_VOLMUSIC, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, name); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); - // #endif ddim.x = dim.x*3; ddim.y = dim.y*1; @@ -1554,15 +1378,6 @@ pos.y -= 0.048f; ddim.y = 0.50f; pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner - /* TODO: #if _NEWLOOK - pos.x = 100.0f/640.0f; - pos.y = 66.0f/480.0f; - ddim.x = 438.0f/640.0f; - ddim.y = 42.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif */ - pos.x = 290.0f/640.0f; ddim.x = 245.0f/640.0f; @@ -1638,15 +1453,6 @@ pos.y -= 0.048f; ddim.y = 0.50f; pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner - /* TODO: #if _NEWLOOK - pos.x = 100.0f/640.0f; - pos.y = 66.0f/480.0f; - ddim.x = 438.0f/640.0f; - ddim.y = 42.0f/480.0f; - pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // violet - pg->SetState(STATE_SHADOW); -#endif*/ - pos.x = 290.0f/640.0f; ddim.x = 245.0f/640.0f; @@ -1706,9 +1512,6 @@ pos.y -= 0.048f; pos.y = 0.10f; ddim.x = 0.30f; ddim.y = 0.80f; - /*TODO: #if _TEEN - pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5); -#else*/ pw = m_interface->CreateWindows(pos, ddim, 10, EVENT_WINDOW5); pw->SetName(" "); @@ -1817,7 +1620,6 @@ pos.y -= 0.048f; ddim.y = 0.0f; pw = m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5); - // TODO: #if _FULL | _NET pos.x = 80.0f/640.0f; pos.y = 240.0f/480.0f; ddim.x = 490.0f/640.0f; @@ -1830,54 +1632,6 @@ pos.y -= 0.048f; pe->SetFontSize(Gfx::FONT_SIZE_SMALL); pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/authors.txt")); - // #endif - /* TODO: #if _SCHOOL - #if _CEEBOTDEMO - pos.x = 80.0f/640.0f; - pos.y = 210.0f/480.0f; - ddim.x = 490.0f/640.0f; - ddim.y = 150.0f/480.0f; - #else - pos.x = 80.0f/640.0f; - pos.y = 200.0f/480.0f; - ddim.x = 490.0f/640.0f; - ddim.y = 150.0f/480.0f; - #endif - pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1); - pe->SetGenericMode(true); - pe->SetEditCap(false); - pe->SetHighlightCap(false); - pe->SetFontType(Gfx::FONT_COURIER); - pe->SetFontSize(Gfx::FONT_SIZE_SMALL); - pe->ReadText("help/authors.txt");*/ - - /* #if _DEMO - //? pos.x = 80.0f/640.0f; - //? pos.y = 240.0f/480.0f; - //? ddim.x = 490.0f/640.0f; - //? ddim.y = 110.0f/480.0f; - //? pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1); - //? pe->SetGenericMode(true); - //? pe->SetEditCap(false); - //? pe->SetHiliteCap(false); - //? pe->SetFontType(Gfx::FONT_COURIER); - //? pe->SetFontSize(Gfx::FONT_SIZE_SMALL); - //? pe->ReadText("help/demo.txt"); - - //? pos.x = 80.0f/640.0f; - //? pos.y = 140.0f/480.0f; - //? ddim.x = 490.0f/640.0f; - //? ddim.y = 100.0f/480.0f; - //? pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT2); - //? pe->SetGenericMode(true); - //? pe->SetEditCap(false); - //? pe->SetHiliteCap(false); - //? pe->SetFontType(Gfx::FONT_COURIER); - //? pe->SetFontSize(Gfx::FONT_SIZE_SMALL); - //? pe->ReadText("help/authors.txt"); -#endif */ - - // TODO: #if !_DEMO pos.x = 40.0f/640.0f; pos.y = 83.0f/480.0f; ddim.x = 246.0f/640.0f; @@ -1907,23 +1661,13 @@ pos.y -= 0.048f; pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - // #endif - - /* TODO: #if _DEMO - pos.x = 481.0f/640.0f; - pos.y = 51.0f/480.0f; - ddim.x = 30.0f/640.0f; - ddim.y = 30.0f/480.0f; - pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT); - pb->SetState(STATE_SHADOW); -#else */ + pos.x = 306.0f/640.0f; pos.y = 17.0f/480.0f; ddim.x = 30.0f/640.0f; ddim.y = 30.0f/480.0f; pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT); pb->SetState(STATE_SHADOW); - // #endif m_engine->SetBackground("generico.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1950,24 +1694,10 @@ pos.y -= 0.048f; m_phase == PHASE_READ || m_phase == PHASE_LOADING ) { - /*TODO: #if _SCHOOL -#if _TEEN -pos.x = 50.0f/640.0f; -pos.y = 430.0f/480.0f; -ddim.x = 200.0f/640.0f; -ddim.y = 10.0f/480.0f; -#else -pos.x = 450.0f/640.0f; -pos.y = 0.0f/480.0f; -ddim.x = 170.0f/640.0f; -ddim.y = 9.0f/480.0f; -#endif -#else */ pos.x = 540.0f/640.0f; pos.y = 9.0f/480.0f; ddim.x = 90.0f/640.0f; ddim.y = 10.0f/480.0f; - //#endif //GetResource(RES_TEXT, RT_VERSION_ID, name); pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, COLOBOT_VERSION_DISPLAY); pl->SetFontType(Gfx::FONT_COURIER); @@ -3227,8 +2957,6 @@ Math::Vector SoundRand() void CMainDialog::FrameParticle(float rTime) { - /* TODO: #if _NEWLOOK -#else */ Math::Vector pos, speed; Math::Point dim; float *pParti, *pGlint; @@ -4765,17 +4493,6 @@ void CMainDialog::UpdateSceneChap(int &chap) { for ( j=0 ; j<9 ; j++ ) { -/* TODO: #if _SCHOOL - if ( m_phase == PHASE_MISSION ) break; - if ( m_phase == PHASE_FREE ) break; -#if _CEEBOTDEMO - if ( m_phase == PHASE_TRAINER && j >= 2 ) break; -#endif -#endif -#if _DEMO - if ( m_phase == PHASE_MISSION && j >= 4 ) break; - if ( m_phase == PHASE_TRAINER && j >= 1 ) break; -#endif */ BuildSceneName(fileName, m_sceneName, (j+1)*100); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) break; @@ -4820,14 +4537,6 @@ void CMainDialog::UpdateSceneChap(int &chap) break; } -/* TODO: #if _TEEN - if ( m_phase == PHASE_TRAINER && !m_main->GetShowAll() && !bPassed ) - { - j ++; - break; - } -#endif*/ - if ( m_phase == PHASE_FREE && j == m_accessChap ) { j ++; @@ -4871,21 +4580,6 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) for ( j=0 ; j<99 ; j++ ) { -/* TODO: #if _SCHOOL - if ( m_phase == PHASE_MISSION ) break; - if ( m_phase == PHASE_FREE ) break; -#if _CEEBOTDEMO -#if _TEEN - if ( m_phase == PHASE_TRAINER && j >= 5 ) break; -#else - if ( m_phase == PHASE_TRAINER && j >= 3 ) break; -#endif -#endif -#endif -#if _DEMO - if ( m_phase == PHASE_MISSION && j >= 3 ) break; - if ( m_phase == PHASE_TRAINER && j >= 5 ) break; -#endif */ BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) break; @@ -4929,14 +4623,6 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) j ++; break; } - -/* TODO: #if _TEEN - if ( m_phase == PHASE_TRAINER && !m_main->GetShowAll() && !bPassed ) - { - j ++; - break; - } -#endif*/ } BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); @@ -5564,21 +5250,7 @@ void CMainDialog::SetupMemorize() GetProfile().SetLocalProfileString("Setup", "KeyMap", key.str()); -#if _NET - if ( m_accessEnable ) - { - iValue = m_accessMission; - SetLocalProfileInt("Setup", "AccessMission", iValue); - - iValue = m_accessUser; - SetLocalProfileInt("Setup", "AccessUser", iValue); - } -#endif - GetProfile().SetLocalProfileInt("Setup", "DeleteGamer", m_bDeleteGamer); - - // TODO: write graphic engine profile - //m_engine->WriteProfile(); } // Remember all the settings. @@ -5788,21 +5460,6 @@ void CMainDialog::SetupRecall() } } -#if _NET - if ( m_accessEnable ) - { - if ( GetProfile().GetLocalProfileInt("Setup", "AccessMission", iValue) ) - { - m_accessMission = iValue; - } - - if ( GetProfile().GetLocalProfileInt("Setup", "AccessUser", iValue) ) - { - m_accessUser = iValue; - } - } -#endif - if ( GetProfile().GetLocalProfileInt("Setup", "DeleteGamer", iValue) ) { m_bDeleteGamer = iValue; @@ -6005,10 +5662,6 @@ void CMainDialog::StartAbort() pos.x = 0.40f; dim.x = 0.20f; -/* TODO: #if _POLISH - pos.x -= 7.0f/640.0f; - dim.x += 14.0f/640.0f; -#endif*/ dim.y = 32.0f/480.0f; pos.y = 0.74f; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 5a3b403..f83704e 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1111,17 +1111,11 @@ void CStudio::StartDialog(StudioDialog type) GetResource(RES_TEXT, RT_IO_PRIVATE, name); pc->SetName(name); pc->SetState(STATE_SHADOW); -#if _POLISH - pc->SetFontSize(8.0f); -#endif pc = pw->CreateCheck(pos, dim, 0, EVENT_DIALOG_CHECK2); GetResource(RES_TEXT, RT_IO_PUBLIC, name); pc->SetName(name); pc->SetState(STATE_SHADOW); -#if _POLISH - pc->SetFontSize(8.0f); -#endif pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_OK); pb->SetState(STATE_SHADOW); diff --git a/src/ui/window.cpp b/src/ui/window.cpp index ed18ce4..98e1e6c 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -1536,8 +1536,6 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) void CWindow::DrawHach(Math::Point pos, Math::Point dim) { -#if _NEWLOOK -#else Math::Point ppos, ddim, uv1, uv2; float dp, max, ndim; bool bStop; @@ -1575,7 +1573,6 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim) ppos.x += ddim.x; } while ( !bStop ); -#endif } } -- cgit v1.2.3-1-g7c22